cd /etc/sysconfig/network-scripts/
[
root@rgdefmdb1 network-scripts]# cat ifcfg-bond0
DEVICE=bond0
NM_CONTROLLED=no #yes的话是不需要network restart,直接生效。
BOOTPROTO=static
ONBOOT=yes
IPADDR=10.225.3.164
NETMASK=255.255.255.0
GATEWAY=10.225.3.254
DNS1=10.225.5.16
USERCTL=no
BONDING_OPTS="mode=1 miimon=100" #redhat6可以直接在这里配置,不需要在/etc/modprobe.d/dist.conf里面配置
[
root@rgdefmdb1 network-scripts]# cat ifcfg-bond1
DEVICE=bond1
NM_CONTROLLED=no
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.0.1
NETMASK=255.255.255.0
USERCTL=no
BONDING_OPTS="mode=1 miimon=100" #1是高可用,0是负载均衡
[
root@rgdefmdb1 network-scripts]# cat ifcfg-eth0
DEVICE="eth0"
NM_CONTROLLED=no
ONBOOT=yes
TYPE=Ethernet
BOOTPROTO=static
MASTER=bond0
SLAVE=yes
USERCTL=no
[
root@rgdefmdb1 network-scripts]# cat ifcfg-eth1
DEVICE="eth1"
NM_CONTROLLED=no
ONBOOT=yes
TYPE=Ethernet
BOOTPROTO=static
MASTER=bond0
SLAVE=yes
USERCTL=no
[
root@rgdefmdb1 network-scripts]# cat ifcfg-eth2
DEVICE="eth2"
NM_CONTROLLED=no
ONBOOT=yes
TYPE=Ethernet
BOOTPROTO=static
MASTER=bond1
SLAVE=yes
USERCTL=no
[
root@rgdefmdb1 network-scripts]# cat ifcfg-eth3
DEVICE="eth3"
NM_CONTROLLED=no
ONBOOT=yes
TYPE=Ethernet
BOOTPROTO=static
MASTER=bond1
SLAVE=yes
USERCTL=no
4 # vi /etc/rc.d/rc.local
加入
ifenslave bond0 eth0 eth1
#那也就是说在主备模式下,当一个网络接口失效时(例如主交换机掉电等),不回出现网络中断,系统会按照cat /etc/rc.d/rc.local里指定网卡的顺序工作,机器仍能对外服务,起到了失效保护的功能.
chkconfig NetworkManager off #开机不启动 如果启动会出现ifconfig的时候eth1等网卡具有自己的ip,而且route -n看路由表也会有eth0等的路由,会不正常
service NetworkManager stop
chkconfig network on
service network restart
可以看
cat /proc/net/bonding/bond1
看到现在bond1在用哪个网卡。可以用ifdown eth2 ,ifup eth2起停端口测试绑定冗余是否正常。
正常情况下看到是这样的。
[
root@rgdefmdb2 network-scripts]# ifconfig
bond0 Link encap:Ethernet HWaddr C4:54:44:88:DE:E4
inet addr:10.225.3.167 Bcast:10.225.3.255 Mask:255.255.255.0
inet6 addr: fe80::c654:44ff:fe88:dee4/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:11780 errors:0 dropped:0 overruns:0 frame:0
TX packets:1963 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1444639 (1.3 MiB) TX bytes:284783 (278.1 KiB)
bond1 Link encap:Ethernet HWaddr C4:54:44:88:DE:E6
inet addr:192.168.0.2 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::c654:44ff:fe88:dee6/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:3579 errors:0 dropped:0 overruns:0 frame:0
TX packets:3021 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:506906 (495.0 KiB) TX bytes:314562 (307.1 KiB)
eth0 Link encap:Ethernet HWaddr C4:54:44:88:DE:E4
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:9784 errors:0 dropped:0 overruns:0 frame:0
TX packets:1953 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:994215 (970.9 KiB) TX bytes:283766 (277.1 KiB)
Memory:95b20000-95b40000
eth1 Link encap:Ethernet HWaddr C4:54:44:88:DE:E4
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:1996 errors:0 dropped:0 overruns:0 frame:0
TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:450424 (439.8 KiB) TX bytes:1017 (1017.0 b)
Memory:95b00000-95b20000
eth2 Link encap:Ethernet HWaddr C4:54:44:88:DE:E6
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:2960 errors:0 dropped:0 overruns:0 frame:0
TX packets:2642 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:378047 (369.1 KiB) TX bytes:270161 (263.8 KiB)
Memory:95a20000-95a40000
eth3 Link encap:Ethernet HWaddr C4:54:44:88:DE:E6
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:619 errors:0 dropped:0 overruns:0 frame:0
TX packets:379 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:128859 (125.8 KiB) TX bytes:44401 (43.3 KiB)
Memory:95a00000-95a20000
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:5964 errors:0 dropped:0 overruns:0 frame:0
TX packets:5964 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:494380 (482.7 KiB) TX bytes:494380 (482.7 KiB)
################################下面这个是上网找的参考,用mode=0##################################