首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Redhat Linux bonding 配置手册

Posted on 2009-11-01 22:44  放飞自我  阅读(4534)  评论(0编辑  收藏  举报
实验环境: Redhat Linux Enterprise 4
绑定的前提条件:芯片组型号相同,而且网卡应该具备自己独立的BIOS芯片
 
一  热备模式.
 
特点:
1. 正在工作的网卡不正常后,切换到备用网卡,此时会中间几秒钟
2. 恢复不正常的网卡时,不会引发网络中断.
首先要看linux是否支持bonding,RHEL4已经默认支持了.(大部分发行版都支持)
# modinfo bonding
 
filename:       /lib/modules/2.6.18-8.el5/kernel/drivers/net/bonding/bonding.ko
author:         Thomas Davis, tadavis@lbl.gov and many others
de.ion:    Ethernet Channel Bonding Driver, v3.0.3
version:        3.0.3
license:        GPL
srcversion:     2547D22885C2FDF28EF7D98
如果有类似上面的信息输出,说明已经支持了.
 
1.编辑虚拟网络接口配置文件,指定网卡IP 
vi /etc/sysconfig/network-.s/ ifcfg-bond0 
[root@rhas-13 root]#cp /etc/sysconfig/network-scripts/ifcfg-lo ifcfg-bond0
 
[root@cl303 network-.s]# vi  ifcfg-bond0
DEVICE=bond0
IPADDR=10.10.10.1
NETMASK=255.255.255.0
NETWORK=10.10.10.0
BROADCAST=10.10.10.255
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
GATEWAY=192.168.0.1
 
在bond0上添加网关,是确保默认路由无故障
[root@Linux ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.0.0.0        *               255.255.255.0   U     0      0        0 bond0
10.0.0.0        *               255.255.255.0   U     0      0        0 eth0
10.0.0.0        *               255.255.255.0   U     0      0        0 eth1
169.254.0.0     *               255.255.0.0     U     0      0        0 bond0
default         10.0.0.1        0.0.0.0         UG    0      0        0 bond0
 
[root@cl303 network-.s]# vi  ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
MASTER=bond0
SLAVE=yes
 
[root@cl303 network-.s]# vi  ifcfg-eth1
DEVICE=eth1
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
MASTER=bond0
SLAVE=yes
 
3 # vi /etc/modprobe.conf
编辑/etc/modprobe.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)提供冗余功能,工作方式是主备的工作方式,也就是说默认情况下只有一块网卡工作,另一块做备份.  
 
4 # vi /etc/rc.d/rc.local 
加入以下内容 
# 仅在热备模式下,eht0 eth1网卡的工作顺序.
 
ifenslave bond0 eth0 eth1 
 
到这时已经配置完毕重新启动机器.
重启会看见以下信息就表示配置成功了
................ 
Bringing up interface bond0 OK 
Bringing up interface eth0 OK 
Bringing up interface eth1 OK 
 
 
二  负载均衡
特点:
1. 双网块同时工作,实现负载均衡,某一网卡不正常时,不会引发网络中断.
2. 恢复不能正常工作的网卡时,会引发网络中断几秒,然后双网卡同时工作.
 
vi /etc/modprobe.conf
编辑/etc/modprobe.conf 文件,加入如下一行内容,以使系统在启动时加载bonding模块,对外虚拟网络接口设备为 bond0 
 
加入下列两行 
alias bond0 bonding 
options bond0 miimon=100 mode=0
 
 
######################################
下面我们讨论以下mode分别为0,1时的情况
 
mode=1工作在主备模式下,这时eth1作为备份网卡是no arp的
[root@rhas-13 network-.s]# 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:18495 errors:0 dropped:0 overruns:0 frame:0
          TX packets:480 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:1587253 (1.5 Mb)  TX bytes:89642 (87.5 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:9572 errors:0 dropped:0 overruns:0 frame:0
          TX packets:480 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:833514 (813.9 Kb)  TX bytes:89642 (87.5 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 NOARP SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:8923 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:753739 (736.0 Kb)  TX bytes:0 (0.0 b)
          Interrupt:15
    那也就是说在主备模式下,当一个网络接口失效时(例如主交换机掉电等),不回出现网络中断,系统会按照cat /etc/rc.d/rc.local里指定网卡的顺序工作,机器仍能对外服务,起到了失效保护的功能.
 
 
通过查看bond0的工作状态查询能详细的掌握bonding的工作状态
[root@cl303 ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v2.6.0 (January 14, 2004)
 
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth0
MII Status: up
MII Polling Interval (ms): 10
Up Delay (ms): 0
Down Delay (ms): 0
 
Slave Interface: eth0
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:0c:29:63:bc:b7
 
Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:0c:29:63:bc:c1
 
 
 
 
在mode=0    负载均衡工作模式,他能提供两倍的带宽,下我们来看一下网卡的配置信息
[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
 
      在这种情况下出现一块网卡失效,仅仅会是服务器出口带宽下降,也不会影响网络使用.
 
 
[root@cl303 ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v2.6.0 (January 14, 2004)
 
Bonding Mode: load balancing (round-robin)
MII Status: up
MII Polling Interval (ms): 1
Up Delay (ms): 0
Down Delay (ms): 0
 
Slave Interface: eth0
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:0c:29:63:bc:b7
 
Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:0c:29:63:bc:c1