实验环境:centos7 ,网卡 ens1,ens2
方法1:修改配置文件做 bond0 (证实有效)
1、创建 bond0 配置文件
[root@localhost sysconfig]# cat /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
BOOTPROTO=none
ONBOOT=yes
TYPE=Ethernet
IPADDR=192.168.1.3
GATEWAY=192.168.1.1
PREFIX=24
IPV6INIT=no
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
BONDING_OPTS="mode=0"
DNS1=199.29.29.29
NDS2=223.5.5.5
2、修改网卡 em1、em2 配置文件
[root@localhost sysconfig]# cat /etc/sysconfig/network-scripts/ifcfg-em1
DEVICE=em1
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
IPV6INIT=no
[root@localhost sysconfig]# cat /etc/sysconfig/network-scripts/ifcfg-em2
DEVICE=em2
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
IPV6INIT=no
3、重启网络
systemctl restart network
4、检测
[root@localhost sysconfig]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: load balancing (round-robin)
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: em2
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 18:66:da:4d:c3:e8
Slave queue ID: 0
Slave Interface: em1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 18:66:da:4d:c3:e7
Slave queue ID: 0
方法2:使用 nmcli 命令做 bond1
网卡 eth0、eth1 做 bond1
1.添加 bond
mcli connection add type bond con-name bond0 ifname bond0 mode active-backup ip4 172.25.254.136/24
2.监测bond变动以及网络状态(新开一个终端)
watch -n 1 cat /proc/net/bonding/bond0
3.分别绑定两块网卡到bond上去:
nmcli connection add con-name eth0 ifname eth0 type bond-slave master bond0
nmcli connection add con-name eth1 ifname eth1 type bond-slave master bond0
4.通过停掉其中一块网卡观察bond反应以及网络变化
ifconfig eth0 down #停掉eth0
nmcli connection delete eth0 #将eth0从bond解绑
nmcli connection add con-name eth0 ifname eth0 type bond-slave master bond0 #加上eth0
ifconfig eth1 down #停掉eth1
方法3,使用 nmcli 命令做 team (证实有效)
1、设置绑定模式 loadbalance
nmcli con add type team con-name team0 ifname team0 config '{"runner":{"name":"loadbalance"}}'
3、设置 team0 的 ip,掩码,网关,手工模式
nmcli con modify team0 ipv4.addresses '10.2.5.117/24' ipv4.gateway '10.2.5.254' ipv4.method manual
4、将 em1 和 em2 分别加入 team0 组
nmcli con add type team-slave con-name team0-port1 ifname em1 master team0
nmcli con add type team-slave con-name team0-port2 ifname em2 master team0
5、查看网卡信息,若发现有橙色的要启动
nmcli con sh
6、若发现有橙色的要启动
nmcli con up team0
7、重启网络
systemctl restart network
8、查看服务启动,确保 active
systemctl status network
systemctl status NetworkManager
8、查看teaming绑定结果
teamdctl team0 st
ethtool team0
-
team 与 bond 区别
team 可以理解为 bond 的升级
A Comparison of Features in Bonding and Team**
Feature | Bonding | Team |
---|---|---|
broadcast Tx policy | Yes | Yes |
round-robin Tx policy | Yes | Yes |
active-backup Tx policy | Yes | Yes |
LACP (802.3ad) support | Yes (active only) | Yes |
Hash-based Tx policy | Yes | Yes |
User can set hash function | No | Yes |
Tx load-balancing support (TLB) | Yes | Yes |
LACP hash port select | Yes | Yes |
load-balancing for LACP support | No | Yes |
Ethtool link monitoring | Yes | Yes |
ARP link monitoring | Yes | Yes |
NS/NA (IPv6) link monitoring | No | Yes |
ports up/down delays | Yes | Yes |
port priorities and stickiness (“primary” option enhancement) | No | Yes |
separate per-port link monitoring setup | No | Yes |
multiple link monitoring setup | Limited | Yes |
lockless Tx/Rx path | No (rwlock) | Yes (RCU) |
VLAN support | Yes | Yes |
user-space runtime control | Limited | Full |
Logic in user-space | No | Yes |
Extensibility | Hard | Easy |
Modular design | No | Yes |
Performance overhead | Low | Very Low |
D-Bus interface | No | Yes |
multiple device stacking | Yes | Yes |
zero config using LLDP | No | (in planning) |
NetworkManager support | Yes | Yes |
参考文章: