1. 程式人生 > >聚合鏈路與橋接測試

聚合鏈路與橋接測試

npos ble option idt ger pre cpe 測試環境 collision

用途:將主機上的兩塊網卡綁定在一起,構成一個邏輯端口。
交換機根據用戶配置的端口負荷分擔策略決定報文從哪一個成員端口發送到對端的交換機。當其中一塊網卡發生故障時,則繼續使用另外一塊正常的網卡。

RHEL5/6叫網卡bonding,需要加載內核模塊
RHEL7叫鏈路聚合,內核自帶驅動,需要配置team的master和多個slave

聚合網絡的原理

真實的ip地址並不是在物理網卡上設置的,而是把兩個或多個物理網卡聚合成一個虛擬的網卡,在虛擬網卡上設置地址,而外部網絡訪問本機時,就是訪問的這個虛擬網卡的地址,虛擬網卡接到數據後經過兩個網卡的負載交給服務器處理。如果一塊網卡出現問題,則通過另一塊傳遞數據,保證正常通信。聚合網絡實驗過程中,添加的兩塊新網卡可以不是active狀態,甚至nmcli connect show查看沒有新添加的網卡信息。也可以使active狀態的網卡。

鏈路聚合的工作模式
1.active-backup 主備
2.loadbalance 負載均衡
3.RR RoundRobin 輪詢

測試環境:

[[email protected] ~]# ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.100.4 netmask 255.255.255.255 broadcast 192.168.100.4
inet6 fe80::922e:b8be:7ea8:4562 prefixlen 64 scopeid 0x20<link>
ether 08:00:27:3e:f6:4d txqueuelen 1000 (Ethernet)
RX packets 164 bytes 20454 (19.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 168 bytes 28639 (27.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 82 bytes 8488 (8.2 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 82 bytes 8488 (8.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:81:e7:fc txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

[[email protected] ~]# hostnamectl
Static hostname: localhost.localdomain
Icon name: computer-vm
Chassis: vm
Machine ID: c59cb0b9011f459297a11b7b6b3e457b
Boot ID: b029771ca9204611abe911f960ea7d51
Virtualization: kvm
Operating System: Red Hat Enterprise Linux Server 7.4 (Maipo)
CPE OS Name: cpe:/o:redhat:enterprise_linux:7.4:GA:server
Kernel: Linux 3.10.0-693.el7.x86_64
Architecture: x86-64
[[email protected] ~]# nmcli connection show
NAME UUID TYPE DEVICE
enp0s3 59118063-4e4e-403c-ad25-374704d6f6f1 802-3-ethernet enp0s3
virbr0 b7180c81-0027-49ee-ab06-8f34a2df30be bridge virbr0
[[email protected] ~]#

一、測試主備模式(active-backup)

1、在主機模式再添加一塊新的網卡

先shutdown 虛擬機,然後再 VirtualBox界面再啟用網卡2。

技術分享

然後啟動虛擬機。

2、查看網卡信息

[[email protected] ~]# nmcli device show | grep -i device --新增網卡為enp0s8
GENERAL.DEVICE: virbr0
GENERAL.DEVICE: enp0s3
GENERAL.DEVICE: enp0s8
GENERAL.DEVICE: lo
GENERAL.DEVICE: virbr0-nic

[[email protected] ~]# nmcli connection show ---看不到enp0s8,因為無配置文件
NAME UUID TYPE DEVICE
enp0s3 59118063-4e4e-403c-ad25-374704d6f6f1 802-3-ethernet enp0s3
virbr0 b4f4c345-d863-41c0-b396-55fd0f67785f bridge virbr0

# nmcli connection show 看不到enp0s8,因為無配置文件,如果手動添加配置文件後,就可以看到enp0s8了。其實都沒必要為enp0s8和enp0s3造配置文件,因為我們要跟把兩塊網卡綁定到一塊,作為新的team設備,使用新的配置文件。這裏只為了測試一個小知識點。

[[email protected] ~]# nmcli connection add con-name enp0s8 type ethernet ifname enp0s8
Connection ‘enp0s8‘ (b3972183-4a71-4635-b910-02c0530517d3) successfully added.
[[email protected] ~]# nmcli connection show
NAME UUID TYPE DEVICE
enp0s3 59118063-4e4e-403c-ad25-374704d6f6f1 802-3-ethernet enp0s3
enp0s8 b3972183-4a71-4635-b910-02c0530517d3 802-3-ethernet enp0s8
virbr0 b4f4c345-d863-41c0-b396-55fd0f67785f bridge virbr0

3、添加team設備及配置文件

[[email protected] ~]# nmcli connection add type team con-name testteamfile ifname testteamdevice config ‘{"runner":{"name":"activebackup"}}‘
Connection ‘testteamfile‘ (d2c8f925-8645-4ac5-95e6-6245a4431778) successfully added.
[[email protected] ~]# nmcli connection show --如果看不到team設備,說明上一命令有問題。
NAME UUID TYPE DEVICE
enp0s3 59118063-4e4e-403c-ad25-374704d6f6f1 802-3-ethernet enp0s3
enp0s8 b3972183-4a71-4635-b910-02c0530517d3 802-3-ethernet enp0s8
testteamfile d2c8f925-8645-4ac5-95e6-6245a4431778 team testteamdevice
virbr0 b4f4c345-d863-41c0-b396-55fd0f67785f bridge virbr0

說明:

# nmcli connection add type team con-name testteamfile ifname testteamdevice config ‘{"runner":{"name":"activebackup"}}‘
testteamfile配置文件名
testteamdevice 綁定的設備名
config ’{運行規則}’。運行規則中出現的所有關鍵字使用雙引號。
"runner":{"name":"activebackup"} 指明運行級別為activebackup

如果添加錯誤,則使用 nmcli connection delete testteamfile來刪除,然後重新再添加。

配置文件添加成功後,會在/etc/sysconfig/network-scripts/目錄下生成。

[[email protected] ~]# cd /etc/sysconfig/network-scripts/
[[email protected] network-scripts]# ls ifcfg-*
ifcfg-enp0s3 ifcfg-enp0s8 ifcfg-lo ifcfg-testteamfile

4、為team設備配置IP

[[email protected] network-scripts]# nmcli connection modify testteamfile ipv4.method manual ipv4.addresses 192.168.100.123/24 ipv4.gateway 192.168.100.100 ipv4.dns 192.168.100.1 connection.autoconnect yes
[[email protected] network-scripts]# nmcli connection show
NAME UUID TYPE DEVICE
enp0s3 59118063-4e4e-403c-ad25-374704d6f6f1 802-3-ethernet enp0s3
enp0s8 b3972183-4a71-4635-b910-02c0530517d3 802-3-ethernet enp0s8
testteamfile d2c8f925-8645-4ac5-95e6-6245a4431778 team testteamdevice
virbr0 b4f4c345-d863-41c0-b396-55fd0f67785f bridge virbr0

5、將兩塊網卡enp0s3和enp0s8綁定到虛擬網卡上

[[email protected] ~]# nmcli connection add type team-slave con-name testteamslave1 ifname enp0s3 master testteamdevice
Connection ‘testteamslave1‘ (506b5fe9-0c3b-4251-b58b-b1a1a53acda4) successfully added.
[[email protected] ~]# nmcli connection add type team-slave con-name testteamslave2 ifname enp0s8 master testteamdevice
Connection ‘testteamslave2‘ (312ba2d8-7b18-4446-b37f-5de7217a6646) successfully added.

[[email protected] ~]# nmcli connection show
NAME UUID TYPE DEVICE
enp0s3 59118063-4e4e-403c-ad25-374704d6f6f1 802-3-ethernet enp0s3
enp0s8 b3972183-4a71-4635-b910-02c0530517d3 802-3-ethernet enp0s8
virbr0 b4f4c345-d863-41c0-b396-55fd0f67785f bridge virbr0
testteamfile d2c8f925-8645-4ac5-95e6-6245a4431778 team --
testteamslave1 506b5fe9-0c3b-4251-b58b-b1a1a53acda4 802-3-ethernet --
testteamslave2 312ba2d8-7b18-4446-b37f-5de7217a6646 802-3-ethernet --

enp0s3----->testteamslave1------>testteamdevice

enpos8----->testteamslave2------>testteamdevice

可以這麽理解:enp0s3和enp0s8被它們的主子master買去做了奴隸,一個取名叫slave1,另一個取名叫slave2。

6、激活虛擬網卡testteamdevice

[[email protected] ~]# nmcli connection up testteamfile ---註意啟動的是文件,而不是設備
Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/157)

[[email protected] ~]# nmcli connection up testteamslave1

[[email protected] ~]# nmcli connection up testteamslave2

先啟動master,再啟動兩個slave。

[[email protected] ~]# nmcli connection show
NAME UUID TYPE DEVICE
virbr0-nic 6944d05c-3906-4fc5-84e7-cb46f3e6e2b2 generic virbr0-nic
virbr0 05e6ca14-f6f5-4697-bcc0-e13e4b212236 bridge virbr0
enp0s3 7419645c-73a9-423f-bcfd-fccd36773841 802-3-ethernet --
testteamslave2 608bb6f1-099d-459d-9589-5b2f2b28b2d9 802-3-ethernet enp0s8
testteamslave1 90b0d08f-dec2-4a1f-827a-ce198f21fb46 802-3-ethernet enp0s3
testteamfile f2277aa4-a7b3-4166-afaa-dcd60e550d97 team testteamdevice
[[email protected] ~]# ifconfig | grep ether
ether 08:00:27:57:c1:ff txqueuelen 1000 (Ethernet)
ether 08:00:27:57:c1:ff txqueuelen 1000 (Ethernet)
ether 08:00:27:57:c1:ff txqueuelen 0 (Ethernet)
ether 52:54:00:59:75:9b txqueuelen 0 (Ethernet)

[[email protected] ~]# ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 08:00:27:57:c1:ff txqueuelen 1000 (Ethernet)
RX packets 144 bytes 17362 (16.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 152 bytes 23282 (22.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 08:00:27:57:c1:ff txqueuelen 1000 (Ethernet)
RX packets 10 bytes 907 (907.0 B)
RX errors 0 dropped 5 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 10 bytes 984 (984.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 10 bytes 984 (984.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

testteamdevice: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.100.123 netmask 255.255.255.0 broadcast 192.168.100.255
inet6 fe80::a00:27ff:fe57:c1ff prefixlen 64 scopeid 0x20<link>
ether 08:00:27:57:c1:ff txqueuelen 0 (Ethernet)
RX packets 133 bytes 14204 (13.8 KiB)
RX errors 0 dropped 4 overruns 0 frame 0
TX packets 116 bytes 17841 (17.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:59:75:9b txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

You have mail in /var/spool/mail/root

從上邊可以看出:testteamdevice,enp0s3,enp0s8 三塊網卡的mac地址一樣。

三個常用的命令:

1、查看虛擬網卡的狀態

[[email protected] ~]# teamdctl testteamdevice state
setup:
runner: activebackup --運行模式
ports:
enp0s3
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up --狀態為啟動
down count: 0
enp0s8
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up --狀態為啟動
down count: 0
runner:
active port: enp0s3 --當前激活的網卡;testteamdevice設備目前使用的是enp0s3網卡

2、查看虛擬網卡的端口

[[email protected] ~]# teamnl testdevice -h
teamnl [options] teamdevname command [command args]
-h --help Show this help
Commands:
ports
options
getoption OPT_NAME
setoption OPT_NAME OPT_VALUE
monitor OPT_STYLE
[[email protected] ~]# teamnl testteamdevice ports ----查看網卡對應的端口
3: enp0s8: up 1000Mbit FD
2: enp0s3: up 1000Mbit FD

[[email protected] ~]# teamnl testteamdevice getoption activeport ---當前使用的網卡端口,當前使用的是enp0s3。
2

驗證結果:

[[email protected] ~]# nmcli device disconnect enp0s3 --斷開enp0s3
Device ‘enp0s3‘ successfully disconnected.
[[email protected] ~]# teamdctl testteamdevice state ---可以虛擬網卡自動連接到時enp0s8網卡上

[[email protected] ~]#teamncl testteamdevice port

3:enp0s8:up 1000Mbit FD

二、橋接

要求:把本機1的其中一塊網卡轉換為橋接設備(交換機),其它客戶機連接到該設備後能與主機1正常通信。

下面把網卡enp0s8轉換為橋接設備:

[[email protected] ~]# nmcli connection show
NAME UUID TYPE DEVICE
enp0s3 6759482b-076f-4181-9d69-ca6dc0190faa 802-3-ethernet enp0s3
virbr0 4f99dff9-d3fb-461a-b0d6-00297e7584a0 bridge virbr0
[[email protected] ~]# nmcli device show | grep -i device
GENERAL.DEVICE: virbr0
GENERAL.DEVICE: enp0s3
GENERAL.DEVICE: enp0s8
GENERAL.DEVICE: lo
GENERAL.DEVICE: virbr0-nic
[[email protected] ~]# ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.100.111 netmask 255.255.255.0 broadcast 192.168.100.255
inet6 fe80::6ea:59df:4b18:530b prefixlen 64 scopeid 0x20<link>
ether 08:00:27:3e:f6:4d txqueuelen 1000 (Ethernet)
RX packets 188 bytes 21984 (21.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 246 bytes 38495 (37.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 08:00:27:45:59:30 txqueuelen 1000 (Ethernet)
RX packets 63 bytes 9404 (9.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 84 bytes 9340 (9.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 84 bytes 9340 (9.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:81:e7:fc txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

[[email protected] ~]#

#nmcli connection add type bridge con-name testbrifile ifname testbridevice
#nmcli connection modify testbrifile ipv4.method manual ipv4.addresses "192.168.100.222/24 192.168.100.1" ipv4.dns 192.168.100.1
#nmcli connection add type bridge-slave con-name testbrislave1 ifname enpos8 master testbridevice
#nmcli connection down testbrifile
#nmcli connection up testbrifile
#nmcli connection up testbrislave1
#ping -I testbridevice 192.168.100.111 #-I表示從哪塊網卡發出ping

聚合鏈路與橋接測試