一、环境介绍:
1、系统环境:
root@mysql1:/root>cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.9 (Santiago)
root@mysql1:/root>
2、网卡情况:
root@mysql1:/root>ifconfig -a | awk -F ‘[ ]‘ ‘{print $1}‘
bond0
eth0
eth1
eth2
lo
root@mysql1:/root>
本次以eth1、eth2进行banding配置,当在IDC机房操作时,可执行ethtool -p eth1/2,然后通过观察网口灯来判断网口具体位置。
3、NetworkManager以及iptables是否已经关闭:
root@mysql1:/root>service NetworkManager status
NetworkManager is stopped
root@mysql1:/root>
root@mysql1:/root>service iptables status
iptables: unrecognized service
root@mysql1:/root>
操作环境中已经关闭了networkmanager并且没有iptable服务,参考命令如下:
service NetworkManager stop
service iptables stop
二、双网卡配置:
在真实环境下,通常为了便于操作,建议先配置一个临时IP,然后在自己电脑上配置一个同网段地址,
最后找根网线端到端通过CRT连接进行配置,操作如下:
1、配置eth1临时地址(重启网络或者重启主机失效):
root@mysql1:/root>ifconfig eth1 192.168.100.10 netmask 255.255.255.0
root@mysql1:/root>ip a |grep eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
inet 192.168.100.10/24 brd 192.168.100.255 scope global eth1
2、通过CRT登录后操作如下(写入配置):
1)配置eth1以及eth2,操作如下:
root@mysql1:/root>cd /etc/sysconfig/network-scripts/
root@mysql1:/etc/sysconfig/network-scripts>cp ifcfg-eth1 ifcfg-eth1.bak
root@mysql1:/etc/sysconfig/network-scripts>cp ifcfg-eth2 ifcfg-eth2.bak
root@mysql1:/etc/sysconfig/network-scripts>cat >>ifcfg-eth1
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=none
USERCTL=no
MASTER=bond1
SLAVE=yes
^C
root@mysql1:/etc/sysconfig/network-scripts>
root@mysql1:/etc/sysconfig/network-scripts>cat >>ifcfg-eth2
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=none
USERCTL=no
MASTER=bond1
SLAVE=yes
^C
root@mysql1:/etc/sysconfig/network-scripts>
分别vi进入eth1、eth2下注释或者删除之前多余的项
2)配置bond1,操作如下:
root@mysql1:/etc/sysconfig/network-scripts>cat >>ifcfg-bond1
DEVICE=bond1
BOOTPROTO=static
IPADDR=192.168.100.10
NETMASK=255.255.255.0
ONBOOT=yes
TYPE=Ethernet
USERCTL=no
BONDING_OPTS="mode=1 arp_interval=1000 arp_ip_target=192.168.100.10 arp_validate=all"
root@mysql1:/etc/sysconfig/network-scripts>
BONDING_OPTS是配置bonding的一个必要参数,其中:miimon=系统每100ms监测一次链路连接状态,如果有一条线路不通就转入另一条线路;
mode表示模式,分为七种:
(1)mode=0 轮询策略(默认):
(2)mode=1 主-备策略(常用):
(3)mode=2 平衡策略(不常用);
(4)mode=3 广播策略(不常用);
(5)mode=4 IEEE802.3ad动态链路聚合(不常用);
(6)mode=5 适配器传输负载均衡(不常用);
(7)mode=6 适配器适应性负载均衡(不常用)
arp_ip_target //arp检测的地址,这个地址通常是汇聚交换机上起的VRRP地址
arp_interval=1000 //arp1000ms检测一次
arp_validate=all //arp验证为all,类型分为active以及backup和all
3、添加bonding模块到配置文件,目的是开机自动加载bonding模块到内核:
root@mysql1:/root>cat >>/etc/modprobe.d/bond1.conf
alias bond1 bonding
options bond1 miimon=100 mode=1
^C
4、系统启动,自动绑定:
root@mysql1:/root>cp /etc/rc.local /etc/rc.local.bak
root@mysql1:/root>cat >>/etc/rc.local
ifenslave bood1 eth1 eth2
^C
root@mysql1:/root>
5、重启网络:
root@mysql1:/etc/sysconfig/network-scripts>service network restart
Shutting down interface bond1: [ OK ]
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface bond1: Determining if ip address 192.168.100.10 is already in use for device bond1...
[ OK ]
Bringing up interface eth0: Determining if ip address 192.168.100.11 is already in use for device eth0...
[ OK ]
root@mysql1:/etc/sysconfig/network-scripts>
6、查看是否已经生效:
root@mysql1:/root>cat /proc/net/bonding/bond1
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth1
MII Status: up
MII Polling Interval (ms): 0
Up Delay (ms): 0
Down Delay (ms): 0
ARP Polling Interval (ms): 1000
ARP IP target/s (n.n.n.n form): 192.168.100.2
Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:6b:19:e4
Slave queue ID: 0
Slave Interface: eth2
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:6b:19:da
Slave queue ID: 0
root@mysql1:/root>
7、测试:
(1)目前主用网卡为eth1:
root@mysql1:/root>cat /proc/net/bonding/bond1
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth1
MII Status: up
MII Polling Interval (ms): 0
Up Delay (ms): 0
Down Delay (ms): 0
ARP Polling Interval (ms): 1000
ARP IP target/s (n.n.n.n form): 192.168.100.2
.........
(2)宕主eth1,现象为切到eth2正常,如下:
root@mysql1:/root>ifdown eth1
root@mysql1:/root>cat /proc/net/bonding/bond1
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth2
MII Status: up
MII Polling Interval (ms): 0
Up Delay (ms): 0
Down Delay (ms): 0
ARP Polling Interval (ms): 1000
ARP IP target/s (n.n.n.n form): 192.168.100.2
..........
(3)启动eth1,目前主用为eth2:如下:
root@mysql1:/root>ifup eth1
root@mysql1:/root>cat /proc/net/bonding/bond1
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth2
MII Status: up
MII Polling Interval (ms): 0
Up Delay (ms): 0
Down Delay (ms): 0
ARP Polling Interval (ms): 1000
ARP IP target/s (n.n.n.n form): 192.168.100.2
.......
(4)宕eth2,现象为切到eth1,如下:
root@mysql1:/root>ifdown eth2
root@mysql1:/root>cat /proc/net/bonding/bond1
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth1
MII Status: up
MII Polling Interval (ms): 0
Up Delay (ms): 0
Down Delay (ms): 0
ARP Polling Interval (ms): 1000
ARP IP target/s (n.n.n.n form): 192.168.100.2
(5)起eth2,如下
root@mysql1:/root>ifup eth2
root@mysql1:/root>cat /proc/net/bonding/bond1
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth1
MII Status: up
MII Polling Interval (ms): 0
Up Delay (ms): 0
Down Delay (ms): 0
ARP Polling Interval (ms): 1000
ARP IP target/s (n.n.n.n form): 192.168.100.2
Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:6b:19:e4
Slave queue ID: 0
Slave Interface: eth2
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:6b:19:da
Slave queue ID: 0
root@mysql1:/root>
到此,切换测试就完成了,在机房环境中,还可以通过拔主机头的网线或者拔交换头的网线都可以实现如上测试。
8、常用命令总结:
(1) cat /proc/net/bonding/端口号,如查看bong1:cat /proc/net/bonding/bond1
(2)ifup+端口号,用于起某个网口,如eth2:ifup eth2
(3)ifdown+端口号,用于宕某个网口,如eth1:ifdown eth1
(4)查看网络情况:ifconfig -a或者ip addr
(5)重启网络:service network restart