分类: LINUX
2010-06-12 02:42:43
Xen下做双网卡的bonding实验
环境:装有Xen内核的Red Hat Enterprise Linux 5 update 4的机器一台
如果和在普通内核下作bonding实验一样的话,真实物理网卡的断开,domain0是检测不到的。所以想到要将eth0和eth1生成的bond0桥接到xenbr0上,用xenbr0检测真实物理网卡的断开。
先关闭xend服务。
配置/etc/sysconfig/network-scripts/目录下的几个文件:
ifcfg-eth0:
DEVICE=eth0
BOOTPROTO=none
HWADDR=00:50:da:7a:51:45
ONBOOT=yes
MASTER=bond0
SLAVE=yes
ifcfg-eth1:
DEVICE=eth1
BOOTPROTO=none
HWADDR=00:14:22:36:F1:FA
ONBOOT=yes
MASTER=bond0
SLAVE=yes
自己创建一个文件,文件名字为ifcfg-bond_name,其中bond_name为ifcfg-eth0和ifcfg-eth1文件里MASTER选项所对应的值。
ifcfg-bond0:
DEVICE=bond0
BOOTPROTO=static
ONBOOT=yes
BRIDGE=xenbr0
和普通内核下做双网卡bonding不同的是BRIDGE选项,这里将bond0设备桥接到了Xen的xenbr0上,而且不能指定IPADDR和NETMASK,在普通内核下这两个选项是需要指定的。
创建ifcfg-xenbr0文件,这里是对xenbr0设备的配置文件。在普通内核里是没有这个设
备的。
ifcfg-xenbr0:
DEVICE=xenbr0
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.0.222
NETMASK=255.255.255.0
TYPE=bridge
这里需要指定静态的IPADDR和NETMASK,TYPE选项为桥接。
因为bonding是一个模块,所以要在/etc/modprobe.conf文件里添加bond0设备的参数:
alias bond0 bonding
options bond0 miimon=100 mode=1 use_carrier=0
其中miimon=100为,每隔100ms就监测物理网卡是否有断开。
mode=1为主从模式(active-backup),mode=0为轮循模式(round robin)。
use_carrier选项为指定监测链路状态的方式,有MII / ETHTOOL ioctls方式或netif_carrier_of()函数方式。MII / ETHTOOL ioctls方式的效率比较低。但是netif_carrier_of()函数方式要依赖于设备的驱动,所以网卡必须要支持此功能。默认的方式为第二种(即use_carrier=1),所以有些情况下要使用第
一种方式,将use_carrier置1。
这些选项也可以在ifcfg-bond0文件里指定:
BONDING_OPTS="mode=1 miimon=100"
下面这步很关键。
Xen默认情况下是不
能处理bonding的,所
以它会试图创建或修改到eth0的桥接。
这里将/etc/xen/xen-config.sxp文件中以network-script开头的行都注释掉。
重启系统。
测试
重新启动网络:
# service network restart
Shutting down interface bond0: bridge xenbr0 is still up; can't delete it
[ OK ]
Shutting down interface xenbr0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface bond0: [ OK ]
Bringing up interface xenbr0: [ OK ]
# ifconfig
bond0 Link encap:Ethernet HWaddr 00:50:DA:7A:51:45
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:2899 errors:0 dropped:0 overruns:0 frame:0
TX packets:331 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:267737 (261.4 KiB) TX bytes:37483 (36.6 KiB)
eth0 Link encap:Ethernet HWaddr 00:50:DA:7A:51:45
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:2589 errors:0 dropped:0 overruns:0 frame:0
TX packets:326 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:237622 (232.0 KiB) TX bytes:36973 (36.1 KiB)
Interrupt:20 Base address:0xef80
eth1 Link encap:Ethernet HWaddr 00:50:DA:7A:51:45
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:310 errors:0 dropped:0 overruns:0 frame:0
TX packets:5 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:30115 (29.4 KiB) TX bytes:510 (510.0 b)
Interrupt:16 Memory:fe8f0000-fe900000
lo 略
virbr0 略
virbr1 略
xenbr0 Link encap:Ethernet HWaddr 00:50:DA:7A:51:45
inet addr:192.168.0.222 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::250:daff:fe7a:5145/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1952 errors:0 dropped:0 overruns:0 frame:0
TX packets:486 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:177848 (173.6 KiB) TX bytes:64037 (62.5 KiB)
正常状态下的/proc/net/bonding/bond0文件:
Ethernet Channel Bonding Driver: v3.4.0 (October 7, 2008)
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: eth0
MII Status: up
Link Failure Count: 1
Permanent HW addr: 00:50:da:7a:51:45
Slave Interface: eth1
MII Status: up
Link Failure Count: 1
Permanent HW addr: 00:14:22:36:f1:fa
这里ping一台机器(同一网段可以连通的机器),然后观察拔掉网卡后的现象。拔掉第一块网卡(eth0)后的状态:
Ethernet Channel Bonding Driver: v3.4.0 (October 7, 2008)
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: eth0
MII Status: down
Link Failure Count: 2
Permanent HW addr: 00:50:da:7a:51:45
Slave Interface: eth1
MII Status: up
Link Failure Count: 2
Permanent HW addr: 00:14:22:36:f1:fa
插回第一块网卡,拔掉第二块网卡(eth1)后的状态:
Ethernet Channel Bonding Driver: v3.4.0 (October 7, 2008)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth0
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: 1
Permanent HW addr: 00:50:da:7a:51:45
Slave Interface: eth1
MII Status: down
Link Failure Count: 2
Permanent HW addr: 00:14:22:36:f1:fa
无论拔掉哪个网卡,都可以ping通那台机器。说明bonding成功。