前言
之前手动配置Bond容易出错,查看了一下Redhat的官方文档,发现是可以通过NetworkManager去配置Bond的,这篇文章是记录如何使用NetworkManager去配置Bond的。
环境初始化
这次的测试环境如下
hostname | test network |
---|
bond-node1 | 172.11.0.23/22 |
bond-node2 | 172.11.0.24/22 |
初始化bond-node1
首先查看当前的网络
1
2
3
4
| sudo virsh domiflist bond-node1
Interface Type Source Model MAC
-------------------------------------------------------------
vnet3 network default virtio 52:54:00:64:b9:13
|
删除原来的default网络
1
| sudo virsh detach-interface --domain bond-node1 --type network --mac 52:54:00:64:b9:13 --config --live
|
添加2张连接test
网络的网卡
1
2
3
4
| sudo virsh attach-interface --domain bond-node1 --type network \
--source test --model virtio --config --live
sudo virsh attach-interface --domain bond-node1 --type network \
--source test --model virtio --config --live
|
验证:
1
2
3
4
5
| sudo virsh domiflist bond-node1
Interface Type Source Model MAC
------------------------------------------------------------
vnet5 network test virtio 52:54:00:6c:bd:a9
vnet6 network test virtio 52:54:00:d7:22:97
|
另外的一个bond-node2也是如法炮制。
1
2
3
4
5
| sudo virsh detach-interface --domain bond-node2 --type network --mac 52:54:00:c3:65:bf --config --live
sudo virsh attach-interface --domain bond-node2 --type network \
--source test --model virtio --config --live
sudo virsh attach-interface --domain bond-node2 --type network \
--source test --model virtio --config --live
|
bond模式说明
Mode | Policy | How it works | Fault Tolerance | Load balancing |
---|
0 | Round Robin | packets are sequentially transmitted/received through each interfaces one by one. | No | Yes |
1 | Active Backup | one NIC active while another NIC is asleep. If the active NIC goes down, another NIC becomes active. only supported in x86 environments. | Yes | No |
2 | XOR [exclusive OR] | In this mode the, the MAC address of the slave NIC is matched up against the incoming request’s MAC and once this connection is established same NIC is used to transmit/receive for the destination MAC. | Yes | Yes |
3 | Broadcast | All transmissions are sent on all slaves | Yes | No |
4 | Dynamic Link Aggregation | aggregated NICs act as one NIC which results in a higher throughput, but also provides failover in the case that a NIC fails. Dynamic Link Aggregation requires a switch that supports IEEE 802.3ad. | Yes | Yes |
5 | Transmit Load Balancing (TLB) | The outgoing traffic is distributed depending on the current load on each slave interface. Incoming traffic is received by the current slave. If the receiving slave fails, another slave takes over the MAC address of the failed slave. | Yes | Yes |
6 | Adaptive Load Balancing (ALB) | Unlike Dynamic Link Aggregation, Adaptive Load Balancing does not require any particular switch configuration. Adaptive Load Balancing is only supported in x86 environments. The receiving packets are load balanced through ARP negotiation. | Yes | Yes |
配置bond
bond-node1
1
| sudo virsh console bond-node1
|
设置主机名:
1
| hostnamectl set-hostname bond-node1
|
配置bond0模式
1
| nmcli con add type bond ifname bond0 bond.options "mode=balance-rr,miimon=100"
|
配置bond4模式
1
| nmcli con add type bond ifname bond0 bond.options "mode=802.3ad,miimon=100"
|
同时需要配置内核自动加载模块
1
2
| # /etc/modules-load.d/bonding.conf
8021q
|
添加slave网卡
1
2
| nmcli con add type ethernet ifname eth0 master bond0
nmcli con add type ethernet ifname eth1 master bond0
|
启动网卡
1
2
| nmcli con up bond-slave-eth0
nmcli con up bond-slave-eth1
|
配置ip
1
2
| nmcli connection modify bond-bond0 ipv4.method manual ipv4.addresses "172.11.0.23/22" ipv4.dns 114.114.114.114 ipv4.gateway 172.11.0.1 connection.autoconnect yes
nmcli con up bond-bond0
|
bond-node2
1
2
| nmcli connection modify bond-bond0 ipv4.method manual ipv4.addresses "172.11.0.24/22" ipv4.dns 114.114.114.114 ipv4.gateway 172.11.0.1 connection.autoconnect yes
nmcli con up bond-bond0
|
验证
1
| cat /proc/net/bonding/bond0
|
这里可以做一个性能测试来看是否工作正常
安装iperf
工具两个节点都需要:
1
2
| yum install epel-release -y
yum install -y iperf
|
这里是将bond-node1作为服务端,bond-node2作为客户端进行测试。
首先开放防火墙,和启动服务端(bond-node1):
1
2
| firewall-cmd --zone=public --add-port=5001/tcp
iperf -s -i 1 -w 448k
|
bond-node2:
1
| iperf -c 172.11.0.23 -i 1 -w 448k -t 600
|
后记
测试了以下boding感觉还是需要强大的硬件,没有强大的硬件没办法很好玩bonding(一个支持LACP的交换机)。
参考链接