os: centos 7.6
centos7中双网卡绑定除了 bonding 技术外,还能使用 teaming 技术,配置也挺方便。
本次使用的工作方式为 activebackup - 主备模式
bonding 有 0-6 七种模式
第一种模式:mod=0,即:(balance-rr)Round-robin policy(平衡抡循环策略)交换机配置Eth-Trunk
第二种模式:mod=1,即:(active-backup)Active-backup policy(主-备份策略)
第三种模式:mod=2,即:(balance-xor)XOR policy(平衡策略)
第四种模式:mod=3,即:broadcast(广播策略)
第五种模式:mod=4,即:(802.3ad)IEEE 802.3ad Dynamic link aggregation(IEEE802.3ad 动态链接聚合)
第六种模式:mod=5,即:(balance-tlb)Adaptive transmit load balancing(适配器传输负载均衡)
第七种模式:mod=6,即:(balance-alb)Adaptive load balancing(适配器适应性负载均衡)
网络接口
enp0s8,enp0s9不需要配置ip
# nmtui-edit
# ifup enp0s8;ifup enp0s9;
# nmcli dev
DEVICE TYPE STATE CONNECTION
enp0s3 ethernet connected enp0s3
enp0s8 ethernet connecting (getting IP configuration) enp0s8
enp0s9 ethernet connecting (getting IP configuration) enp0s9
lo loopback unmanaged --
# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:23:94:42 brd ff:ff:ff:ff:ff:ff
inet 10.0.2.25/24 brd 10.0.2.255 scope global noprefixroute dynamic enp0s3
valid_lft 1174sec preferred_lft 1174sec
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:dd:ce:b1 brd ff:ff:ff:ff:ff:ff
4: enp0s9: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:74:1a:f4 brd ff:ff:ff:ff:ff:ff
创建 team 类型的接口 team0,模式为 activebackup
# nmcli con show
NAME UUID TYPE DEVICE
enp0s3 54fe5543-f63f-48eb-ad29-48205128e109 ethernet enp0s3
enp0s8 c155dffa-104a-48ad-bacd-38c461439cb3 ethernet enp0s8
enp0s9 3c7a84a7-154f-36a0-8673-dee2366614c4 ethernet enp0s9
# nmcli con add type team con-name team0 ifname team0 config '{"runner":{"name":"activebackup"}}'
Connection 'team0' (10992833-122e-4cb7-9808-77b68af04fdb) successfully added.
# nmcli con show
NAME UUID TYPE DEVICE
enp0s3 54fe5543-f63f-48eb-ad29-48205128e109 ethernet enp0s3
enp0s8 c155dffa-104a-48ad-bacd-38c461439cb3 ethernet enp0s8
enp0s9 3c7a84a7-154f-36a0-8673-dee2366614c4 ethernet enp0s9
team0 10992833-122e-4cb7-9808-77b68af04fdb team team0
添加物理网卡到 team0
# nmcli con add type team-slave con-name team0-port1 ifname enp0s8 master team0
Connection 'team0-port1' (0320bf56-1987-4b34-8b34-fa0790813d12) successfully added.
# nmcli con add type team-slave con-name team0-port2 ifname enp0s9 master team0
Connection 'team0-port2' (5833b612-8904-4501-8b4c-391174469d76) successfully added.
配置ip地址及网管,dns
# nmcli con modify team0 ipv4.address '192.168.56.119/24';
nmcli con modify team0 ipv4.gateway '192.168.56.1';
nmcli con modify team0 ipv4.method manual;
nmcli con up team0;
nmcli con modify team0 ipv4.dns "8.8.8.8";
重启网络服务
# nmcli con show
NAME UUID TYPE DEVICE
enp0s3 54fe5543-f63f-48eb-ad29-48205128e109 ethernet enp0s3
team0 10992833-122e-4cb7-9808-77b68af04fdb team team0
team0-port1 0320bf56-1987-4b34-8b34-fa0790813d12 ethernet enp0s8
team0-port2 5833b612-8904-4501-8b4c-391174469d76 ethernet enp0s9
enp0s8 c155dffa-104a-48ad-bacd-38c461439cb3 ethernet --
enp0s9 3c7a84a7-154f-36a0-8673-dee2366614c4 ethernet --
# teamdctl team0 state
setup:
runner: activebackup
ports:
enp0s8
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up
down count: 0
enp0s9
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up
down count: 0
runner:
active port: enp0s8
查看网卡
# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:23:94:42 brd ff:ff:ff:ff:ff:ff
inet 10.0.2.25/24 brd 10.0.2.255 scope global noprefixroute dynamic enp0s3
valid_lft 1096sec preferred_lft 1096sec
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master team0 state UP group default qlen 1000
link/ether 08:00:27:dd:ce:b1 brd ff:ff:ff:ff:ff:ff
4: enp0s9: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master team0 state UP group default qlen 1000
link/ether 08:00:27:dd:ce:b1 brd ff:ff:ff:ff:ff:ff
6: team0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 08:00:27:dd:ce:b1 brd ff:ff:ff:ff:ff:ff
inet 192.168.56.119/24 brd 192.168.56.255 scope global noprefixroute team0
valid_lft forever preferred_lft forever
故障验证
打开一个窗口一直 ping
来自 192.168.56.119 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.56.119 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.56.119 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.56.119 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.56.119 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.56.119 的回复: 字节=32 时间<1ms TTL=64
vmware 移除虚拟机的网卡 enp0s8
# teamdctl team0 state
setup:
runner: activebackup
ports:
enp0s8
link watches:
link summary: down
instance[link_watch_0]:
name: ethtool
link: down
down count: 0
enp0s9
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up
down count: 0
runner:
active port: enp0s9
显示的 enp0s8 为 down, runner = enp0s9
参考:
删除 team
# nmcli con del team0 team0-port1 team0-port2
断开 team-slave
# nmcli dev dis enp0s8
# nmcli dev con enp0s8
# nmcli con add type team con-name CNAME ifname INAME [config JSON]
JSON语法格式如下:’{“runner”:{“name”:“METHOD”}}’
METHOD 是以下的其中一个:broadcast、activebackup、roundrobin、loadbalance 或者 lacp。
roundrobin - 轮询模式
# nmcli con add type team con-name team0 ifname team0 config '{"runner":{"name": "roundrobin"}}'
activebackup - 主备模式
# nmcli con add type team con-name team0 ifname team0 config '{"runner":{"name":"activebackup"}}'