概述: 通过网卡绑定,处理网卡单点故障,实验的操作系统是Redhat Linux Enterprise 5.3. 绑定的前提条件:芯片组型号相同,而且网卡应该具备自己独立的BIOS芯片。 网卡绑定时有四种模式,其中常用的是模式0和模式1: 模式0(轮循模式):负载均衡工作模式,他能提供两倍的带宽 ,这种情况下出现一块网卡失效,仅仅会是服务器出口带宽下降,也不会影响网络使用. 模式1(主备模式):当一个网络接口失效时(例如主交换机掉电等),不会出现网络中断,系统会按照cat /etc/rc.local里指定网卡的顺序工作,机器仍能对外服务,起到了失效保护的功能 案例: 模式1 1. modprobe bonding //调用模块bonding modinfo bonding //查看内核中加载的模块相关参数 内容:
- filename: /lib/modules/2.6.25.19/kernel/drivers/net/bonding/bonding.ko
2.编辑虚拟网络接口配置文件,指定网卡IP 注意:不要指定单个网卡的IP 地址、子网掩码或网卡 ID。将上述信息指定到虚拟适配器(bonding)中即可。 cd /etc/sysconfig/network-scripts/ vim ifcfg-eth0 //模块别名 内容:
- DEVICE=eth0 //设备
- BOOTPROTO=dhcp //自动获取地址
- ONBOOT=yes //启动激活
vim ifcfg-eth1 内容:
- DEVICE=eth1
- BOOTPROTO=dhcp
- ONBOOT=yes
cp ifcfg-eth0 ifcfg-bond0 vim ifcfg-bond0 //编辑额外的网卡 内容:
- DEVICE=bond0
- BOOTPROTO=none
- IPADDR=192.168.2.101
- NETMASK=255.255.255.0
- ONBOOT=yes
3.vim /etc/modprobe.conf //编辑模块配置文件,以使系统在启动时加载bonding模块,对外虚拟网络接口设备为 bond0 内容加入二行:
- alias bond0 bonding //内核模块
- options bond0 miimon=100 //链路监测 mode=1 //工作模式
4.vim /etc/rc.local 内容加入一行:
- ifenslave bond0 eth0 eth1
配置完毕,重新启动电脑 1.Xshell:\> ping 192.168.2.101
- Pinging 192.168.2.101 with 32 bytes of data:
- Reply from 192.168.2.101: bytes=32 time<1ms TTL=64
- Reply from 192.168.2.101: bytes=32 time<1ms TTL=64
- Reply from 192.168.2.101: bytes=32 time<1ms TTL=64
- Reply from 192.168.2.101: bytes=32 time<1ms TTL=64
- Ping statistics for 192.168.2.101:
- Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
- Approximate round trip times in milli-seconds:
- Minimum = 0ms, Maximum = 0ms, Average = 0ms
2.ifconfig //查看网卡信息
- bond0 Link encap:Ethernet HWaddr 00:0C:29:9E:49:28
- inet addr:192.168.2.101 Bcast:192.168.2.255 Mask:25
- 5.255.255.0
- inet6 addr: fe80::20c:29ff:fe9e:4928/64 Scope:Link
- UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
- RX packets:87 errors:0 dropped:0 overruns:0 frame:0
- TX packets:122 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:0
- RX bytes:13696 (13.3 KiB) TX bytes:24910 (24.3 KiB)
- eth0 Link encap:Ethernet HWaddr 00:0C:29:9E:49:28
- UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
- RX packets:73 errors:0 dropped:0 overruns:0 frame:0
- TX packets:98 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:1000
- RX bytes:10395 (10.1 KiB) TX bytes:19299 (18.8 KiB)
- Interrupt:19 Base address:0x2000
- eth1 Link encap:Ethernet HWaddr 00:0C:29:9E:49:28
- UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
- RX packets:14 errors:0 dropped:0 overruns:0 frame:0
- TX packets:24 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:1000
- RX bytes:3301 (3.2 KiB) TX bytes:5611 (5.4 KiB)
3.cat /proc/net/bonding/bond0 //查看内核信息
- 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: 0
- Permanent HW addr: 00:0c:29:9e:49:28
- Slave Interface: eth1
- MII Status: up
- Link Failure Count: 0
- Permanent HW addr: 00:0c:29:9e:49:32
断开网卡eth0后: 1.Xshell:\> ping 192.168.2.101 -t
- Reply from 192.168.2.101: bytes=32 time<1ms TTL=64
- Reply from 192.168.2.101: bytes=32 time<1ms TTL=64
- Request timed out.
- Reply from 192.168.2.101: bytes=32 time<1ms TTL=64
- Reply from 192.168.2.101: bytes=32 time<1ms TTL=64
2.cat /proc/net/bonding/bond0
- 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: 1
- Permanent HW addr: 00:0c:29:9e:49:28
- Slave Interface: eth1
- MII Status: up
- Link Failure Count: 0
- Permanent HW addr: 00:0c:29:9e:49:32
断开网卡eth1后:
Reply from 192.168.2.101: bytes=32 time<1ms TTL=64 Reply from 192.168.2.101: bytes=32 time<1ms TTL=64 Request timed out. Reply from 192.168.2.101: bytes=32 time<1ms TTL=64 Reply from 192.168.2.101: bytes=32 time<1ms TTL=64 模式0 注意:只需修改模块配置文件就可以,其它配置与模式1一样 1.vim /etc/modprobe.conf //编辑模块配置文件 文件内容修改一行:
- options bond0 miimon=100 mode=0
配置完毕,重新启动电脑 断开网卡eth0后: Reply from 192.168.2.101: bytes=32 time<1ms TTL=64 Reply from 192.168.2.101: bytes=32 time<1ms TTL=64 Request timed out. Request timed out. Request timed out. 断开网卡eth1后: Reply from 192.168.2.101: bytes=32 time<1ms TTL=64 Reply from 192.168.2.101: bytes=32 time<1ms TTL=64 Request timed out. Reply from 192.168.2.101: bytes=32 time<1ms TTL=64 Reply from 192.168.2.101: bytes=32 time<1ms TTL=64 Reply from 192.168.2.101: bytes=32 time<1ms TTL=64
转载于:https://blog.51cto.com/yz406/962510