Fedora16---Channel Bonding Interfaces

来源:互联网 发布:python写界面 编辑:程序博客网 时间:2024/04/29 14:17

Fedora allows administrators to bind multiple network interfaces together into a single channel using the bonding kernel module and a special network interface called a channel bonding interface. Channel bonding enables two or more network interfaces to act as one, simultaneously increasing the bandwidth and providing redundancy.

To create a channel bonding interface, create a file in the /etc/sysconfig/network-scripts/ directory called ifcfg-bondN, replacing N with the number for the interface, such as 0.

After the channel bonding interface is created, the network interfaces to be bound together must be configured by adding the MASTER= and SLAVE= directives to their configuration files. The configuration files for each of the channel-bonded interfaces can be nearly identical.

For a channel bonding interface to be valid, the kernel module must be loaded. To ensure that the module is loaded when the channel bonding interface is brought up, create a new file as root named bonding.conf in the /etc/modprobe.d/ directory. Note that you can name this file anything you like as long as it ends with a .confextension. Insert the following line in this new file: alias bondN bondingReplace N with the interface number, such as 0. For each configured channel bonding interface, there must be a corresponding entry in your new /etc/modprobe.d/bonding.conf file.


对于bonding的网络负载均衡是我们在文件服务器中常用到的,比如把三块网卡,当做一块来用,解决一个IP地址,流量过大,服务器网络压力过大的问 题。对于文件服务器来说,比如NFS或SAMBA文件服务器,没有任何一个管理员会把内部网的文件服务器的IP地址弄很多个来解决网络负载的问题。如果在 内网中,文件服务器为了管理和应用上的方便,大多是用同一个IP地址。对于一个百M的本地网络来说,文件服务器在多个用户同时使用的情况下,网络压力是极 大的,特别是SAMABA和NFS服务器。为了解决同一个IP地址,突破流量的限制,毕竟网线和网卡对数据的吞吐量是有限制的。如果在有限的资源的情况 下,实现网络负载均衡,最好的办法就是 bonding ;
网络冗余;
对于服务器来说,网络设备的稳定也是比较重要的,特别是网卡。在生产型的系统中,网卡的可靠性就更为重要了。在生产型的系统中,大多通过硬件设备的冗余来 提供服务器的可靠性和安全性,比如电源。bonding 也能为网卡提供冗余的支持。把网个网卡绑定到一个IP地址,当一块网卡发生物理性损坏的情况下,另一块网卡也能提供正常的服务。

双网卡绑定设置
一、编辑虚拟网络接口配置文件,指定网卡IP
假设eth0是对外服务的网卡,已经调试好网络;eth1是希望与eth0同时对外提供服务的网卡

# cd /etc/sysconfig/network-scripts/

#vi ifcfg-bond0

写入如下信息和原来 ifcfg-eth0 的配置其实差不多。
所以我建议执行如下语句,将ifcfg-eth0复制一份再改。

# cp ifcfg-eth0 ifcfg-bon0

将ifcfg-bon0的信息修改大致如下:

DEVICE=bond0
BOOTPROTO=static
IPADDR=[IP]
NETMASK=[MASK]
BROADCAST=[BROADCAST]
GATEWAY=[GATEWAY]
ONBOOT=yes
TYPE=Ethernet

二、配置真实网卡
修改ifcfg-eth0如下:

DEVICE=eth0

BOOTPROTO=none

ONBOOT=yes

MASTER=bond0     #如果不写,则必须做第四步

SLAVE=yes             #如果不写,则必须做第四步

USERCTL=yes

类似地修ifcfg-eth1如下:

DEVICE=eth1

BOOTPROTO=none

ONBOOT=yes

MASTER=bond0     #如果不写,则必须做第四步

SLAVE=yes             #如果不写,则必须做第四步

USERCTL=yes

三、加载模块,让系统 支持bonding
默认情况下,内核已支持bonding,只需要简单修改/etc/modprobe.conf 这个配置文档就可以了:添加两行

alias bond0 bonding

options bond0 miimon=100 mode=1

说明:
mode指定了bond0的工作模式,在redhat中有0-6共7种工作模式,常用的是0和1。

mode=0 表示 load balancing (round-robin)为负载均衡方式,两块网卡都工作。
mode=1 表示 fault-tolerance (active-backup)提供冗余功能,工作方式是主 从的工作方式,也就是说默认情况下只有一块网卡工作,另一块做备份。
mode=2 表示 XOR policy 为平衡策略。此模式提供负载平衡和容错能力
mode=3 表示 broadcast 为广播策略。此模式提供了容错能力
mode=4 表示 IEEE 802.3ad Dynamic link aggregation 为 IEEE 802.3ad 为 动态链接聚合。该策略可以通过 xmit_hash_policy 选项从缺省的 XOR 策略改变到其他策略。
mode=5 表示 Adaptive transmit load balancing 为适配器传输负载均衡。该 模式的必要条件:ethtool 支持获取每个 slave 的速率
mode=6 表示 Adaptive load balancing 为适配器适应性负载均衡。该模式包含 了 balance-tlb 模式,同时加上针对 IPV4 流量的接收负载均衡(receive load   balance, rlb),而且不需要任何 switch(交换机)的支持。
bonding 只能提供链路监测,即从主机到交换机的链路是否接通。如果只是交换机对 外的链路 down 掉了,而交换机本身并没有故障,那么 bonding 会认为链路没有问题而继 续使用。

关于绑定网卡的详细参数可参见笔者的另一篇文章

http://czmmiao.iteye.com/admin/blogs/1044031

四、增加开机启动脚本
在 /etc/rc.d/rc.local里加上

#ifenslave bond0 eth0 eth1

如果eth0和eth1都写了MASTER和SLAVE,则上面的步骤做不做都无所谓。
五、重启
reboot或者service network restart 都可以看到结果。

六、查看绑定在哪张网卡上

# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.0.3 (March 23, 2006)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth0
MII Status: up
MII Polling Interval (ms): 500
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth0
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:0c:29:01:4f:77

Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:0c:29:01:4f:8b
六、测试
ping着某个地址,当然是能ping通的地址啦。如果发现网络不通,请检查ifcfg-bond0的网络设置。
然后拔掉一根网线,如果ping没断,证明拔了一根backup的线,不是主线,重新插上等两分钟。
此时拔掉另一根网线,估计现在可以看到ping超时或者卡在那里,稍等10~30秒,ping继续连同。
测试成功。

七、交换机配置

conf t
interf port-channel 1
switchport mode access
inter range fa0/1-2
channel-group 1 mode on

原创粉丝点击