Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2115238
  • 博文数量: 227
  • 博客积分: 10521
  • 博客等级: 上将
  • 技术积分: 3452
  • 用 户 组: 普通用户
  • 注册时间: 2006-10-20 14:59
个人简介

低调做人,高调做事!

文章分类

全部博文(227)

文章存档

2013年(4)

2012年(8)

2011年(16)

2010年(24)

2009年(92)

2008年(83)

分类: LINUX

2010-09-03 16:44:30

有时候一些重要的文件服务器除了在应用层实现高可用和负载均衡外,还需要在硬件(网卡)、物理线路上来保证网络的的高可用及负载均衡。

Linux bonding 驱动提供了一个把多个网络接口设备捆绑为单个的网络接口设置来使用,用于网络负载均衡及网络冗余,bonding在Linux内核2.4.12以后就已经默认支持,你可以通过如下方法查看内核是否支持bonding,否则你需要将它编译到内核。

[root@localhost ~]# modprobe -l | grep bonding
/lib/modules/2.6.18-164.el5PAE/kernel/drivers/net/bonding/bonding.ko

如果有返回结果,就说明内核支持,下面就简单介绍下实施步骤。



实施步骤如下:

1、创建网卡bond0文件
[root@localhost network-scripts]# more ifcfg-bond0
# Broadcom Corporation NetXtreme II BCM5708 Gigabit Ethernet
DEVICE=bond0
BOOTPROTO=none
ONBOOT=yes
NETMASK=255.255.255.0
IPADDR=192.168.100.11
GATEWAY=192.168.100.1
TYPE=Ethernet


2、修改ifcfg-eth0文件
[root@localhost network-scripts]# more ifcfg-eth0
# Broadcom Corporation NetXtreme II BCM5708 Gigabit Ethernet
DEVICE=eth0
USERCTL=no
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
TYPE=Ethernet


3、修改ifcfg-eth0文件
[root@localhost network-scripts]# more ifcfg-eth1
# Broadcom Corporation NetXtreme II BCM5708 Gigabit Ethernet
DEVICE=eth1
USERCTL=no
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
TYPE=Ethernet


4、修改/etc/modprobe.conf配置文件
目的是将新添加的bond0设备加入modprobe.conf中,以便kernel识别。

[root@localhost network-scripts]# more /etc/modprobe.conf
alias bond0 bonding
options bond0 miimon=100 mode=1

注:
miimon:是用来进行链路监测的 ,例如miimon=100,单位是毫秒,那么系统每100ms监测一次链路连接状态,如果有一条线路不通就转入另一条线路。
mode:为工作模式,可设置为高可用还是负载均衡,0为负载均衡(默认值),需根据交换机提供的工作模式选择,1为主备模式(也就是说只有一块网卡工作,另一块做备份)。

如果你要更改mode,记得一定要重新启动机器,切记切记!!!


5、将bonding生效(或完成上述步骤后重新启动电脑)
[root@localhost ~]# ldconfig
[root@localhost ~]# /etc/init.d/network restart


6、查看bonding状态
[root@localhost ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.4.0 (October 7, 2008)

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:1e:c9:b6:ac:cf

Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:1e:c9:b6:ac:d1

你也可以down掉 eth0 借口,再看看情况:

[root@localhost ~]# ifdown eth0
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.4.0 (October 7, 2008)

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
Link Failure Count: 0
Permanent HW addr: 00:1e:c9:b6:ac:d1



在测试中分别测试了高可用环境和负载均衡环境,网络故障的切换速度很快,对数据包的传输没有任何影响,在负载均衡下,整个机器的网路吞吐量比单网卡翻了一倍,你可以使用cacti来监控网络流量状况。

官方说明文档:http://www.kernel.org/pub/linux/kernel/people/marcelo/linux-2.4/Documentation/networking/bonding.txt
阅读(1640) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-09-06 14:41:02

Download More than 1000 free IT eBooks: http://free-ebooks.appspot.com