(一)简述 1.双网卡绑定技术在centos7中使用了teaming技术,而在rhel6/centos7中使用的是bonding技术, 在centos7中双网卡绑定既能使用teaming也可以使用bonding,这里推荐使用teaming技术,方便与查看和监控。
- 原理 这里介绍两种最常见的双网卡绑定模式: (1) roundrobin - 轮询模式 所有链路处于负载均衡状态,这种模式的特点增加了带宽,同时支持容错能力。 (2) activebackup - 主备模式 一个网卡处于活动状态,另一个处于备份状态,所有流量都在主链路上处理,当活动网卡down掉时,启用备份网卡。 3.查看服务器的相关信息:
[root@localhost ~]# nmcli dev
DEVICE TYPE STATE CONNECTION
em1 ethernet connected --
em2 ethernet connected --
em3 ethernet unavailable --
em4 ethernet unavailable --
lo loopback unmanaged --
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
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
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: em1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master team0 state UP qlen 1000
link/ether 36:3c:c4:19:d0:ef brd ff:ff:ff:ff:ff:ff
3: em2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master team0 state UP qlen 1000
link/ether 36:3c:c4:19:d0:ef brd ff:ff:ff:ff:ff:ff
4: em3: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN qlen 1000
link/ether 24:6e:96:a2:dd:ae brd ff:ff:ff:ff:ff:ff
5: em4: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN qlen 1000
link/ether 24:6e:96:a2:dd:af brd ff:ff:ff:ff:ff:ff
18: team0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
link/ether 36:3c:c4:19:d0:ef brd ff:ff:ff:ff:ff:ff
inet 10.128.105.156/24 brd 10.128.105.255 scope global team0
valid_lft forever preferred_lft forever
inet6 fe80::718:e575:f031:47d4/64 scope link
valid_lft forever preferred_lft forever
###########其中state UP 为网卡有网线或启用的网口,有上边的参数可知,em1和em2有网线接口,其他的网口没有。lo为本地回环网卡
(二)Roundrobin(轮询)安装步骤 1,查看网卡的连接信息:nmcli con sh
[root@localhost ~]# nmcli con sh
NAME UUID TYPE DEVICE
em1 4c8a8aee-327b-4f29-9ec4-ea2b2551420b 802-3-ethernet --
em2 62bde3ef-9f40-42aa-9b3a-4fe8b1aabf42 802-3-ethernet --
em3 56ef9d05-3a5d-4cd6-af5b-3d39adce619f 802-3-ethernet --
em4 761f7809-d10c-4e3b-bc06-c0906ca55d1c 802-3-ethernet --
2,删除无用的网卡:nmcli con del em3
[root@localhost ~]# nmcli con del em3
Connection 'em3' (56ef9d05-3a5d-4cd6-af5b-3d39adce619f) successfully deleted.
[root@localhost ~]# nmcli con sh
NAME UUID TYPE DEVICE
em1 4c8a8aee-327b-4f29-9ec4-ea2b2551420b 802-3-ethernet --
em2 62bde3ef-9f40-42aa-9b3a-4fe8b1aabf42 802-3-ethernet --
em4 761f7809-d10c-4e3b-bc06-c0906ca55d1c 802-3-ethernet --
3,# 使用nmcli命令操作,创建team接口team0,同时设置teaming模式为roundrobin
[root@localhost ~]# nmcli con add type team con-name team0 ifname team0 config '{"runner":{"name": "roundrobin"}}'
[root@localhost ~]# nmcli con sh
NAME UUID TYPE DEVICE
team0 5a1976d7-2c91-456e-8dda-0b12c6ef0c04 team team0
em1 4c8a8aee-327b-4f29-9ec4-ea2b2551420b 802-3-ethernet --
em2 62bde3ef-9f40-42aa-9b3a-4fe8b1aabf42 802-3-ethernet --
em4 761f7809-d10c-4e3b-bc06-c0906ca55d1c 802-3-ethernet --
4,给接口team0设置ip地址和网关,并取消手动模式:
[root@localhost ~]# nmcli con modify team0 ipv4.address '10.128.105.157/24' ipv4.gateway '10.128.105.254'
###设置为手动模式,取消DHCP
[root@localhost ~]# nmcli con modify team0 ipv4.method manual
5,使用ifup team0 启用team0网卡,然后重启网络服务。
[root@localhost ~]# ifup team0
[root@localhost ~]# /etc/init.d/network restart
Restarting network (via systemctl): [ OK ]
[root@localhost ~]# ip a |grep team0
2: em1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master team0 state UP qlen 1000
10: team0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
inet 10.128.105.157/24 brd 10.128.105.255 scope global team0
6,再次将两张物理网卡添加到team
[root@localhost ~]# nmcli con add type team-slave con-name team0-port2 ifname em1 master team0
Connection 'team0-port2' (e01c37f5-b3a1-4e6d-96ab-a6e676ad3c32) successfully added.
[root@localhost ~]# nmcli con add type team-slave con-name team0-port2 ifname em2 master team0
Connection 'team0-port2' (8b13a9de-d64c-44fc-a86d-ea45d2f511cf) successfully added.
[root@localhost ~]# nmcli con sh
NAME UUID TYPE DEVICE
team0 64b123d5-189d-43b0-a850-77d47c0da86c team team0
team0-port1 24181898-bffe-4ae1-90e8-f47da64b5512 802-3-ethernet em1
team0-port2 8b13a9de-d64c-44fc-a86d-ea45d2f511cf 802-3-ethernet em2
em1 4c8a8aee-327b-4f29-9ec4-ea2b2551420b 802-3-ethernet --
em2 62bde3ef-9f40-42aa-9b3a-4fe8b1aabf42 802-3-ethernet --
em4 761f7809-d10c-4e3b-bc06-c0906ca55d1c 802-3-ethernet --
7,现在查看team0的状态模式是否是roundrobin。teamdctl team0 st
[root@localhost ~]# teamdctl team0 st
setup:
runner: roundrobin
ports:
em1
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up
down count: 0
em2
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up
down count: 0
这样,team模式的roundrobin搭建成功。
8,测试是否正常工作 8.1,首先把em1网卡禁用,用其他的服务器ping看是否断。
[root@localhost etc]# ifdown em1
Device 'em1' successfully disconnected.
[root@localhost etc]# nmcli con sh
NAME UUID TYPE DEVICE
team0 64b123d5-189d-43b0-a850-77d47c0da86c team team0
team0-port2 8b13a9de-d64c-44fc-a86d-ea45d2f511cf 802-3-ethernet em2
em1 4c8a8aee-327b-4f29-9ec4-ea2b2551420b 802-3-ethernet --
em2 62bde3ef-9f40-42aa-9b3a-4fe8b1aabf42 802-3-ethernet --
em4 761f7809-d10c-4e3b-bc06-c0906ca55d1c 802-3-ethernet --
team0-port1 24181898-bffe-4ae1-90e8-f47da64b5512 802-3-ethernet --
[root@localhost ~]# teamdctl team0 st
setup:
runner: roundrobin
ports:
em2
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up
down count: 0
从上图看出实在正常的。
8.2,把网卡em1启用,em2禁用查看下下
[root@localhost etc]# ifup em1
[root@localhost etc]# nmcli con sh
NAME UUID TYPE DEVICE
team0 64b123d5-189d-43b0-a850-77d47c0da86c team team0
team0-port1 24181898-bffe-4ae1-90e8-f47da64b5512 802-3-ethernet em1
team0-port2 8b13a9de-d64c-44fc-a86d-ea45d2f511cf 802-3-ethernet em2
em1 4c8a8aee-327b-4f29-9ec4-ea2b2551420b 802-3-ethernet --
em2 62bde3ef-9f40-42aa-9b3a-4fe8b1aabf42 802-3-ethernet --
em4 761f7809-d10c-4e3b-bc06-c0906ca55d1c 802-3-ethernet --
[root@localhost etc]# ifdown em2
Device 'em2' successfully disconnected.
[root@localhost etc]# nmcli con sh
NAME UUID TYPE DEVICE
team0 64b123d5-189d-43b0-a850-77d47c0da86c team team0
team0-port1 24181898-bffe-4ae1-90e8-f47da64b5512 802-3-ethernet em1
em1 4c8a8aee-327b-4f29-9ec4-ea2b2551420b 802-3-ethernet --
em2 62bde3ef-9f40-42aa-9b3a-4fe8b1aabf42 802-3-ethernet --
em4 761f7809-d10c-4e3b-bc06-c0906ca55d1c 802-3-ethernet --
team0-port2 8b13a9de-d64c-44fc-a86d-ea45d2f511cf 802-3-ethernet --
网卡流量em2没变,而em1变化了。
(三)双网卡绑定activebackup的实现 具体的大概步骤和上边差不多,省略如下: (首先删除刚才绑定的网卡模式轮询:nmcli con del team0 team0-port1 team0-port2)
1, 添加逻辑网卡team0,并启用activebackup模式
[root@localhost ~]# nmcli con add type team con-name team0 ifname team0 config '{"runner":{"name":"activebackup"}}'
2, 绑定ip
[root@localhost ~]# nmcli con modify team0 ipv4.address 10.128.105.157/24 ipv4.gateway 10.128.105.254
[root@localhost ~]# nmcli con modify team0 ipv4.method manual
3, 添加物理网卡到activebackup模式
[root@localhost ~]# nmcli con add type team-slave con-name team0-port1 ifname em1 master team0
Connection 'team0-port1' (24181898-bffe-4ae1-90e8-f47da64b5512) successfully added.
[root@localhost ~]# nmcli con add type team-slave con-name team0-port2 ifname em2 master team0
Connection 'team0-port2' (8b13a9de-d64c-44fc-a86d-ea45d2f511cf) successfully added.
4,查看状态
[root@localhost ~]# teamdctl team0 st
setup:
runner: activebackup
ports:
em1
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up
down count: 0
em2
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up
down count: 0
runner:
active port: em1
成功,处于活动中的网卡为 eno33554984
备注:注意 在做网卡绑定的时候,如果发现物理网卡总是无法绑定到team0,请检查该物理网卡是否处于up状态。还有就是主备模式在切换的过程中会有间隔,会丢几个包。
重要:命令简述 二,双网卡绑定round_bin 双网卡轮询 1.# 查看物理网卡信息 [root@localhost ~]# nmcli dev 2. # 查看网卡连接信息 [root@localhost ~]# nmcli con sh 3.# 首先,删除两个无用的有线连接 [root@localhost ~]# nmcli con del 4. # 最后,查看下 [root@localhost ~]# nmcli con sh
5.# 使用nmcli命令操作,创建team接口team0,同时设置teaming模式为roundrobin [root@localhost ~]# nmcli con add type team con-name team0 ifname team0 config '{"runner":{"name": "roundrobin"}}' 6. # 给接口team0设置ip地址 [root@localhost ~]# nmcli con modify team0 ipv4.address '10.0.0.2/24' ipv4.gateway '10.0.0.1' ####### 设置为手动模式,取消DHCP [root@localhost ~]# nmcli con modify team0 ipv4.method manual
-
使用ifup 启动team0并没有成功,继续排查
[root@localhost ~]# ifup team0 (关闭网卡em1命令:ifdown em1 ) [root@localhost ~]# ip a | grep team0 8 # 再次将两张物理网卡添加到team [root@localhost ~]# nmcli con add type team-slave con-name team0-port1 ifname em1 master team0 Connection 'team0-port1' (0331ea43-95c0-4106-b388-8484d4c3940d) successfully added. [root@localhost ~]# nmcli con add type team-slave con-name team0-port2 ifname em2 master team0
9# 现在查看team0的状态就出现了,模式是:roundrobin [root@localhost ~]# teamdctl team0 st