Centos7多网卡绑定bond快速实践
一、准备环境
VMware软件、Centos7虚拟机
二、添加网卡
为虚拟机再添加两块网卡,查看网卡信息,可以看到有ens32、ens34、ens35三块网卡
ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:54:02:06 brd ff:ff:ff:ff:ff:ff
inet 192.168.30.142/24 brd 192.168.30.255 scope global noprefixroute dynamic ens32
valid_lft 1615sec preferred_lft 1615sec
inet6 fe80::d089:c15:e69a:8ce4/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: ens34: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:54:02:1a brd ff:ff:ff:ff:ff:ff
inet 192.168.30.143/24 brd 192.168.30.255 scope global noprefixroute dynamic ens34
valid_lft 1765sec preferred_lft 1765sec
inet6 fe80::a4af:b843:9032:9dd3/64 scope link noprefixroute
valid_lft forever preferred_lft forever
4: ens35: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:54:02:10 brd ff:ff:ff:ff:ff:ff
inet 192.168.30.141/24 brd 192.168.30.255 scope global noprefixroute dynamic ens35
valid_lft 1765sec preferred_lft 1765sec
inet6 fe80::b7cf:76d7:23aa:63c2/64 scope link noprefixroute
valid_lft forever preferred_lft forever
查看网卡配置文件,可以看到添加网卡后,并没有生成对应的网卡文件
ls /etc/sysconfig/network-scripts/ifcfg*
/etc/sysconfig/network-scripts/ifcfg-ens32 /etc/sysconfig/network-scripts/ifcfg-lo
可以为网卡生成配置文件,但在本文中不需要这样做
nmcli connection add type ethernet con-name ens34 ifname ens34 autoconnect yes
nmcli connection add type ethernet con-name ens35 ifname ens35 autoconnect yes
再次查看网卡配置文件,生成成功
ls /etc/sysconfig/network-scripts/ifcfg*
/etc/sysconfig/network-scripts/ifcfg-ens32 /etc/sysconfig/network-scripts/ifcfg-ens35
/etc/sysconfig/network-scripts/ifcfg-ens34 /etc/sysconfig/network-scripts/ifcfg-lo
三,选定网卡绑定模式
多网卡一共有7种bond模式,这里直接选用mode=6 (balance-alb) Adaptive load balancing(适配器适应性负载均衡),该模式不需要交换机支持
四、开始配置
1、加载bonding模块,并设置开机启动
[root@localhost ~]#lsmod|grepbonding[root@localhost ~]#modprobe bonding[root@localhost ~]#lsmod|grepbondingbonding 152979 0
启用rc.local开机启动项
chmod +x /etc/rc.d/rc.local
在文件中写入modprobe bonding
2、建立bond网口配置文件并进行配置
/etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
NAME=bond0
TYPE=Bond
BONDING_MASTER=yes
IPADDR=192.168.30.250
PREFIX=255.255.255.0
GATEWAY=192.168.30.2
DNS1=114.114.114.114
ONBOOT=yes
BOOTPROTO=none
BONDING_OPTS="mode=6 miimon=100"
3、修改三块网卡的配置
vi /etc/sysconfig/network-scripts/ifcfg-ens32
DEVICE=ens32
ONBOOT=yes
BOOTPROTO=none
TYPE=Ethernet
MASTER=bond0
SLAVE=yes
vi /etc/sysconfig/network-scripts/ifcfg-ens34
DEVICE=ens34
ONBOOT=yes
BOOTPROTO=none
TYPE=Ethernet
MASTER=bond0
SLAVE=yes
vi /etc/sysconfig/network-scripts/ifcfg-ens35
DEVICE=ens35
ONBOOT=yes
BOOTPROTO=none
TYPE=Ethernet
MASTER=bond0
SLAVE=yes
4、重新加载网络配置
注意:这一步会断网!
nmcli connection reload && systemctl restart network.service
使用新IP链接ssh
五、验证绑定是否生效
cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: adaptive load balancing
Primary Slave: None
Currently Active Slave: ens32
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: ens32
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:54:02:06
Slave queue ID: 0
Slave Interface: ens34
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:54:02:1a
Slave queue ID: 0
Slave Interface: ens35
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:54:02:10
Slave queue ID: 0
查看网卡状态
ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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: ens32: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP group default qlen 1000
link/ether 00:0c:29:54:02:06 brd ff:ff:ff:ff:ff:ff
3: ens34: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP group default qlen 1000
link/ether 00:0c:29:54:02:1a brd ff:ff:ff:ff:ff:ff
4: ens35: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP group default qlen 1000
link/ether 00:0c:29:54:02:10 brd ff:ff:ff:ff:ff:ff
5: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 00:0c:29:54:02:06 brd ff:ff:ff:ff:ff:ff
inet 192.168.30.250/24 brd 192.168.30.255 scope global bond0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe54:206/64 scope link
valid_lft forever preferred_lft forever
查看接口带宽,带宽为3G
ethtool bond0
Settings for bond0:
Supported ports: [ ]
Supported link modes: Not reported
Supported pause frame use: No
Supports auto-negotiation: No
Supported FEC modes: Not reported
Advertised link modes: Not reported
Advertised pause frame use: No
Advertised auto-negotiation: No
Advertised FEC modes: Not reported
Speed: 3000Mb/s
Duplex: Full
Port: Other
PHYAD: 0
Transceiver: internal
Auto-negotiation: off
Link detected: yes
连续ping测试,并禁用第一个网卡,此时会丢一个包,网络依然正常运行
来自 192.168.30.250 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.30.250 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.30.250 的回复: 字节=32 时间=1ms TTL=64
请求超时。
来自 192.168.30.250 的回复: 字节=32 时间=1ms TTL=64
来自 192.168.30.250 的回复: 字节=32 时间<1ms TTL=64
完毕!