Linux 双网卡绑定bonding
环境:
CentOS 5系列 + Xen
1 双网卡绑定 ,产生bond0 接口
脚本如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| cp /etc/sysconfig/network-scripts/ifcfg-eth1 /etc/sysconfig/network-scripts/ifcfg-eth1.bak cat > /etc/sysconfig/network-scripts/ifcfg-eth1 <<EOF DEVICE=eth1 USERCTL=no BOOTPROTO=none ONBOOT=yes MASTER=bond0 SLAVE=yes TYPE=Ethernet EOF cp /etc/sysconfig/network-scripts/ifcfg-eth2 /etc/sysconfig/network-scripts/ifcfg-eth2.bak cat > /etc/sysconfig/network-scripts/ifcfg-eth2 <<EOF DEVICE=eth2 USERCTL=no BOOTPROTO=none ONBOOT=yes MASTER=bond0 SLAVE=yes TYPE=Ethernet EOF cat >/etc/sysconfig/network-scripts/ifcfg-bond0 << EOF DEVICE=bond0 BOOTPROTO=none IPADDR=192.168.10.xx NETMASK=255.255.255.0 NETWORK=192.168.10.254 USERCTL=no ONBOOT=yes TYPE=Ethernet EOF
|
2 修改xen配置文件
/etc/xen/xend-config.sxp
(network-script ‘network-bridge netdev=bond0’)
使xen使用bond0 接口,默认生成xenbr0 的接口
或者
(network-script ‘network-bridge bridge=xenbr1 netdev=bond0’)
指定桥接的接口
原来的虚拟机是使用了多网卡 桥接的脚本
/etc/xen/xend-config.sxp
(network-script multi_bridge)
/etc/xen/scripts/multi_bridge
1 2 3 4 5 6
| #!/bin/bash dir=$(dirname "$0") "$dir/network-bridge" "$@" vifnum=0 netdev=eth0 bridge=xenbr0 "$dir/network-bridge" "$@" vifnum=1 netdev=eth1 bridge=xenbr1 "$dir/network-bridge" "$@" vifnum=2 netdev=eth2 bridge=xenbr2 "$dir/network-bridge" "$@" vifnum=3 netdev=eth3 bridge=xenbr3
|
修改使用bond0
sed -i ‘s/eth1/bond0/g’ /etc/xen/scripts/multi_bridge sed -i ‘5,6s/^/#/‘ /etc/xen/scripts/multi_bridge
3 domainU 配置文件
1 2 3 4 5 6 7 8 9 10 11 12
| name = "domain-1" uuid = "a5b43314-cd35-74e3-a357-4290768b7599" maxmem = 8192 memory = 8192 vcpus = 6 bootloader = "/usr/bin/pygrub" on_poweroff = "destroy" on_reboot = "restart" on_crash = "restart" vfb = [ "type=vnc,vncunused=1,keymap=en-us" ] disk = [ "tap:aio:/data/xenserver/domain-1/domain-1.img,xvda,w" ] vif = [ "mac=00:16:3e:37:02:c7,bridge=xenbr0,script=vif-bridge", "mac=00:16:36:18:22:f1,bridge=xenbr1,script=vif-bridge" ]
|
4 修改内核加载参数,使之生效
1 2 3 4 5 6
| cp /etc/modprobe.conf /etc/modprobe.conf.bak cat >> /etc/modprobe.conf << EOF alias bond0 bonding options bond0 miimon=100 mode=0 EOF
|
xen方式需要重启机器,才能保证双网卡绑定正常
加载绑定模块
modprobe bonding
xen 在重启完后,会生成一个pbond0 的接口
cat /proc/net/bonding/pbond0
CentOS 6系列 + KVM
ifcfg-bond0
1 2 3 4 5
| DEVICE=bond0 BOOTPROTO=static BRIDGE=br0 NM_CONTROLLED=no ONBOOT=yes
|
ifcfg-br0
1 2 3 4 5 6 7 8 9 10 11
| DEVICE=br0 TYPE=Bridge BOOTPROTO=static ONBOOT=yes IPADDR=192.168.11.110 NETMASK=255.255.255.0 GATEWAY=192.168.11.254 MTU=1500 SLAVE=bond0 NM_CONTROLLED=no PEERDNS=no
|
vi /etc/libvirt/qemu/domain-1.xml
1 2 3 4 5 6
| <interface type='bridge'> <mac address='52:54:31:b3:73:31'/> <source bridge='br0'/> <model type='virtio'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface>
|
多个bonding
修改内核模块
1 2 3 4 5 6 7
| cat >> /etc/modprobe.conf << EOF alias bond0 bonding options bond0 miimon=100 mode=0 alias bond1 bonding options bond1 miimon=100 mode=0 EOF
|
modprobe bonding