LINUX学生会

centos7上实现bonding

2017-07-02  本文已影响708人  fengkaipeng

centos7中网络管理需要用到nmcli这个工具,全称为NetworkManager command line tool,下面介绍的bondding是使用nmcli工具完成的。

环境

两块网卡:

bonding

1. 先查看一下信息:
[root@www ~]# nmcli connection show 
NAME  UUID                                  TYPE            DEVICE 
eth0  c6852fda-3d65-4874-8849-0645e0bc06dd  802-3-ethernet  eth0   #NAME列为端口链接名   
eth1  30563221-eac0-4128-bb2b-a492522a1333  802-3-ethernet  eth1
2. 创建bond虚拟网卡
[root@www ~]# nmcli connection add type bond con-name bond0 ifname bond0 mode balance-rr ipv4.method manual ipv4.addresses 172.17.99.99/16 ipv4.gateway 172.17.0.1 #这里模式选用了轮询模式,还有很多模式,可以补全显示出来 
Connection 'bond0' (c0d52464-c50a-41c8-8843-d4af1b999b5c) successfully added.
3. 创建真实网卡配置文件
[root@www network-scripts]# nmcli connection add type bond-slave ifname eth0 master bond0  #将eth0加入到bond0组中
Connection 'bond-slave-eth0' (bedfd9a8-10b6-4ceb-92d5-22c2ae99347d) successfully added.
[root@www network-scripts]# nmcli connection add type bond-slave ifname eth1 master bond0 #将eth1加入到bond0中
Connection 'bond-slave-eth1' (5970aede-20d6-4536-a463-d3c12dd77d14) successfully added.

这里type类型为bond-slave,表示这块真实网卡属于一块附属的网卡,配置的属性都不能使用了,master表示这块从属网卡属于bond0这个组中

4. 启用

之前生成了bond0和eth0,eth1的配置文件,但是0和1的新配置文件还没有使用,我们来看下:

[root@www network-scripts]# nmcli connection show 
NAME             UUID                                  TYPE            DEVICE 
bond0            c0d52464-c50a-41c8-8843-d4af1b999b5c  bond            bond0  
eth0             c6852fda-3d65-4874-8849-0645e0bc06dd  802-3-ethernet  eth0   
eth1             30563221-eac0-4128-bb2b-a492522a1333  802-3-ethernet  eth1   
bond-slave-eth0  bedfd9a8-10b6-4ceb-92d5-22c2ae99347d  802-3-ethernet  --  #生效的还是eth0和1的原有配置文件,新生成的配置文件和网卡没有挂上,这里显示的--   
bond-slave-eth1  5970aede-20d6-4536-a463-d3c12dd77d14  802-3-ethernet  --

需要将bond-slave-eth0bond-slave-eth1启用,如下:

[root@www network-scripts]# nmcli connection up bond-slave-eth0
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4)
[root@www network-scripts]# nmcli connection up bond-slave-eth1
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4)
5. 验证

这个时候,用ip a命令看到原来的网卡应该已经不能使用了,取代的是虚拟网卡,而且可以看到三个网卡的MAC地址是相同的,如下:

eth0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP qlen 1000  link/ether 00:0c:29:05:ca:d6 brd ff:ff:ff:ff:ff:ff
eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP qlen 1000  link/ether 00:0c:29:05:ca:d6 brd ff:ff:ff:ff:ff:ff
bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000 link/ether 00:0c:29:05:ca:d6 brd ff:ff:ff:ff:ff:ff

可以cat /proc/net/bonding/bond0来查看详细信息:

...
Bonding Mode: load balancing (round-robin) #轮询模式
...

Slave Interface: eth0 #从接口eth0
MII Status: up #启用状态
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:05:ca:d6
Slave queue ID: 0

Slave Interface: eth1 #从接口eth1
MII Status: up  #启用状态
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:05:ca:e0
Slave queue ID: 0

看到bond模式为轮询,两块网卡都处于up状态,实验成功

上一篇下一篇

猜你喜欢

热点阅读