免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 967 | 回复: 0
打印 上一主题 下一主题

linux_bonding 配置 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-03-12 17:07 |只看该作者 |倒序浏览

linux_bonding  
说明:
多块网卡虚拟成为一块网卡,具有相同的IP地址。这项技术其实在sun和cisco以及foundry中已经存在,分别称为Trunking和etherchannel以及portgroup技术,
在Linux中,这种技术称为bonding。主要实现冗余或负载均衡和增加带宽的功能。
    bonding技术早在内核版本为2.0的时候就已经出现,在内核2.4.x中已经包含,只需要在编译的时候把网络设备选项中的Bonding driver support选中就可以
。默认2.6内核中bonding已经被编译为M的选项,不需重新编译内核。察看是否挂在bonding,可用lsmod,modinfo等命令。
    其实Redhat在kernel-doc里有一篇文档,表述比较详细,可以先看看/usr/share/doc/kernel-doc-2.6.18/Documentation/networking/bonding.txt或者
linux-2.6.23/Documentation/networking/bonding.txt
一:不需重起的配置方法。
1 modprobe bonding miimon=100 mode=1
2 ifconfig bond0 192.168.1.1 netmask 255.255.255.0
3 ifenslave bond0 eth0 eth1
4 route add default gw 192.168.1.1 dev bond0
二:重起仍然生效的配置方法一。
1关闭要绑定的物理网卡
修改ifcfg-eth0和ifcfg-eth1的启动项
DEVICE=eth0
BOOTPROTO=none //网卡启动协议,分别有static,dhcp,none。
ONBOOT=no
2建立虚拟网卡
在/etc/sysconfig/network-scripts/ 目录下建立 ifcfg-bond0,并修改 /etc/modprobe.conf文件实现开机自动挂载。
/etc/sysconfig/network-scripts/ifcfg-bond0 配置如下:
DEVICE=bond0
IPADDR=192.168.0.193
NETMASK=255.255.255.0
BOOTPROTO=static
ONBOOT=yes
GATEWAY=192.168.0.3
/etc/modprobe.conf 配置如下:
alias eth0 bnx2
alias eth1 bnx2
alias bond0 bonding
options bonding miimon=100 mode=1(miimon是用来进行链路监测的。
比如:miimon=100,那么系统每100ms监测一次链路连接状态,如果有一条线路不通就转入另一条线路。模式1为主备模式,模式0为负载均衡与增加带宽的模式)
注:以上为只做一组bonding的方式,如果做多组的话可以更改为以下的方式:
alias eth0 bnx2
alias eth1 bnx2
alias eth2 e1000
alias eth3 e1000
install bond0 /sbin/modprobe -a eth0 eth1 && /sbin/modprobe bonding
alias bond0 bonding
install bond1 /sbin/modprobe -a eth2 eth3 && /sbin/modprobe bonding
alias bond1 bonding
options bonding mode=1 miimon=100 max_bonds=2
最后执行测试, REBOOT确认bond0是否启动,如果启动,配置成功。
查看bonding状态
cat /proc/net/bonding/bond0
三:重起仍然生效的配置方法二
1 vi /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
IPADDR=192.168.0.193
NETMASK=255.255.255.0
BOOTPROTO=static
ONBOOT=yes
GATEWAY=192.168.0.3
2 vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
3 vi /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
4 vi /etc/modprobe.conf
alias bond0 bonding
options bond0 miimon=100 mode=1
5 reboot
四: Linux 的 BONDING 模式
bonding 的应用分为合并网卡提高带宽与冗余两种功能。
在 linux kernel bonding 的 kernel module 內,可以依据传入 mode=X 的方式来决定运行模式,其中数值可能結果依据官方文件说明如下:
mode=0 (balance-rr)
Round-robin policy: Transmit packets in sequential order from the first available
slave through the last. This mode provides load balancing and fault tolerance.
mode=1 (active-backup)
Active-backup policy: Only one slave in the bond is active. A different slave
becomes active if, and only if, the active slave fails. The bond's MAC address is externally visible on only one port
(network adapter) to avoid confusing the switch. This mode provides fault tolerance. The primary option affects the behavior
of this mode.
mode=2 (balance-xor)
XOR policy: Transmit based on [(source MAC address XOR'd with destination
MAC address) modulo slave count]. This selects the same slave for each destination MAC address. This mode provides load
balancing and fault tolerance.
所以可以依据实际需求決定要使用哪种模式来提供 bonding 功能。一般所谓合并与平衡负载功能部份,选择 mode=0,而若是要达成 active-backup 架构的話,
則选择使用 mode=1 即可,注意,网卡需要支持mii-tool
设定配置文件, /etc/modprobe.conf 放置如下內容即可决定类型:
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)提供冗余功能,工作方式是主备的工作方式,也就是说默认情况下只有一块网卡工作,另一块做备份。
max_bonds=2 表示最大的网卡绑定数量为2。


注意:bonding modes(扼要说明)0 balance-rr: 负载平衡模式, 需有 switch 设定 (trunk) 支援才能发挥实质效果,具容错功能, 其中一張 Slave 网卡失效仍可持续运作
1 active-backup: 同一时间只有单一 Slave 网卡运作,Active Slave 网卡失效时自动启用下一个Slave 网卡,不需 switch 支援
2 balance-xor: *********
3 broadcast: 所有 Slave 网卡一起收送网络封包,具容错功能, 其中一張 Slave 网卡失效仍可持续运作
4 802.3ad: *********
5 balance-tlb: 传出自动负载平衡,传入由 Current Active Slave 负责,具容错功能, 其中一張 Slave 网卡失效仍可持续运作,不需 switch 支援及设定
6 balance-alb: 传出及传入皆自动负载均衡,具容错功能, 其中一張 Slave 网卡失效仍可持续运作,Slave 网卡 driver 需支援 setting hardware address
功能,不需 switch 支援及设定

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/19489/showart_1860554.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP