转帖:Linux双网卡绑定一个IP,实现容错或负载均衡

 
转帖:Linux双网卡绑定一个IP,实现容错或负载均衡
 
 

其实早在08年9月就做了这个了,只不过最近在学RHCE的时候发现也有bond方面的内容。
        发出来大家也学习一下。

实验环境: CentOS5.3 eth0 eth1
1.先修改eth0 和eht1这2个网卡配置文件。目录在(/etc/sysconfig/network-scripts/)如下:
DEVICE=eth0
ONBOOT=yes
MASTER=bond0
BOOTPROTO=none
2. eth1也是同样的修改。如下:
DEVICE=eth1
ONBOOT=yes
MASTER=bond0
BOOTPROTO=none
3.新建一个虚拟网卡bond0,创建bond0的配置文件ifcfg-bond0。如下:
DEVICE=bond0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.0.223
NETMASK=255.255.255.0
BROADCAST=192.168.0.255
TYPE=Ethernet
4.修改/etc/modprobe.conf添加内容如下:
alias bond0 bonding
options bond0 miimon=100 mode=0
注意:mode可以为0,1,2,3。     0为负载均衡、1为失效保护,我们一般用到0。
关于:modprobe.conf文件在AS版本里面有,linux9.0的是这个modules.conf文件。
5.修改/etc/rc.d/rc.local添加内容如下:
ifenslave bond0 eth0 eth1
route add -net 192.168.0.255 netmask 255.255.255.0 bond0 或者
route add default gw 192.168.0.255 –interface bond0
OK 完成。
验证:
1.可以不停的ping一个地址,用ifconfig会发现eth0和eth1的RX、TX(xx.x KiB)会同时增长,总数等于bond0的RX、TX(xx.x KiB)。断掉任意一个网线网络不会断。
2.[root@~]#less /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.2.4 (January 28, 2008)
Bonding Mode: fault-tolerance (active-backup)    mode=1时
Bonding Mode: load balancing (round-robin)         mode=0时
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth0
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:0c:29:1f:17:c9

Slave Interface: eth1
MII Status: up
Link Failure Count: 1
Permanent HW addr: 00:0c:29:1f:17:d3

你可能感兴趣的:(linux开发)