利用多張網卡整合成單一連線技術,可提升網路量、負載或容錯能力。
以下範例採用Dell R210 主機,兩張網卡,CentOS 7、Active-Backup模式作為設定:
mode=1 (active-backup)
Active-backup policy: In this mode, only one slave in the bond is active. The other one will become active, only when the active slave fails.
The bond’s MAC address is externally visible on only one port (network adapter) to avoid confusing the switch. This mode provides fault tolerance.
mode=6 (balance-alb)
Adaptive load balancing: includes balance-tlb plus receive load balancing (rlb) for IPV4 traffic, and does not require any special switch support.
The receive load balancing is achieved by ARP negotiation.
The bonding driver intercepts the ARP Replies sent by the local system on their way out and overwrites the source hardware address with the
unique hardware address of one of the slaves in the bond such that different peers use different hardware addresses for the server.
一、Creating the Bonding interface
Please check the module bonding is already enabled.
#lsmod | grep bonding
If it is not enabled, please enable it using the following command.
#modprobe bonding
1. Use the nmcli connection command without any arguments to view the existing network connections. You can shorten the “connection” argument to “con“
# nmcli connection NAME UUID TYPE DEVICE em1 ab251811-2b4b-4ab4-8863-90d07fc887cc 802-3-ethernet em1 em2 0882d018-7199-4f3f-9d61-97f77c3f0e5e 802-3-ethernet --
2. Include the “add type bond” arguments, and any additional information to create a network bond connection.
# nmcli con add type bond con-name bond0 ifname bond0 mode active-backup ip4 172.16.25.111/24 Connection 'bond0' (259e1bb0-8f60-4b26-8e0c-4776da856ebf) successfully added.
3. The ‘nmcli con add type bond’ command creates an interface configuration file in the /etc/sysconfig/network-scripts directory.
# cat /etc/sysconfig/network-scripts/ifcfg-bond0 DEVICE=bond0 BONDING_OPTS=mode=active-backup TYPE=Bond BONDING_MASTER=yes BOOTPROTO=none IPADDR=192.168.219.150 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 IPV6_ADDR_GEN_MODE=stable-privacy NAME=bond0 UUID=1a75eef0-f2c9-417d-81a0-fabab4a1531c ONBOOT=yes
若想更改為其他模式,例如mode6,可改為:
BONDING_OPTS="miimon=100 mode=6" # systemctl restart network.service
4. The ip addr command shows the new bond0 interface:
# ip addr show bond0 9: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000 link/ether d4:ae:52:bd:93:ba brd ff:ff:ff:ff:ff:ff inet 172.16.25.111/24 brd 172.16.25.255 scope global bond0 valid_lft forever preferred_lft forever inet6 fe80::1697:6379:1670:9b3e/64 scope link valid_lft forever preferred_lft forever
二、Creating the Slave Interfaces
1. For each interface that you want to bond, use the ‘nmcli con add type bond-slave‘ command. 將各張網卡綁定:
# nmcli con add type bond-slave ifname em1 master bond0
2. The following example adds the em2 interface as a “bond-slave“.
# nmcli con add type bond-slave ifname em2 master bond0
3. The nmcli con command shows the new connections.
# nmcli connection
4. The nmcli con add type bond-slave commands create interface configuration files in the /etc/sysconfig/network-scripts directory.
# cat /etc/sysconfig/network-scripts/ifcfg-bond-slave-em1 TYPE=Ethernet NAME=bond-slave-em1 UUID=4a058211-d3ef-45e5-96d9-5de7284eb6a3 DEVICE=em1 ONBOOT=yes MASTER=bond0 SLAVE=yes # cat /etc/sysconfig/network-scripts/ifcfg-bond-slave-em2 TYPE=Ethernet NAME=bond-slave-em2 UUID=4167684e-1502-4a76-bb0c-fc28cf589bb5 DEVICE=em2 ONBOOT=yes MASTER=bond0 SLAVE=yes
5. The ip addr command includes “SLAVE” for the ens33 and ens37 interfaces and also includes “master bond0“.
三、Activating the Bond
1
# nmcli connection up bond-slave-em1 # nmcli connection up bond-slave-em2 # nmcli con up bond0
2. The ip addr command, or the ip link command, now shows the slave and the bond interfaces that are UP.
# ip link 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT qlen 1 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: em1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc mq master bond0 state UP mode DEFAULT qlen 1000 link/ether d4:ae:52:bd:93:ba brd ff:ff:ff:ff:ff:ff 3: em2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc mq master bond0 state UP mode DEFAULT qlen 1000 link/ether d4:ae:52:bd:93:bb brd ff:ff:ff:ff:ff:ff 9: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT qlen 1000 link/ether d4:ae:52:bd:93:ba brd ff:ff:ff:ff:ff:ff
四、Viewing Network Bonding Information
1. Each network interface contains a directory in the /sys/class/net directory. For example:
# ls /sys/class/net bond0 bonding_masters em1 em2 lo
2. In this example, a network bond named ‘bond0’ exists. A directory of the same name exists that contains configuration information for that bond. For example:
# ls /sys/class/net/bond0
3. Within this directory is a bonding directory that contains information for the bond0 interface. For example:
# ls /sys/class/net/bond0/bonding
4. There are also directories that contain information for each of the slaves. For example:
# ls /sys/class/net/bond0/lower_em1
5. Following are some examples of viewing files in the /sys/class/net directory.
# cat /sys/class/net/bonding_masters bond0 # cat /sys/class/net/bond0/operstate up # cat /sys/class/net/bond0/address d4:ae:52:bd:93:ba # cat /sys/class/net/bond0/bonding/active_slave em1 目前模式: # cat /sys/class/net/bond0/bonding/mode active-backup 1 或 balance-alb 6 可用網卡共: # cat /sys/class/net/bond0/bonding/slaves em1 em2
6. Following is an example of viewing the /proc/net/bonding/bond0 file.
# cat /proc/net/bonding/bond0 Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011) Bonding Mode: adaptive load balancing Primary Slave: None Currently Active Slave: em1 MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0 Slave Interface: em1 MII Status: up Speed: 100 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: d4:ae:52:bd:93:ba Slave queue ID: 0 Slave Interface: em2 MII Status: up Speed: 100 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: d4:ae:52:bd:93:bb Slave queue ID: 0
# nmcli connection NAME UUID TYPE DEVICE bond-slave-em1 4a058211-d3ef-45e5-96d9-5de7284eb6a3 802-3-ethernet em1 bond-slave-em2 4167684e-1502-4a76-bb0c-fc28cf589bb5 802-3-ethernet em2 bond0 259e1bb0-8f60-4b26-8e0c-4776da856ebf bond bond0 em1 ab251811-2b4b-4ab4-8863-90d07fc887cc 802-3-ethernet -- em2 0882d018-7199-4f3f-9d61-97f77c3f0e5e 802-3-ethernet --
# ifconfig
bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST> mtu 1500
inet 172.16.25.111 netmask 255.255.255.0 broadcast 172.16.25.255
inet6 fe80::1697:6379:1670:9b3e prefixlen 64 scopeid 0x20<link>
ether d4:ae:52:bd:93:ba txqueuelen 1000 (Ethernet)
RX packets 6717 bytes 1015934 (992.1 KiB)
RX errors 0 dropped 7 overruns 0 frame 0
TX packets 505 bytes 78380 (76.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
em1: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500
ether d4:ae:52:bd:93:ba txqueuelen 1000 (Ethernet)
RX packets 3612 bytes 530652 (518.2 KiB)
RX errors 0 dropped 3441 overruns 0 frame 0
TX packets 505 bytes 78380 (76.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
em2: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500
ether d4:ae:52:bd:93:bb txqueuelen 1000 (Ethernet)
RX packets 3105 bytes 485282 (473.9 KiB)
RX errors 0 dropped 4 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 129 bytes 12604 (12.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 129 bytes 12604 (12.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0