CentOS7.x下bonding的配置及删除

2020-04-30   169 次阅读


记一次ct7系列下网卡bonding的配置过程,centos6的bonding配置请参考centos6下bonding的配置

环境介绍:

操作系统版本内核网卡名称
CentOSLinuxrelease7.2.1511(Core)3.10.0-327.el7.x86_64eno33554960/eno50332184

1.备份网卡配置文件:

[root@localhost ~]$ cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]$ mkdir /tmp/net_bak
[root@localhost network-scripts]$ cp ifcfg-* /tmp/net_bak/
[root@localhost network-scripts]$ ls /tmp/net_bak/
ifcfg-eno16777736 ifcfg-eno33554960 ifcfg-eno50332184 ifcfg-eno67109408 ifcfg-eno83886632 ifcfg-lo

2.使用系统内置命令nmcli配置bonding,mode 1模式

[root@localhost network-scripts]$ nmcli connection add type bond ifname bond0 mode 1                    # 生成bond配置文件
[root@localhost network-scripts]$ nmcli connection add type bond-slave ifname eno33554960 master bond0  # 将网卡'eno33554960'与'eno50332184'绑定到bond0
[root@localhost network-scripts]$ nmcli connection add type bond-slave ifname eno50332184 master bond0  # 将网卡'eno33554960'与'eno50332184'绑定到bond0
[root@localhost network-scripts]$ ls ifcfg-bond-*     # 查看生成的配置文件
ifcfg-bond-bond0 ifcfg-bond-slave-eno33554960 ifcfg-bond-slave-eno50332184
  • bonding模式介绍:
    • balance-rr (0) –轮询模式,负载均衡(bond默认的模式)
    • active-backup (1) –主备模式(常用)
    • balance-xor (2) -平衡模式
    • broadcast (3) -广播模式
    • 802.3ad (4) –动态链接聚合模式
    • balance-tlb (5) -适配器传输负载均衡
    • balance-alb (6) -适配器适应性负载均衡

3.修改bond0网卡配置

[root@localhost network-scripts]$ vim ifcfg-bond-bond0
#修改如下参数即可
BONDING_OPTS="mode=active-backup miimon=100"  # 这里注意,需要添加侦测时间参数。
BOOTPROTO=static                              #将 dhcp 改为static
IPADDR=10.110.11.22                           # 配置 IP 地址
PREFIX=24                                     # 配置掩码 
GATEWAY=10.110.11.254                         # 配置网关

4.关闭和停止NetworkManager服务

[root@localhost network-scripts]$ systemctl stop NetworkManager
[root@localhost network-scripts]$ systemctl disable NetworkManager

5.重启网络,验证配置结果

[root@localhost network-scripts]$ ip addr show
1: lo:<LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
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: 'eno33554960:<BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP qlen 1000'
link/ether 00:0c:29:07:2c:90 brd ff:ff:ff:ff:ff:ff
3: 'eno50332184:<BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP qlen 1000'
link/ether 00:0c:29:07:2c:90 brd ff:ff:ff:ff:ff:ff
31: 'bond0:<BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP'
link/ether 00:0c:29:07:2c:90 brd ff:ff:ff:ff:ff:ff
inet 10.110.11.22/24 brd 10.110.11.254 scope global bond0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe07:2c90/64 scope link
valid_lft forever preferred_lft forever

6.查看bond信息

[root@localhost network-scripts]$ cat /proc/net/bonding/bond0
EthernetChannelBondingDriver: v3.7.1(April27,2011)
'BondingMode: fault-tolerance (active-backup)'# bond主备模式
PrimarySlave:None
'CurrentlyActiveSlave: eno33554960'# 当前激活的网卡
MII Status: up
MII PollingInterval(ms):100
UpDelay(ms):0
DownDelay(ms):0
'SlaveInterface: eno33554960'      # bond0 组内的网卡
MII Status: up
Speed:1000Mbps
Duplex: full
LinkFailureCount:0
Permanent HW addr:00:0c:29:07:2c:90
Slave queue ID:0
'SlaveInterface: eno50332184'      # bond0 组内的网卡
MII Status: up
Speed:1000Mbps
Duplex: full
LinkFailureCount:0
Permanent HW addr:00:0c:29:07:2c:9a
Slave queue ID:0

7.删除bond

[root@localhost ~]$ ls /sys/class/net/   #查看网络设备
bond0 bond1 bonding_masters eno16777736 eno33554960 eno50332184 eno67109408 eno83886632 lo
`#直接删除bond0,会提示无权限,需要通过bonding_masters文件来删除bond设备,但是bonding_masters文件是无法直接修改的,那么我们这样做:`
[root@localhost ~]$ echo -bond0 >/sys/class/net/bonding_masters
`#echo后面的 '-' 是删除设备, '+' 是增加设备`

脑无理想 枉活一世