分类: LINUX
2011-12-31 10:28:24
- vi /etc/sysconfig/ network-scripts/ ifcfg-bond0
- [root@rhas-13 root]# cp /etc/sysconfig/network-scripts/ifcfg-eth0 ifcfg-bond0
- 将第一行改成 DEVICE=bond0
- # cat ifcfg-bond0
- DEVICE=bond0
- BOOTPROTO=static
- IPADDR=172.31.0.13
- NETMASK=255.255.252.0
- BROADCAST=172.31.3.254
- ONBOOT=yes
- TYPE=Ethernet
这里要主意,不要指定单个网卡的IP 地址、子网掩码或网卡 ID。将上述信息指定到虚拟适配器(bonding)中即可。[root@rhas-13 network-scripts]# cat ifcfg-eth0
- DEVICE=eth0
- ONBOOT=yes
- BOOTPROTO=dhcp
- [root@rhas-13 network-scripts]# cat ifcfg-eth1
- DEVICE=eth0
- ONBOOT=yes
- BOOTPROTO=dhcp
编辑 /etc/modules.conf 文件,加入如下一行内容,以使系统在启动时加载bonding模块,对外虚拟网络接口设备为 bond0加入下列两行
- alias bond0 bonding
- options bond0 miimon=100 mode=1
说明:miimon是用来进行链路监测的。 比如:miimon=100,那么系统每100ms监测一次链路连接状态,如果有一条线路不通就转入另一条线路;mode的值表示工作模式,他共有0,1,2,3四种模式,常用的为0,1两种。
- mode=0表示load balancing (round-robin)为负载均衡方式,两块网卡都工作。
- mode=1表示fault-tolerance (active-backup)提供冗余功能,工作方式是主备的工作方式,也就是说默认情况下只有一块网卡工作,另一块做备份.
bonding只能提供链路监测,即从主机到交换机的链路是否接通。如果只是交换机对外的链路down掉了,而交换机本身并没有故障,那么bonding会认为链路没有问题而继续使用
加入两行
- ifenslave bond0 eth0 eth1
- route add -net 172.31.3.254 netmask 255.255.255.0 bond0
工作在主备模式下,这时eth1作为备份网卡是no arp的
那也就是说在主备模式下,当一个网络接口失效时(例如主交换机掉电等),不回出现网络中断,系统会按照cat /etc/rc.d/rc.local里指定网卡的顺序工作,机器仍能对外服务,起到了失效保护的功能.
负载均衡工作模式,他能提供两倍的带宽,下我们来看一下网卡的配置信息
- [root@rhas-13 root]# ifconfig
- bond0 Link encap:Ethernet HWaddr 00:0E:7F:25:D9:8B
- inet addr:172.31.0.13 Bcast:172.31.3.255 Mask:255.255.252.0
- UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
- RX packets:2817 errors:0 dropped:0 overruns:0 frame:0
- TX packets:95 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:0
- RX bytes:226957 (221.6 Kb) TX bytes:15266 (14.9 Kb)
- eth0 Link encap:Ethernet HWaddr 00:0E:7F:25:D9:8B
- inet addr:172.31.0.13 Bcast:172.31.3.255 Mask:255.255.252.0
- UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
- RX packets:1406 errors:0 dropped:0 overruns:0 frame:0
- TX packets:48 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:1000
- RX bytes:113967 (111.2 Kb) TX bytes:7268 (7.0 Kb)
- Interrupt:11
- eth1 Link encap:Ethernet HWaddr 00:0E:7F:25:D9:8B
- inet addr:172.31.0.13 Bcast:172.31.3.255 Mask:255.255.252.0
- UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
- RX packets:1411 errors:0 dropped:0 overruns:0 frame:0
- TX packets:47 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:1000
- RX bytes:112990 (110.3 Kb) TX bytes:7998 (7.8 Kb)
- Interrupt:15
在这种情况下出现一块网卡失效,仅仅会是服务器出口带宽下降,也不会影响网络使用.
Finally, today I had implemented NIC bounding (bind both NIC so that it works as a single device). Bonding is nothing but Linux kernel feature that allows to aggregate multiple like interfaces (such as eth0, eth1) into a single virtual link such as bond0. The idea is pretty simple get higher data rates and as well as link failover. The following instructions were tested on:
Say Hello To bounding DriverThis server act as an heavy duty ftp, and nfs file server. Each, night a perl script will transfer lots of data from this box to a backup server. Therefore, the network would be setup on a switch using dual network cards. I am using Red Hat enterprise Linux version 4.0. But, the inductions should work on RHEL 5 and 6 too.
Linux allows binding of multiple network interfaces into a single channel/NIC using special kernel module called bonding. According to official bonding documentation:
Step #1: Create a Bond0 Configuration FileThe Linux bonding driver provides a method for aggregating multiple network interfaces into a single logical "bonded" interface. The behavior of the bonded interfaces depends upon the mode; generally speaking, modes provide either hot standby or load balancing services. Additionally, link integrity monitoring may be performed.
Red Hat Enterprise Linux (and its clone such as CentOS) stores network configuration in /etc/sysconfig/network-scripts/ directory. First, you need to create a bond0 config file as follows:
# vi /etc/sysconfig/network-scripts/ifcfg-bond0
Append the following linest:
- DEVICE=bond0
- IPADDR=192.168.1.20
- NETWORK=192.168.1.0
- NETMASK=255.255.255.0
- USERCTL=no
- BOOTPROTO=none
- ONBOOT=yes
You need to replace IP address with your actual setup. Save and close the file.
Step #2: Modify eth0 and eth1 config filesOpen both configuration using a text editor such as vi/vim, and make sure file read as follows for eth0 interface
- DEVICE=eth0
- USERCTL=no
- ONBOOT=yes
- MASTER=bond0
- SLAVE=yes
- BOOTPROTO=none
Open eth1 configuration file using vi text editor, enter:
- DEVICE=eth1
- USERCTL=no
- ONBOOT=yes
- MASTER=bond0
- SLAVE=yes
- BOOTPROTO=none
Save and close the file.
Step # 3: Load bond driver/moduleMake sure bonding module is loaded when the channel-bonding interface (bond0) is brought up. You need to modify kernel modules configuration file:
First, load the bonding module, enter:
- Bonding Mode: load balancing (round-robin)
- MII Status: up
- MII Polling Interval (ms): 100
- Up Delay (ms): 200
- Down Delay (ms): 200
- Slave Interface: eth0
- MII Status: up
- Link Failure Count: 0
- Permanent HW addr: 00:0c:29:c6:be:59
- Slave Interface: eth1
- MII Status: up
- Link Failure Count: 0
- Permanent HW addr: 00:0c:29:c6:be:63
To kist all network interfaces, enter:
- bond0 Link encap:Ethernet HWaddr 00:0C:29:C6:BE:59
- inet addr:192.168.1.20 Bcast:192.168.1.255 Mask:255.255.255.0
- inet6 addr: fe80::200:ff:fe00:0/64 Scope:Link
- UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
- RX packets:2804 errors:0 dropped:0 overruns:0 frame:0
- TX packets:1879 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:0
- RX bytes:250825 (244.9 KiB) TX bytes:244683 (238.9 KiB)
- eth0 Link encap:Ethernet HWaddr 00:0C:29:C6:BE:59
- inet addr:192.168.1.20 Bcast:192.168.1.255 Mask:255.255.255.0
- inet6 addr: fe80::20c:29ff:fec6:be59/64 Scope:Link
- UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
- RX packets:2809 errors:0 dropped:0 overruns:0 frame:0
- TX packets:1390 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:1000
- RX bytes:251161 (245.2 KiB) TX bytes:180289 (176.0 KiB)
- Interrupt:11 Base address:0x1400
- eth1 Link encap:Ethernet HWaddr 00:0C:29:C6:BE:59
- inet addr:192.168.1.20 Bcast:192.168.1.255 Mask:255.255.255.0
- inet6 addr: fe80::20c:29ff:fec6:be59/64 Scope:Link
- UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
- RX packets:4 errors:0 dropped:0 overruns:0 frame:0
- TX packets:502 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:1000
- RX bytes:258 (258.0 b) TX bytes:66516 (64.9 KiB)
- Interrupt:10 Base address:0x1480
Read the which covers the following additional topics: