http://www.cnblogs.com/hukey/p/6224969.htmlhtml
1. 简要
双网卡绑定技术在centos7中使用了teaming技术,而在rhel6/centos7中使用的是bonding技术,
在centos7中双网卡绑定既能使用teaming也可使用bonding,这里推荐使用teaming技术,方便与查看和监控。
2. 原理
这里介绍两种最多见的双网卡绑定模式:
(1) roundrobin - 轮询模式
全部链路处于负载均衡状态,这种模式的特色增长了带宽,同时支持容错能力。
(2) activebackup - 主备模式
一个网卡处于活动状态,另外一个处于备份状态,全部流量都在主链路上处理,当活动网卡down掉时,启用备份网卡。linux
3. 基础环境
系统:centos7
在centos7中,关闭虚拟机添加网卡,再开启虚拟机,系统是不会自动生成网卡的配置文件:
在centos7中要生成网卡配置文件的方法很简单,使用以下命令:centos
# 查看物理网卡信息 [root@localhost ~]# nmcli dev DEVICE TYPE STATE CONNECTION eno16777736 ethernet connected eno16777736 eno33554984 ethernet connected Wired connection 1 eno50332208 ethernet connected Wired connection 2 lo loopback unmanaged --
上面的信息能够看到,一共有四张网卡,其中lo是本地回环网卡,另外三张为物理网卡。服务器
# 查看网卡链接信息 [root@localhost ~]# nmcli con sh NAME UUID TYPE DEVICE Wired connection 2 9a1314bf-d273-406a-930a-dc4160dee4ec 802-3-ethernet eno50332208 Wired connection 1 47eef4a3-7fa4-4a73-83ef-1485bda9b950 802-3-ethernet eno33554984 eno16777736 51d00668-2cf5-41da-ad8d-5019d62e98ad 802-3-ethernet eno16777736
上面的信息能够查看到一共有3个链接,其中两个有线链接,表示没有设置过的网卡链接,还有一个enoxx链接。接下来要修改两个有线链接的命名方法,并生成网卡配置文件:网络
# 首先,删除两个无用的有线链接 [root@localhost ~]# nmcli con del 9a1314bf-d273-406a-930a-dc4160dee4ec Connection 'Wired connection 2' (9a1314bf-d273-406a-930a-dc4160dee4ec) successfully deleted. [root@localhost ~]# nmcli con del 47eef4a3-7fa4-4a73-83ef-1485bda9b950 Connection 'Wired connection 1' (47eef4a3-7fa4-4a73-83ef-1485bda9b950) successfully deleted.
4. roundrobin模式:
roundrobin模式也称为轮询模式,它 基于每个包 ,当某一台服务器的两张网卡设置为roundrobin模式teaming,此时服务器发出的数据包,就会在两个物理
网卡上进行轮询,即第一个数据包走一张网卡,第二个数据包走第二张网卡,依次轮询。
注意:
(1)roundrobin具备容错性,当一张网卡down掉,数据包依然发送成功。
(2)在使用roundrobin模式必需要在交换机上作以太通道,否则会出现网络没法连通。负载均衡
实际操做:oop
# 使用nmcli命令操做,建立team接口team0,同时设置teaming模式为roundrobin [root@localhost ~]# nmcli con add type team con-name team0 ifname team0 config '{"runner":{"name": "roundrobin"}}' Connection 'team0' (9dc48bd6-54b9-48db-b7dd-ecf34ae9196f) successfully added.
# 给接口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
# 将两张物理网卡加入到team中 [root@localhost ~]# nmcli con add type team-slave con-name team0-port1 ifname eno33554984 master team0 Connection 'team0-port1' (22d3640e-f5c8-499c-b0dd-913c8970d800) successfully added. [root@localhost ~]# nmcli con add type team-slave con-name team0-port2 ifname eno50332208 master team0 Connection 'team0-port2' (12660d2a-0e1f-41e6-96b2-53de4fc6b78c) successfully added. [root@localhost ~]# nmcli con sh NAME UUID TYPE DEVICE team0-port2 12660d2a-0e1f-41e6-96b2-53de4fc6b78c 802-3-ethernet -- eno16777736 51d00668-2cf5-41da-ad8d-5019d62e98ad 802-3-ethernet eno16777736 team0-port1 22d3640e-f5c8-499c-b0dd-913c8970d800 802-3-ethernet -- team0 9dc48bd6-54b9-48db-b7dd-ecf34ae9196f team team0 eno33554984 32d2389e-4e82-4419-9d18-5aff8f0be003 802-3-ethernet eno33554984 eno50332208 eea2a115-63f8-4f33-be84-12559f02542c 802-3-ethernet eno50332208
如今成功将两张物理网卡绑定到了team组中测试
# 如今查看team0的状态就出现了,模式是:roundrobin [root@localhost ~]# teamdctl team0 st setup: runner: roundrobin ports: eno33554984 link watches: link summary: up instance[link_watch_0]: name: ethtool link: up down count: 0 eno50332208 link watches: link summary: up instance[link_watch_0]: name: ethtool link: up down count: 0
这样,team模式的roundrobin搭建成功。centos7
总结:
在作链路聚合的时候,所要使用到的物理网卡不能独立存在链接,也就是在nmcli con sh查看时,不能独立存在,不然就没法绑定到team模式中。spa
4.1 测试
由于这里是虚拟机环境,只能经过down掉网卡进行查看。
[root@localhost ~]# teamdctl team0 st setup: runner: roundrobin ports: eno33554984 link watches: link summary: up instance[link_watch_0]: name: ethtool link: up down count: 0 eno50332208 link watches: link summary: up instance[link_watch_0]: name: ethtool link: up down count: 0
两张网卡同时在线,如今down掉其中一张网卡,
[root@localhost ~]# nmcli con del team0-port1 Connection 'team0-port1' (0331ea43-95c0-4106-b388-8484d4c3940d) successfully deleted. [root@localhost ~]# nmcli con sh NAME UUID TYPE DEVICE eno16777736 51d00668-2cf5-41da-ad8d-5019d62e98ad 802-3-ethernet eno16777736 team0 9dc48bd6-54b9-48db-b7dd-ecf34ae9196f team team0 team0-port2 880f2146-fe93-42dd-8d28-7d0dd50b4011 802-3-ethernet eno50332208 [root@localhost ~]# teamdctl team0 st setup: runner: roundrobin ports: eno50332208 link watches: link summary: up instance[link_watch_0]: name: ethtool link: up down count: 0
这样就发现eno33554984网卡已经down掉了。
[root@localhost ~]# nmcli con add type team-slave con-name team0-port1 ifname eno33554984 master team0 Connection 'team0-port1' (59acd6bf-affc-4994-a050-83c45816859a) successfully added. [root@localhost ~]# [root@localhost ~]# teamdctl team0 st setup: runner: roundrobin ports: eno33554984 link watches: link summary: up instance[link_watch_0]: name: ethtool link: up down count: 0 eno50332208 link watches: link summary: up instance[link_watch_0]: name: ethtool link: up down count: 0
虚拟机环境就这样测试了吧,至于生产环境就直接拔网线,ping测试。
资料有说linux下roundrobin具备容错的效果,为了测试是否有容错的效果,虚拟机作了下更改来验证:
这一次网卡所有改为桥接模式,为了更好的测试是否具备容错性。
roundrobin已经配置完毕。接下来咱们down掉一张网卡检查是否具备容错性。
经过虚拟机测试,容错性是存在的。
5. 双网卡绑定activebackup的实现
[root@localhost ~]# nmcli con sh NAME UUID TYPE DEVICE team0-port2 2a1aa534-e021-4452-bb0a-2002dabcbc08 802-3-ethernet eno50332208 team0-port1 9a10c9ef-ee9c-4151-9a47-59b4668e8934 802-3-ethernet -- eno16777736 51d00668-2cf5-41da-ad8d-5019d62e98ad 802-3-ethernet eno16777736 team0 c2278f3f-5c6b-4e1d-b925-514d3c3832b6 team team0 [root@localhost ~]# nmcli con del team0 team0-port1 team0-port2 Connection 'team0' (c2278f3f-5c6b-4e1d-b925-514d3c3832b6) successfully deleted. Connection 'team0-port1' (9a10c9ef-ee9c-4151-9a47-59b4668e8934) successfully deleted. Connection 'team0-port2' (2a1aa534-e021-4452-bb0a-2002dabcbc08) successfully deleted. [root@localhost ~]# nmcli con sh NAME UUID TYPE DEVICE eno16777736 51d00668-2cf5-41da-ad8d-5019d62e98ad 802-3-ethernet eno16777736 # 以上操做就删除了roundrobin模式,恢复到初始状态。
# 添加逻辑网卡team0,并启用activebackup模式 [root@localhost ~]# nmcli con add type team con-name team0 ifname team0 config '{"runner":{"name":"activebackup"}}' Connection 'team0' (f0794e59-419d-4c2a-96b9-464610b6321a) successfully added. # 绑定ip [root@localhost ~]# nmcli con modify team0 ipv4.address 192.168.118.122/24 ipv4.gateway 192.168.118.1 [root@localhost ~]# nmcli con modify team0 ipv4.method manual # 添加物理网卡到activebackup模式 [root@localhost ~]# nmcli con add type team-slave con-name team0-port1 ifname eno33554984 master team0 Connection 'team0-port1' (52656904-6e85-4a04-98b4-2b19773fa290) successfully added. [root@localhost ~]# nmcli con add type team-slave con-name team0-port2 ifname eno50332208 master team0 Connection 'team0-port2' (44d96e3a-014a-481f-9122-4ca2d3be9f7a) successfully added.
[root@localhost ~]# teamdctl team0 st setup: runner: activebackup ports: eno33554984 link watches: link summary: up instance[link_watch_0]: name: ethtool link: up down count: 0 eno50332208 link watches: link summary: up instance[link_watch_0]: name: ethtool link: up down count: 0 runner: active port: eno33554984
成功,处于活动中的网卡为 eno33554984
5.1 测试
经过down掉活动网卡测试网络是否仍然处于连通状态
测试成功。注意: 在作网卡绑定的时候,若是发现物理网卡老是没法绑定到team0,请检查该物理网卡是否处于up状态。