问题:在日常场景维护中为了应用环境的高可用性,其中网卡的高可用性是最基础的性质;此文就redhat 6.4版本做个简单的主备bond配置;在linux 7中将使用team的概念配置将变的更加简单,后期有机会再做测试学习;
实施步骤:
1、创建一个bond0的文件
2、配置bond0文件的网卡内容信息
3、将eth1和eth2 配置网卡信息添加入bond0网卡中
4、设置/etc/modprobe.d/dist.conf 保证网卡运行在主备模式下(如果使用负载均衡模式,请做相关的配置以及测试)
实验:
查看网卡信息:
[root@redis ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 08:00:27:E5:8C:03
inet addr:192.168.1.30 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fee5:8c03/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:175 errors:0 dropped:0 overruns:0 frame:0
TX packets:109 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:21468 (20.9 KiB) TX bytes:14431 (14.0 KiB)
eth1 Link encap:Ethernet HWaddr 08:00:27:41:41:5C
inet addr:192.168.56.102 Bcast:192.168.56.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe41:415c/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:14 errors:0 dropped:0 overruns:0 frame:0
TX packets:15 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:5644 (5.5 KiB) TX bytes:2946 (2.8 KiB)
eth2 Link encap:Ethernet HWaddr 08:00:27:F2:30:D5
inet addr:192.168.56.101 Bcast:192.168.56.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fef2:30d5/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:16 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:6610 (6.4 KiB) TX bytes:1152 (1.1 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:4 errors:0 dropped:0 overruns:0 frame:0
TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:240 (240.0 b) TX bytes:240 (240.0 b)
创建并配置bond0网卡
[root@redis network-scripts]# touch /etc/sysconfig/network-scripts/ifcfg-bond0
[root@redis network-scripts]# cat ifcfg-bond0
DEVICE=bond0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=no
IPADDR=192.168.1.100
PREFIX=24
GATEWAY=192.168.1.1
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
NAME=“System bond0”
配置eth1,eth2配置文件,将两个网卡加入到bond0中来
[root@redis network-scripts]# cat ifcfg-eth1
DEVICE=eth1
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no
PEERDNS=no
[root@redis network-scripts]# cat ifcfg-eth2
DEVICE=eth2
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no
PEERDNS=no
配置添加/etc/modprobe.d/dist.conf内容
最后一行添加
alias bond0 bonding
options bond0 miimon=100 mode=1 max_bonds=2
停止NMCI服务,重新启动网卡信息
service iptables stop
chkconfig iptables off
service NetworkManager stop
chkconfig NetworkManager off
[root@redis network-scripts]# service network restart
Shutting down interface eth0: [ OK ]
Shutting down interface eth1: /etc/sysconfig/network-scripts/ifdown-eth: line 116: /sys/class/net/bond0/bonding/slaves: No such file or directory
[ OK ]
Shutting down interface eth2: /etc/sysconfig/network-scripts/ifdown-eth: line 116: /sys/class/net/bond0/bonding/slaves: No such file or directory
[ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface bond0: [ OK ]
Bringing up interface eth0: [ OK ]
测试:网卡相互down测试网络连通性
首选查看bond0的运行信息
[root@redis network-scripts]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth1
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 08:00:27:41:41:5c
Slave queue ID: 0
Slave Interface: eth2
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 08:00:27:f2:30:d5
Slave queue ID: 0
[root@redis network-scripts]#
down eth1
ifdown eth1 查看确认 ping
至此双网卡主备绑定完成;
总结:配置简单,在生产环境中配置还是相对来说比较多的;这里只是其中的一种方法,还有其他很多的配置方法,请看官自行测试;