Centos7多网卡绑定bond快速实践


Centos7多网卡绑定bond快速实践

文章插图
 
一、准备环境
VMware软件、centos7虚拟机
二、添加网卡
为虚拟机再添加两块网卡,查看网卡信息,可以看到有ens32、ens34、ens35三块网卡
ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host lovalid_lft forever preferred_lft foreverinet6 ::1/128 scope hostvalid_lft forever preferred_lft forever2: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000link/ether 00:0c:29:54:02:06 brd ff:ff:ff:ff:ff:ffinet 192.168.30.142/24 brd 192.168.30.255 scope global noprefixroute dynamic ens32valid_lft 1615sec preferred_lft 1615secinet6 fe80::d089:c15:e69a:8ce4/64 scope link noprefixroutevalid_lft forever preferred_lft forever3: ens34: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000link/ether 00:0c:29:54:02:1a brd ff:ff:ff:ff:ff:ffinet 192.168.30.143/24 brd 192.168.30.255 scope global noprefixroute dynamic ens34valid_lft 1765sec preferred_lft 1765secinet6 fe80::a4af:b843:9032:9dd3/64 scope link noprefixroutevalid_lft forever preferred_lft forever4: ens35: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000link/ether 00:0c:29:54:02:10 brd ff:ff:ff:ff:ff:ffinet 192.168.30.141/24 brd 192.168.30.255 scope global noprefixroute dynamic ens35valid_lft 1765sec preferred_lft 1765secinet6 fe80::b7cf:76d7:23aa:63c2/64 scope link noprefixroutevalid_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 yesnmcli 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 | grep bonding[root@localhost ~]# modprobe bonding[root@localhost ~]# lsmod | grep bondingbonding1529790启用rc.local开机启动项
chmod +x /etc/rc.d/rc.local
在文件中写入modprobe bonding
2、建立bond网口配置文件并进行配置
/etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0NAME=bond0TYPE=BondBONDING_MASTER=yesIPADDR=192.168.30.250PREFIX=255.255.255.0GATEWAY=192.168.30.2DNS1=114.114.114.114ONBOOT=yesBOOTPROTO=noneBONDING_OPTS="mode=6miimon=100"3、修改三块网卡的配置
vi
/etc/sysconfig/network-scripts/ifcfg-ens32
DEVICE=ens32ONBOOT=yesBOOTPROTO=noneTYPE=EthernetMASTER=bond0SLAVE=yesvi /etc/sysconfig/network-scripts/ifcfg-ens34
DEVICE=ens34ONBOOT=yesBOOTPROTO=noneTYPE=EthernetMASTER=bond0SLAVE=yesvi /etc/sysconfig/network-scripts/ifcfg-ens35
DEVICE=ens35ONBOOT=yesBOOTPROTO=noneTYPE=EthernetMASTER=bond0SLAVE=yes4、重新加载网络配置
注意:这一步会断网!
【Centos7多网卡绑定bond快速实践】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 balancingPrimary Slave: NoneCurrently Active Slave: ens32MII Status: upMII Polling Interval (ms): 100Up Delay (ms): 0Down Delay (ms): 0Slave Interface: ens32MII Status: upSpeed: 1000 MbpsDuplex: fullLink Failure Count: 0Permanent HW addr: 00:0c:29:54:02:06Slave queue ID: 0Slave Interface: ens34MII Status: upSpeed: 1000 MbpsDuplex: fullLink Failure Count: 0Permanent HW addr: 00:0c:29:54:02:1aSlave queue ID: 0Slave Interface: ens35MII Status: upSpeed: 1000 MbpsDuplex: fullLink Failure Count: 0Permanent HW addr: 00:0c:29:54:02:10Slave queue ID: 0查看网卡状态
ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host lovalid_lft forever preferred_lft foreverinet6 ::1/128 scope hostvalid_lft forever preferred_lft forever2: ens32: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP group default qlen 1000link/ether 00:0c:29:54:02:06 brd ff:ff:ff:ff:ff:ff3: ens34: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP group default qlen 1000link/ether 00:0c:29:54:02:1a brd ff:ff:ff:ff:ff:ff4: ens35: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP group default qlen 1000link/ether 00:0c:29:54:02:10 brd ff:ff:ff:ff:ff:ff5: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000link/ether 00:0c:29:54:02:06 brd ff:ff:ff:ff:ff:ffinet 192.168.30.250/24 brd 192.168.30.255 scope global bond0valid_lft forever preferred_lft foreverinet6 fe80::20c:29ff:fe54:206/64 scope linkvalid_lft forever preferred_lft forever


推荐阅读