三、CentOS6配置bonding
Centos6配置bonding和上面的Cetons7做bonding基本一样,只是配置有些不同.
系统: Centos6 网卡: em1、em2 bond0:172.16.0.183 负载模式: mode1(adaptive load balancing) # 这里的负载模式为1,也就是主备模式.
1、关闭和停止NetworkManager服务
service NetworkManager stop
chkconfig NetworkManager off
ps: 如果有装的话关闭它,如果报错说明没有装这个,那就不用管
2、加载bonding模块
modprobe --first-time bonding
3、创建基于bond0接口的配置文件
vim /etc/sysconfig/network-scripts/ifcfg-bond0
修改如下 (根据你的需要):
DEVICE=bond0 TYPE=Bond BOOTPROTO=none ONBOOT=yes IPADDR=172.16.0.183 NETMASK=255.255.255.0 GATEWAY=172.16.0.1 DNS1=114.114.114.114 USERCTL=no BONDING_OPTS="mode=6 miimon=100"
4、加载bond0接口到内核
vi /etc/modprobe.d/bonding.conf
修改成如下:
alias bond0 bonding
5、编辑em1、em2的接口文件
vim /etc/sysconfig/network-scripts/ifcfg-em1
修改成如下:
DEVICE=em1 MASTER=bond0 SLAVE=yes USERCTL=no ONBOOT=yes BOOTPROTO=none
vim /etc/sysconfig/network-scripts/ifcfg-em2
修改成如下:
DEVICE=em2 MASTER=bond0 SLAVE=yes USERCTL=no ONBOOT=yes BOOTPROTO=none
6、加载模块、重启网络与测试
modprobe bonding
service network restart
查看bondo接口的状态
cat /proc/net/bonding/bond0
Bonding Mode: fault-tolerance (active-backup) # bond0接口当前的负载模式是主备模式 Primary Slave: None Currently Active Slave: em2 MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0 Slave Interface: em1 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 2 Permanent HW addr: 84:2b:2b:6a:76:d4 Slave queue ID: 0 Slave Interface: em2 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 84:2b:2b:6a:76:d5 Slave queue ID: 0
通过ifconfig命令查看下接口的状态,你会发现mode=1模式下所有的mac地址都是一致的,说明对外逻辑就是一个mac地址
ifconfig bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST> mtu 1500 inet6 fe80::862b:2bff:fe6a:76d4 prefixlen 64 scopeid 0x20<link> ether 84:2b:2b:6a:76:d4 txqueuelen 0 (Ethernet) RX packets 147436 bytes 14519215 (13.8 MiB) RX errors 0 dropped 70285 overruns 0 frame 0 TX packets 10344 bytes 970333 (947.5 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 em1: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500 ether 84:2b:2b:6a:76:d4 txqueuelen 1000 (Ethernet) RX packets 63702 bytes 6302768 (6.0 MiB) RX errors 0 dropped 64285 overruns 0 frame 0 TX packets 344 bytes 35116 (34.2 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 em2: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500 ether 84:2b:2b:6a:76:d4 txqueuelen 1000 (Ethernet) RX packets 65658 bytes 6508173 (6.2 MiB) RX errors 0 dropped 6001 overruns 0 frame 0 TX packets 1708 bytes 187627 (183.2 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 0 (Local Loopback) RX packets 31 bytes 3126 (3.0 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 31 bytes 3126 (3.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
进行高可用测试,拔掉其中的一条网线看丢包和延时情况, 然后在插回网线(模拟故障恢复),再看丢包和延时的情况.
本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-06/144865.htm
