[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
網卡綁定模式:active-backup - 主備模式bash
一個網卡處於活躍狀態,另外一個處於備份狀態,全部流量都在主鏈路上處理,當活躍網卡down掉時,啓用備份網卡。網絡
綁定網卡:eno33554992+eno50332216=bond0ide
設置網卡eno33554992爲主網卡(優先處於活躍狀態),eno50332216爲輔網卡(備份狀態,主網卡鏈路正常時,輔網卡處於備份狀態)。oop
[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 bonding配置中,須要將eno33554992和eno50332216綁定爲bond0,而且設置eno33554992爲主網卡,首先須要這兩塊網卡現有的配置信息,不然bond0建立完成後,未刪除的網卡配置信息會影響bond0的正常工做。測試
若是nmcli connectionshow命令輸出中無將要進行配置的網卡鏈接信息,則無需進行刪除操做。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 bond ifname bond0 con-name bond0 miimon 100 mode active-backup primary eno33554992 ip4 192.168.231.200/24 Connection 'bond0' (dc55d681-0d5a-4de2-8e94-0e5cb2e249c9) successfully added.
primary eno33554992:指定主網卡爲eno33554992 --這裏也能夠不指定primary網卡(備註:子網卡均正常時,primary網卡優先處於活躍狀態)。接口
mode active-backup:指定bonding模式爲active-backupip
miimon 100:以毫秒爲單位指定 MII 連接監控的頻率(默認爲0,即關閉此功能;配置miimon參數時,最好從100開始)。虛擬機
bonding內核模塊必須在ifcfg-bondN中的BONDING_OPTS="bonding parameters"中指定,各參數間使用空格分隔,不要在/etc/modprobe.d/bonding.conf和已經棄用的/etc/modprobe.conf文件中指定bonding配置選項。it
配置完成後,此時會在/etc/sysconfig/network-scripts目錄下生成ifcfg-bond0的配置文件:
[root@test03 network-scripts]# cat ifcfg-bond0 DEVICE=bond0 BONDING_OPTS="miimon=100 mode=active-backup primary=eno33554992" TYPE=Bond BONDING_MASTER=yes BOOTPROTO=none IPADDR=192.168.231.200 PREFIX=24 DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_PEERDNS=yes IPV6_PEERROUTES=yes IPV6_FAILURE_FATAL=no NAME=bond0 UUID=dc55d681-0d5a-4de2-8e94-0e5cb2e249c9 ONBOOT=yes
將網卡eno33554992和eno50332216建立爲bond0的子接口:
# 添加網卡eno33554992:設備類型:bond-slave;鏈接名稱:bond0-p1;master:bond0 [root@test03 network-scripts]# nmcli connection add type bond-slave ifname eno33554992 con-name bond0-p1 master bond0 Connection 'bond0-p1' (aaa54dc4-8122-4246-99e8-afd711e3102d) successfully added. # 添加網卡eno50332216:設備類型:bond-slave;鏈接名稱:bond0-p2;master:bond0 [root@test03 network-scripts]# nmcli connection add type bond-slave ifname eno50332216 con-name bond0-p2 master bond0 Connection 'bond0-p2' (11e38097-2273-4565-bf1c-3ce2e2e2a0ea) successfully added.
配置完成後,此時會在/etc/sysconfig/network-scripts目錄下生成ifcfg-bond0-p1,ifcfg-bond0-p2的配置文件:
[root@test03 network-scripts]# cat ifcfg-bond0-p1 TYPE=Ethernet NAME=bond0-p1 UUID=aaa54dc4-8122-4246-99e8-afd711e3102d DEVICE=eno33554992 ONBOOT=yes MASTER=bond0 SLAVE=yes [root@test03 network-scripts]# [root@test03 network-scripts]# cat ifcfg-bond0-p2 TYPE=Ethernet NAME=bond0-p2 UUID=11e38097-2273-4565-bf1c-3ce2e2e2a0ea DEVICE=eno50332216 ONBOOT=yes MASTER=bond0 SLAVE=yes
查看當前已激活的網絡接口:
[root@test03 network-scripts]# nmcli connection show --active NAME UUID TYPE DEVICE eno16777736 613db14a-2375-4a89-b55a-d2abd8fc65d5 802-3-ethernet eno16777736 bond0-p2 11e38097-2273-4565-bf1c-3ce2e2e2a0ea 802-3-ethernet eno50332216 bond0-p1 aaa54dc4-8122-4246-99e8-afd711e3102d 802-3-ethernet eno33554992 bond0 dc55d681-0d5a-4de2-8e94-0e5cb2e249c9 bond bond0
若是bond0-p一、bond0-p二、bond0沒有激活,可以使用下面命令進行激活:
[root@test03 network-scripts]# nmcli connection up bond0-p1 [root@test03 network-scripts]# nmcli connection up bond0-p2 [root@test03 network-scripts]# nmcli connection up bond0
[root@test03 network-scripts]# cd /proc/net/bonding/ [root@test03 bonding]# ls bond0 [root@test03 bonding]# cat bond0 Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011) Bonding Mode: fault-tolerance (active-backup) Primary Slave: eno33554992 (primary_reselect always) Currently Active Slave: eno33554992 MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0 Slave Interface: eno33554992 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:56:69:57 Slave queue ID: 0 Slave Interface: eno50332216 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:56:69:61 Slave queue ID: 0
首先查看bond0當前狀態:
[root@test03 network-scripts]# cd /proc/net/bonding/ [root@test03 bonding]# ls bond0 [root@test03 bonding]# cat bond0 Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011) Bonding Mode: fault-tolerance (active-backup) Primary Slave: eno33554992 (primary_reselect always) Currently Active Slave: eno33554992 MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0 Slave Interface: eno33554992 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:56:69:57 Slave queue ID: 0 Slave Interface: eno50332216 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:56:69:61 Slave queue ID: 0
當前活躍網卡爲主網卡:eno33554992,長ping bond0 IP地址:ping 192.168.231.200 -t,網絡暢通,如今斷開eno33554992的網絡鏈接:
[root@test03 bonding]# nmcli connection down bond0-p1 Connection 'bond0-p1' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5) # ping 192.168.231.200 -t 來自 192.168.231.200 的回覆: 字節=32 時間=2ms TTL=64 來自 192.168.231.200 的回覆: 字節=32 時間<1ms TTL=64 請求超時。 請求超時。 來自 192.168.231.200 的回覆: 字節=32 時間<1ms TTL=64 來自 192.168.231.200 的回覆: 字節=32 時間<1ms TTL=64
發現網絡短暫斷開後恢復(本次測試環境爲虛擬機,真實物理機應該看不到網絡斷開鏈接的狀況),此時查看bond0狀態爲:
[root@test03 bonding]# cat bond0 Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011) Bonding Mode: fault-tolerance (active-backup) Primary Slave: None Currently Active Slave: eno50332216 MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0 Slave Interface: eno50332216 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:56:69:61 Slave queue ID: 0
如今恢復eno33554992的網絡鏈接:
[root@test03 bonding]# nmcli connection up bond0-p1 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/7) # ping 192.168.231.200 -t 來自 192.168.231.200 的回覆: 字節=32 時間=2ms TTL=64 來自 192.168.231.200 的回覆: 字節=32 時間<1ms TTL=64 請求超時。 請求超時。 來自 192.168.231.200 的回覆: 字節=32 時間<1ms TTL=64 來自 192.168.231.200 的回覆: 字節=32 時間<1ms TTL=64
查看bond0工做狀態爲:
[root@test03 bonding]# cat bond0 Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011) Bonding Mode: fault-tolerance (active-backup) Primary Slave: eno33554992 (primary_reselect always) Currently Active Slave: eno33554992 MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0 Slave Interface: eno50332216 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:56:69:61 Slave queue ID: 0 Slave Interface: eno33554992 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:56:69:57 Slave queue ID: 0