- 论坛徽章:
- 0
|
Linux Channel Bonding可以支持把多个网络适配器集合在一起, 当作一个网络适配器来使用。在 Linux 下,网卡的高可用性是通过 MII 或者 ETHTOOL 的状态监测来实现的,所以,需要检查系统中的网络适配器是否支持 MII 或者ETHTOOL 的连状态监测。可以用命令 "ethtool eth0" 来检查,如果显示的 "Link detected:" 信息与实现的连接状态一致,就没有问题。如果系统中的网络适配器不支持 MII 或者 ETHTOOL 状态监测,当连接失效时,系统就不能检测到,同时,在 bonding 驱动加载时,会记录一条不支持 MII 和 ETHTOOL 的警告信息。
环境: Red Hat Enterprise Linux 4 Update1
1.加载bonding模块(Red Hat Enterprise Linux 4 Update1中内核中包含bonding模块)
我们需要在modprobe.conf文件中加入两行,这样才可以在设置了 bond 设置后,系统启动的时候自动加载 bonding 的驱动程序
install bond0 /sbin/modprobe -a eth0 eth1 && /sbin/modprobe bonding
options bonding mode=0 miimon=100
这里指定eth0,eth1为两个需要绑定的网卡。
如:
#vi /etc/modprobe.conf
alias eth0 e1000
alias eth1 e1000
install bond0 /sbin/modprobe -a eth0 eth1 && /sbin/modprobe bonding
options bonding mode=6 miimon=100
如果需要绑定多个网卡,那么设置为:
alias eth0 e1000
alias eth1 e1000
alias eth2 tg3
alias eth3 tg3
install bond0 /sbin/modprobe -a eth0 eth1 && /sbin/modprobe bonding
install bond1 /sbin/modprobe -a eth2 eth3 && /sbin/modprobe bonding
options bonding mode=6 miimon=100 max_bonds=2
其中:
miimon 是指多久时间检查网络一次,单位是ms(毫秒),其意义是假设其中有一条网络断线,会在0.1秒内自动备援
mode 共有七种模式(0~6)
mode=0:负载均衡模式,有自动备援,但需要"Switch"支持和设定。
mode=1:自动备援模式,其中一条线若断线,其他线路将会自动备援。
mode=6:负载均衡模式,有自动备援,不需要"Switch"支持和设定。
max_bonds 为bonging的数量
2.配置bonding
#cd /etc/sysconfig/network-scripts
#vi ifcfg-bond0
DEVICE=bond0
BOOTPROTO=none
TYPE=Ethernet
ONBOOT=yes
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.254
在 bond 中的所有网络适配器的脚本中,都要有 SLAVE 和 MASTER 的定义。例如,如果要让eth0和eth1成为bond0的成员,它们对应的配置文件(ifcfg-eth0和ifcfg-eth1)就要仿照下面的内容进行更改:
如:
#vi ifcfg-eth0
DEVICE=eth0
USERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
BOOTPROTO=none
#vi ifcfg-eth1
DEVICE=eth1
USERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
BOOTPROTO=none
3.重新启动网络
#service network restart
4.验证bonging状态
# ifconfig
bond0 Link encap:Ethernet HWaddr 00:0F:1F:6B:5E:96
inet addr:192.168.1.100 Bcast:192.168.1.255 Mask:255.255.252.0
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:19552 errors:0 dropped:0 overruns:0 frame:0
TX packets:2011 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2156066 (2.0 Mb) TX bytes:236358 (230.8 Kb)
eth0 Link encap:Ethernet HWaddr 00:0F:1F:6B:5E:96
inet addr:192.168.1.100 Bcast:192.168.1.255 Mask:255.255.252.0
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:9787 errors:0 dropped:0 overruns:0 frame:0
TX packets:1006 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1078288 (1.0 Mb) TX bytes:119413 (116.6 Kb)
Interrupt:28
eth1 Link encap:Ethernet HWaddr 00:0F:1F:6B:5E:96
inet addr:192.168.1.100 Bcast:192.168.1.255 Mask:255.255.252.0
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:9765 errors:0 dropped:0 overruns:0 frame:0
TX packets:1005 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1077778 (1.0 Mb) TX bytes:116945 (114.2 Kb)
Interrupt:29
# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v2.6.0 (January 14, 2004)
Bonding Mode: load balancing (round-robin)
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:0f:1f:6b:5e:96
Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:0f:1f:6b:5e:97
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/815/showart_348105.html |
|