Network Teaming可聯合或合併物理網絡接口,造成具備較高吞吐量或冗餘方式的邏輯網絡接口。其做爲網卡綁定的備選方式出現,在系統中和傳統的bonding方式並存。shell
[root@test03 ~]# uname -a Linux test03 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux [root@test03 ~]# ip addr show 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:56:69:4d brd ff:ff:ff:ff:ff:ff inet 192.168.231.13/24 brd 192.168.231.255 scope global eno16777736 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe56:694d/64 scope link valid_lft forever preferred_lft forever 3: eno33554992: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:56:69:57 brd ff:ff:ff:ff:ff:ff 4: eno50332216: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:56:69:61 brd ff:ff:ff:ff:ff:ff
網卡綁定模式:activebackup - 主備模式網絡
一個網卡處於活躍狀態,另外一個處於備份狀態,全部流量都在主鏈路上處理,當活躍網卡down掉時,啓用備份網卡。ide
綁定網卡:eno33554992+eno50332216=team0oop
- 設置eno33554992爲主網卡(優先處於活躍狀態),eno50332216爲輔網卡(備份狀態,主網卡鏈路正常時,輔網卡處於備份狀態);-- <u>此時無需設置輔網卡粘滯位。</u>
- 設置eno33554992爲主網卡,eno50332216爲輔網卡,主網卡鏈路故障後,輔網卡切換爲活躍狀態,主網卡鏈路恢復後,輔網卡仍保持活躍狀態直至其鏈路故障。 -- <u>此時須要設置輔網卡粘滯位{"sticky" true}。</u>
[root@test03 network-scripts]# nmcli device DEVICE TYPE STATE CONNECTION eno16777736 ethernet connected eno16777736 eno33554992 ethernet connected eno33554992 eno50332216 ethernet connected eno50332216 lo loopback unmanaged -- # 共四張網卡,lo爲本地迴環網卡,另外三張爲物理網卡。
[root@test03 network-scripts]# nmcli connection show NAME UUID TYPE DEVICE eno50332216 36b38556-4bf8-4ce0-8045-4f5465530f67 802-3-ethernet eno50332216 eno33554992 46831ccf-905b-4361-b5ba-c5448133e288 802-3-ethernet eno33554992 eno16777736 613db14a-2375-4a89-b55a-d2abd8fc65d5 802-3-ethernet eno16777736
本次Network Teaming配置中,須要將eno33554992
和eno50332216
綁定爲team0
,而且設置eno33554992
爲主網卡,首先須要這兩塊網卡現有的配置信息,不然team0
建立完成後,未刪除的網卡配置信息會影響team0
的正常工做。測試
若是nmcli connection show
命令輸出中無將要進行配置的網卡鏈接信息,則無需進行刪除操做。3d
[root@test03 network-scripts]# nmcli connection delete eno33554992 [root@test03 network-scripts]# nmcli connection delete eno50332216 [root@test03 network-scripts]# [root@test03 network-scripts]# nmcli connection show NAME UUID TYPE DEVICE eno16777736 613db14a-2375-4a89-b55a-d2abd8fc65d5 802-3-ethernet eno16777736 # 網卡鏈接信息刪除成功。 # 這裏刪除的其實就是/etc/sysconfig/network-scripts目錄下兩塊網卡的配置文件。 [root@test03 network-scripts]# pwd /etc/sysconfig/network-scripts [root@test03 network-scripts]# ls ifcfg-* ifcfg-eno16777736 ifcfg-lo
[root@test03 network-scripts]# nmcli connection add type team ifname team0 con-name team0 config '{"runner": {"name":"activebackup"}}' ip4 192.168.231.100/24 Connection 'team0' (dfe2f884-40e0-4686-a7f9-2be4b1a4b5b2) successfully added.
設備類型:team;設備名稱和鏈接名稱:均爲team0;綁定模式:activebackup - 主備模式;IP及子網掩碼:192.168.231.100/24;code
固然,也能夠後續設置IP地址,示例:接口
#建立team0並設置爲主備模式 [root@test03 network-scripts]# nmcli connection add type team ifname team0 con-name team0 config '{"runner": {"name":"activebackup"}}' #設置IP地址及子網掩碼 [root@test03 network-scripts]# nmcli connection modify team0 ipv4.addresses 192.168.231.100/24 #設置IP地址獲取方法爲手動 [root@test03 network-scripts]# nmcli connection modify team0 ipv4.method manual
配置完成後,會在/etc/sysconfig/network-scripts目錄下生成ifcfg-team0的配置文件ip
[root@test03 network-scripts]# cat /etc/sysconfig/network-scripts/ifcfg-team0 DEVICE=team0 TEAM_CONFIG="{\"runner\": {\"name\":\"activebackup\"}}" DEVICETYPE=Team BOOTPROTO=none DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no NAME=team0 UUID=dfe2f884-40e0-4686-a7f9-2be4b1a4b5b2 ONBOOT=yes IPADDR=192.168.231.100 PREFIX=24 IPV6_PEERDNS=yes IPV6_PEERROUTES=yes
# 添加網卡eno33554992,設備類型:team-slave;鏈接名稱:team0-p1;master:team0;優先級:100 [root@test03 network-scripts]# nmcli connection add type team-slave ifname eno33554992 con-name team0-p1 master team0 config '{"prio": 100}' Connection 'team0-p1' (4c8901c7-0246-47ce-8d5a-272f23f88d70) successfully added. # 添加網卡eno50332216,設備類型:team-slave;鏈接名稱:team0-p1;master:team0;優先級:-10; 粘滯位:true(sticky標誌請根據實際須要設置) [root@test03 network-scripts]# nmcli connection add type team-slave ifname eno50332216 con-name team0-p2 master team0 config '{"prio": -10,"sticky": true}' Connection 'team0-p2' (d898f1f5-bb0f-496e-8cdd-7f3898c2a482) successfully added.
本次配置中
eno33554992
爲主網卡,設置其優先級爲100;eno50332216
爲輔網卡,設置其優先級爲-10,粘滯位爲true。文檔prio:優先級。
數字越大,網卡優先級越高,優先爲活躍網卡;若不設置優先級,則默認爲0,先接入網絡的網卡爲活躍網卡,另外一塊爲備份網卡,直至活躍網卡斷開鏈接,備份網卡自動升級爲活躍網卡,兩塊網卡角色互換。
sticky:粘滯位,默認爲false;
- 輔網卡
eno50332216
中設置了sticky爲true,表明若是輔網卡鏈接狀態變爲爲活躍狀態後,不管主網卡鏈接是否正常,其將會一直保持爲活躍狀態。- 若不設置sticky,在輔網卡爲活躍狀態時,若主網卡鏈接恢復正常,則活躍網卡由主網卡接管,輔網卡會變爲備份狀態。
可根據實際須要進行參數設置。
配置完成後,此時會在/etc/sysconfig/network-scripts目錄下生成ifcfg-team0-p1,ifcfg-team0-p2的配置文件:
[root@test03 network-scripts]# cat ifcfg-team0-p1 TEAM_PORT_CONFIG="{\"prio\": 100}" NAME=team0-p1 UUID=4c8901c7-0246-47ce-8d5a-272f23f88d70 DEVICE=eno33554992 ONBOOT=yes TEAM_MASTER=team0 DEVICETYPE=TeamPort [root@test03 network-scripts]# cat ifcfg-team0-p2 TEAM_PORT_CONFIG="{\"prio\": -10,\"sticky\": true}" NAME=team0-p2 UUID=d898f1f5-bb0f-496e-8cdd-7f3898c2a482 DEVICE=eno50332216 ONBOOT=yes TEAM_MASTER=team0 DEVICETYPE=TeamPort
# 激活team0-p1 [root@test03 ~]# nmcli connection up team0-p1 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5) # 激活team0-p2 [root@test03 ~]# nmcli connection up team0-p2 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/6) # 激活team0 [root@test03 ~]# nmcli connection up team0 Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/7)
# 查看當前活躍網卡 [root@test03 network-scripts]# nmcli connection show --active NAME UUID TYPE DEVICE team0-p1 4c8901c7-0246-47ce-8d5a-272f23f88d70 802-3-ethernet eno33554992 eno16777736 613db14a-2375-4a89-b55a-d2abd8fc65d5 802-3-ethernet eno16777736 team0 d6e07840-dff8-49e9-a23c-35eb0cc0ec4b team team0 team0-p2 d898f1f5-bb0f-496e-8cdd-7f3898c2a482 802-3-ethernet eno50332216 #查看team0端口狀態 [root@test03 network-scripts]# teamnl team0 ports 4: eno50332216: up 1000Mbit FD 3: eno33554992: up 1000Mbit FD [root@test03 network-scripts]# teamdctl team0 stat setup: runner: activebackup ports: eno33554992 link watches: link summary: up instance[link_watch_0]: name: ethtool link: up eno50332216 link watches: link summary: up instance[link_watch_0]: name: ethtool link: up runner: active port: eno33554992
# 查看team0詳細配置 [root@test03 network-scripts]# teamdctl team0 config dump { "device": "team0", "mcast_rejoin": { "count": 1 }, "notify_peers": { "count": 1 }, "ports": { "eno33554992": { "link_watch": { "name": "ethtool" }, "prio": 100 }, "eno50332216": { "link_watch": { "name": "ethtool" }, "prio": -10, "sticky": true } }, "runner": { "name": "activebackup" } } # 單獨查看team0子網卡詳細配置 [root@test03 network-scripts]# teamdctl team0 port config dump eno33554992 { "link_watch": { "name": "ethtool" }, "prio": 100 } [root@test03 network-scripts]# teamdctl team0 port config dump eno50332216 { "link_watch": { "name": "ethtool" }, "prio": -10, "sticky": true }
[root@test03 ~]# teamdctl team0 stat setup: runner: activebackup ports: eno33554992 link watches: link summary: up instance[link_watch_0]: name: ethtool link: up eno50332216 link watches: link summary: up instance[link_watch_0]: name: ethtool link: up runner: active port: eno33554992
當前活躍子網卡爲eno33554992
,ping team0的IP地址一直能夠ping通。如今將該網卡斷開鏈接:
# 斷開team0-p1的網絡鏈接 [root@test03 ~]# nmcli connection down team0-p1 Connection 'team0-p1' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2) # 查看team0鏈接狀態 [root@test03 ~]# teamdctl team0 stat setup: runner: activebackup ports: eno50332216 link watches: link summary: up instance[link_watch_0]: name: ethtool link: up runner: active port: eno50332216 # 活躍網卡變爲eno50332216,ping測試短暫中斷後恢復。 來自 192.168.231.100 的回覆: 字節=32 時間<1ms TTL=64 來自 192.168.231.100 的回覆: 字節=32 時間<1ms TTL=64 來自 192.168.231.100 的回覆: 字節=32 時間=1ms TTL=64 來自 192.168.231.100 的回覆: 字節=32 時間<1ms TTL=64 請求超時。 請求超時。 來自 192.168.231.100 的回覆: 字節=32 時間=1ms TTL=64 來自 192.168.231.100 的回覆: 字節=32 時間<1ms TTL=64 來自 192.168.231.100 的回覆: 字節=32 時間<1ms TTL=64
因爲本次測試在虛擬機中進行,ping測試會出現較明顯的中斷,在真實的物理機上測試時,ping測試會一直正常或出現短暫中斷後恢復。
官方文檔推薦使用:
nmcli device [disconnect|connect] ifname
命令來進行網卡的斷開和鏈接操做,但在虛擬機上使用此方法斷開網卡鏈接後,恢復網卡鏈接時會報錯,這裏使用命令nmcli connection [down|up] ifname
進行操做。
當前活躍網卡爲輔網卡eno50332216
,如今鏈接主網卡:
# 恢復team0-p1的網絡鏈接 [root@test03 ~]# nmcli connection up team0-p1 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/7) # 查看team0的鏈接狀態 [root@test03 ~]# teamdctl team0 stat setup: runner: activebackup ports: eno33554992 link watches: link summary: up instance[link_watch_0]: name: ethtool link: up eno50332216 link watches: link summary: up instance[link_watch_0]: name: ethtool link: up runner: active port: eno50332216 # ping測試短暫中斷後恢復 來自 192.168.231.100 的回覆: 字節=32 時間<1ms TTL=64 請求超時。 請求超時。 來自 192.168.231.100 的回覆: 字節=32 時間=1ms TTL=64 來自 192.168.231.100 的回覆: 字節=32 時間<1ms TTL=64
因爲本次測試在虛擬機中進行,ping測試會出現較明顯的中斷,在真實的物理機上測試時,ping測試會一直正常或出現短暫中斷後恢復。
在主網卡鏈接恢復正常後,查看team0發現當前活躍網卡仍爲輔網卡
eno50332216
,沒有將活躍網卡切換爲主網卡eno33554992
,緣由是在輔網卡中設置了粘滯位sticky=true,sticky標誌使輔網卡爲活躍狀態後,若其網絡鏈接不發生故障,則會一直保持其爲活躍網卡。 若是在輔網卡配置中不設置sticky標誌,主網卡鏈接恢復正常後,活躍網卡由主網卡接管,輔網卡會變爲備份狀態。
對於各類雙網卡綁定配置模式,請參考系統中的示例文件,文件位置:
/usr/share/doc/teamd-xx/example_configs/