redhat7linux双网卡绑定,centos7/redhat7双网卡绑定

简要

双网卡绑定技术在centos7中使用了teaming技术,而在rhel6/centos7中使用的是bonding技术,

在centos7中双网卡绑定既能使用teaming也可以使用bonding,这里推荐使用teaming技术,方便与查看和监控。

原理

这里介绍两种最常见的双网卡绑定模式:

(1) roundrobin - 轮询模式

所有链路处于负载均衡状态,这种模式的特点增加了带宽,同时支持容错能力。

(2) activebackup - 主备模式

一个网卡处于活动状态,另一个处于备份状态,所有流量都在主链路上处理,当活动网卡down掉时,启用备份网卡。

基础环境

系统:centos7

在centos7中,关闭虚拟机添加网卡,再开启虚拟机,系统是不会自动生成网卡的配置文件:

在centos7中要生成网卡配置文件的方法很简单,使用如下命令:

查看物理网卡信息

[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.

再次创建新的连接并生成配置文件

[root@localhost ~]# nmcli conn add type ethernet con-name eno50332208 ifname eno50332208

Connection 'eno50332208' (eea2a115-63f8-4f33-be84-12559f02542c) successfully added.

[root@localhost ~]# nmcli conn add type ethernet con-name eno33554984 ifname eno33554984

Connection 'eno33554984' (32d2389e-4e82-4419-9d18-5aff8f0be003) successfully added.

# 最后,查看下

[root@localhost ~]# nmcli con sh

NAME UUID TYPE DEVICE

eno16777736 51d00668-2cf5-41da-ad8d-5019d62e98ad 802-3-ethernet eno16777736

eno33554984 32d2389e-4e82-4419-9d18-5aff8f0be003 802-3-ethernet eno33554984

eno50332208 eea2a115-63f8-4f33-be84-12559f02542c 802-3-ethernet eno50332208

[root@localhost ~]# ll /etc/sysconfig/network-scripts/ifcfg-eno*

-rw-r--r--. 1 root root 394 Nov 26 05:59 /etc/sysconfig/network-scripts/ifcfg-eno16777736

-rw-r--r--. 1 root root 288 Dec 26 08:44 /etc/sysconfig/network-scripts/ifcfg-eno33554984

-rw-r--r--. 1 root root 288 Dec 26 08:44 /etc/sysconfig/network-scripts/ifcfg-eno50332208

网络连接和配置文件都成功生成了。 接下来通过eno33554984 和 eno50332208 使用teaming模式进行双网卡绑定

roundrobin模式:

roundrobin模式也称为轮询模式,它 基于每一个包 ,当某一台服务器的两张网卡设置为roundrobin模式teaming,此时服务器发出的数据包,就会在两个物理

网卡上进行轮询,即第一个数据包走一张网卡,第二个数据包走第二张网卡,依次轮询。

注意:

(1)roundrobin具有容错性,当一张网卡down掉,数据包依然发送成功。

(2)在使用roundrobin模式必须要在交换机上做以太通道,不然会出现网络无法连通。

实际操作:

使用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

查看team0的状态

[root@localhost ~]# teamdctl team0 st

setup:

runner: roundrobin

4.1 roundrobin问题排查

第一次查看出现的是这样的结果,检查下配置:

# 通过直接查看网卡发现team0并没有启动

[root@localhost ~]# ip a | grep team0

5: team0: mtu 1500 qdisc noqueue state DOWN

# 使用ifup 启动team0并没有成功,继续排查

[root@localhost ~]# ifup team0

[root@localhost ~]# ip a | grep team0

5: team0: mtu 1500 qdisc noqueue state DOWN

直接sysetmctl restart network 也没有成功。

# 发现team0-port1 team0-port2没有添加成功物理网卡,怎么回事呢?

[root@localhost ~]# nmcli con sh

NAME UUID TYPE DEVICE

team0-port2 ec96c1e1-d268-4ba1-a2f9-0133a9f02655 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

# 删除掉

[root@localhost ~]# nmcli con del team0-port1

Connection 'team0-port1' (22d3640e-f5c8-499c-b0dd-913c8970d800) successfully deleted.

[root@localhost ~]# nmcli con del team0-port2

Connection 'team0-port2' (ec96c1e1-d268-4ba1-a2f9-0133a9f02655) 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

eno33554984 32d2389e-4e82-4419-9d18-5aff8f0be003 802-3-ethernet eno33554984

eno50332208 eea2a115-63f8-4f33-be84-12559f02542c 802-3-ethernet eno50332208

[root@localhost ~]# nmcli con del eno33554984 eno50332208

Connection 'eno33554984' (32d2389e-4e82-4419-9d18-5aff8f0be003) successfully deleted.

Connection 'eno50332208' (eea2a115-63f8-4f33-be84-12559f02542c) 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

# 再次将两张物理网卡添加到team

[root@localhost ~]# nmcli con add type team-slave con-name team0-port1 ifname eno33554984 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 eno50332208 master team0

Connection 'team0-port2' (880f2146-fe93-42dd-8d28-7d0dd50b4011) successfully added.

[root@localhost ~]# nmcli con sh

NAME UUID TYPE DEVICE

team0-port1 0331ea43-95c0-4106-b388-8484d4c3940d 802-3-ethernet eno33554984

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

现在成功将两张物理网卡绑定到了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搭建成功。

总结:

在做链路聚合的时候,所要使用到的物理网卡不能独立存在连接,也就是在nmcli con sh查看时,不能独立存在,否则就无法绑定到team模式中。

4.2 测试

因为这里是虚拟机环境,只能通过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测试。

转载来源:https://www.cnblogs.com/hukey/p/6224969.html

你可能感兴趣的:(redhat7linux双网卡绑定,centos7/redhat7双网卡绑定)