[环境: RHEL6]
1.建议安装"rpm -q kernel-doc"
shell> rpm -ql kernel-doc | grep bonding.txt
/usr/share/doc/kernel-doc-2.6.32/Documentation/networking/bonding.txt
bonding.txt-->教你怎么去配置双网可单IP,真实机器如果有双网卡的话,任意一根网线掉线不影响连接!
从bonding.txt中可以看到双网卡绑定的策略mode有8种,例如0,1!一个轮叫,一个backup!
2.[双网卡绑定一个IP]
维护网络! eth0接到一个交换机,eth1接到另一个交换机!
eth0和eth1绑定到一块网卡上!
mii是网络的一个接口!没有这个接口,我们的网卡是用不了的!
mii-tool eth0
miimon --->以多长时间去监控网络的连接! 0.1s-->一般用这个时间段去监控我们的网络端口的连接情况!
bonding
0-->rr
1-->back-up
bonding--->系统内核中的一个模块设备
make menuconfig-->Networking support-->... -> device drivers-->network device support-->Bonding driver support
[然后用一下help,可以找到对应的文档~]
让系统自动加载这个模块:
vim /etc/modprobe.d/bond.conf ///开机或网络启动都会读这个文件!
#alias eth0 8129too ---->代表我们需要将模块8139对应eth0的网络设备!
alias bond0 bonding ---->现在我们将bonding的模块对应bond0的网络设备!
options bonding mode=0 miimon=100 --->参数 bonding内核模块的功能,mode=0[rr轮叫],miimon=100[监控毫秒为单位]
这时候我们需要写两块网卡的支持: [可以有多块~]
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
SLAVE=yes
MASTER=bond0
...eth1 ///让它们各自保留自己的
...
ifcfg-bond0
DEVICE=bond0
ONBOOT=yes
BOOTPROTO=none
IPADDR=10.1.1.x
NETMASK=255.255.255.0
=================================================
=================================================
具体配置:
bonding
vi /etc/modprobe.d/bond.conf
alias bond0 bonding
options bond0 mode=0 miimon=100
ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
SLAVE=yes
MASTER=bond0
ifcfg-eth1
DEVICE=eth1
ONBOOT=yes
BOOTPROTO=none
SLAVE=yes
MASTER=bond0
ifcfg-bond0
DEVICE=bond0
ONBOOT=yes
BOOTPROTO=none
IPADDR=10.1.1.X
NETMASK=255.255.255.0
==================================================
双网卡绑定单个IP地址
为了提供网络的高可用性,我们可能需要将多块网卡绑定成一块虚拟网卡对外提供服务,这样即使其中的一块物理网卡出现故障,也不会导致连接中断。多网卡绑定这个词在不同的平台有不同叫法,在Linux下叫bonding,IBM称为etherchanel,broadcom叫team,但是名字怎么变,效果都是将两块或更多的网卡当做一块网卡使用,在增加带宽的同时也可以提高冗余性。比如我们在RHEL6下可以将eth0和eth1绑定成虚拟网卡bond0。
# vim /etc/sysconfig/network-scripts/ifcfg-bond0 # cat /etc/sysconfig/network-scripts/ifcfg-bond0 DEVICE=bond0 BOOTPROTO=static ONBOOT=yes IPADDR=192.168.12.128 NETMASK=255.255.255.0 USERCTL=no # |
# vim /etc/sysconfig/network-scripts/ifcfg-eth0 # vim /etc/sysconfig/network-scripts/ifcfg-eth1 # cat /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE="eth0" TYPE=Ethernet BOOTPROTO=static ONBOOT="yes" MASTER=bond0 SLAVE=yes USERCTL=no # cat /etc/sysconfig/network-scripts/ifcfg-eth1 DEVICE="eth1" TYPE=Ethernet BOOTPROTO=static ONBOOT="yes" MASTER=bond0 SLAVE=yes USERCTL=no # |
# vim /etc/modprobe.d/dist.conf # grep bond0 /etc/modprobe.d/dist.conf alias bond0 bonding options bond0 miimon=100 mode=1 //miimon是指多久时间要检查网络一次,单位是ms(毫秒)这边的100,是100ms,即是0.1秒 //mode共有七种(0~6),这里解释两个常用的选项。
|
# service network restart # cat /proc/net/bonding/bond0 Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009) 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 Speed: 100 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:45:bf:a0 Slave queue ID: 0 Slave Interface: eth1 MII Status: up Speed: 100 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:45:bf:aa Slave queue ID: 0 # route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.128.0 0.0.0.0 255.255.255.0 U 0 0 0 bond0 169.254.0.0 0.0.0.0 255.255.0.0 U 1004 0 0 bond0 # lsmod | grep bond bonding 109558 0 # |
选择一台Linux机器ping测试机,然后停掉当前使用的网卡eth0,查看是否能够继续ping通
# ifdown eth0 # cat /proc/net/bonding/bond0 //发现此时激活的网卡为eth1了,如果测试可以ping通,则实验完成 Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009) 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: eth1 MII Status: up Speed: 100 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:45:bf:aa Slave queue ID: 0 # |