NIC Bonding on CentOS 7 with nmtui
當系統管理員希望增加可用帶寬,並提供冗餘和負載平衡的數據傳輸,內核支持bonding允許以聚合的方式實現。簡單地說,綁定意味着將兩個或多個物理網絡接口(稱爲奴隸)聚合成一個單獨的邏輯節點(稱爲主網絡)。如果一個特定的NIC(網絡接口卡)的經驗問題,通信不受影響只要其他保持活躍。
1.先決條件
默認情況下,bonding內核模塊沒有啓用。因此,我們將需要加載它並確保它持久。使用modprobe--first-time加載bonding模塊,如果加載模塊失敗,會發出警告。
# modprobe --first-time bonding
以上的命令僅加載bondiing模塊爲當前會話,服務器重啓後模塊不會自動加載。爲了確保持續加載,創建/etc/modules-load.d/bonding.conf文件放置於文件夾/etc/modules-load.d目錄中,確保每次服務器重啓時加載bonding模塊。
# echo "# Load thebonding kernel module at boot" > /etc/modules-load.d/bonding.conf
# echo "bonding">> /etc/modules-load.d/bonding.conf
服務器重啓之後確保bonding模塊自動加載
[root@MiWiFi-R3-srvDesktop]# lsmod|grep bonding
bonding 136705 0
[root@MiWiFi-R3-srvDesktop]#
2.配置bonding
查看系統當前可用網卡,當前兩塊網卡上均無可用連接。
[root@MiWiFi-R3-srv ~]# nmcli device status
DEVICE TYPE STATE CONNECTION
bond0 bond disconnected --
eno16777736 ethernet disconnected --
eno33554992 ethernet disconnected --
lo loopback unmanaged --
[root@MiWiFi-R3-srv ~]# nmcli connection show
NAME UUID TYPE DEVICE
當前服務器網卡信息如下
[root@MiWiFi-R3-srvDesktop]# ifconfig
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 00:0c:29:51:e8:75 txqueuelen 1000 (Ethernet)
RX packets 2227 bytes 216343 (211.2 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 109 bytes 10643 (10.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier0 collisions 0
eno33554992:flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 00:0c:29:51:e8:7f txqueuelen 1000 (Ethernet)
RX packets 2633 bytes 300745 (293.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 138 bytes 11748 (11.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo:flags=73<UP,LOOPBACK,RUNNING> mtu65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 2 bytes 196 (196.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2 bytes 196 (196.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@MiWiFi-R3-srvDesktop]#
登陸圖形界面,nmtui打開配置界面如下
[root@MiWiFi-R3-srvDesktop]#nmtui
點擊add
bondàcreate進去bond配置界面
設置profile name及device名,選擇add添加網卡,如下
設置profile name 爲eth0,device設置爲網卡eno16777736,點擊ok。相同方法配置eth1,device設置爲eno33554992。
配置完成後,返回主界面,設置mode爲active-backup,設置primary設備爲eno16777736。點擊ok退出。
查看服務器當前配置
[root@MiWiFi-R3-srvDesktop]# cat /proc/net/bonding/mybond
Ethernet Channel BondingDriver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance(active-backup)
Primary Slave: eno16777736(primary_reselect always)
Currently Active Slave:eno16777736
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:51:e8:7f
Slave queue ID: 0
Slave Interface: eno16777736
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr:00:0c:29:51:e8:75
Slave queue ID: 0
[root@MiWiFi-R3-srvDesktop]#
查看網卡信息,eno16777736與eno33554992網卡mac地址相同
[root@MiWiFi-R3-srvDesktop]# ifconfig
eno16777736:flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500
ether 00:0c:29:51:e8:7f txqueuelen 1000 (Ethernet)
RX packets 3626 bytes 343058 (335.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 138 bytes 15571 (15.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eno33554992:flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500
ether 00:0c:29:51:e8:7f txqueuelen 1000 (Ethernet)
RX packets 4034 bytes 428144 (418.1 KiB)
RX errors 0 dropped 34 overruns 0 frame 0
TX packets 139 bytes 11838 (11.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo:flags=73<UP,LOOPBACK,RUNNING> mtu65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 2 bytes 196 (196.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2 bytes 196 (196.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
mybond:flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST> mtu 1500
inet 192.168.31.119 netmask 255.255.255.0 broadcast 192.168.31.255
inet6 fe80::20c:29ff:fe51:e87f prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:51:e8:7f txqueuelen 0 (Ethernet)
RX packets 66 bytes 8172 (7.9 KiB)
RX errors 0 dropped 34 overruns 0 frame 0
TX packets 30 bytes 5018 (4.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@MiWiFi-R3-srvDesktop]#
再次查看當前設置狀態
[root@MiWiFi-R3-srvDesktop]# nmcli device status
DEVICE TYPE STATE CONNECTION
mybond bond connected mybond
eno16777736 ethernet connected eth0
eno33554992 ethernet connected eth1
bond0 bond disconnected --
lo loopback unmanaged --
[root@MiWiFi-R3-srv ~]#
當前設備的鏈接信息
[root@MiWiFi-R3-srvDesktop]# nmcli connection show
NAME UUID TYPE DEVICE
eth0 4435f07a-4585-452e-85a5-c9a968d48bab 802-3-ethernet eno16777736
eth1 48142a3f-a088-4e27-9d96-ccc586792980 802-3-ethernet eno33554992
mybond fcc6f5d4-5da6-499d-97e5-e7b5ba1cd2a0 bond mybond
3.bonding模式
mode= value
balance-rr or 0
Sets a round-robin policy for faulttolerance and load balancing.Transmissions are received and sent outsequentially on each bonded slave interface beginning with the first oneavailable.
active-backup or 1
Sets an active-backup policyfor fault tolerance.Transmissions arereceived and sent out via the first available bonded slave interface. Anotherbonded slave interface is only used if the active bonded slave interface fails.
balance-xo ror 2
Transmissions are based on the selected hashpolicy. The
default is to derive a hash by XOR ofthe source and destination MAC addresses multipliedby the modulo of the number of slave interfaces. In this mode traffic destined for specific peers will always be sent over thesame interface. As the destination is determinedby the MAC addresses this method works best for traffic to peers on the same linkor local network. If traffic has to pass through a single router then this modeof traffic balancing will be suboptimal.
broadcast or 3
Sets a broadcast policy for fault tolerance.All transmissions are sent on all slave interfaces.
80 2.3ad or 4
Sets an IEEE 802.3ad dynamiclink aggregation policy. Creates aggregation groups that share the same speedand duplex settings. Transmits and receives on all slaves in the activeaggregator. Requires a switch that is 802.3ad compliant.
balance-tlb or5
Sets a Transmit Load Balancing (TLB) policyfor fault tolerance and load balancing. The outgoing traffic is distributed accordingto the current load on each slave interface. Incoming traffic is received bythe current slave. If the receiving slave fails, another slave takes over theMAC address of the failed slave. This mode is only suitable for local addressesknown to the kernel bonding module and therefore cannot be used behind a bridgewith virtual machines.
balance-alb or6
Sets an Adaptive Load Balancing (ALB) policyfor fault tolerance and load balancing. Includes transmit and receive loadbalancing for IP v4 traffic.Receive load balancing is achieved through AR Pnegotiation. This mode is only suitable for local addresses known to the kernelbonding module and therefore cannot be used behind a bridge with virtualmachines.