linux绑定网卡编号,linux下多网卡绑定配置及心得

绑定多块网卡为一个虚拟ip,类似csico的etherchannel,实现冗余或负载均衡和增加带宽的功能。

内核需要bonding的支持,察看是否挂在bonding,lsmod命令。默认2.6内核中bonding已经被编译为M的选项,不需重新编译内核。

其实Redhat关于bond,在kernel-doc里有一篇文档,讲述得非常详细,可以先看看/usr/share/doc/kernel-doc- 2.6.18/Documentation/networking/bonding.txt

一:不需重起的配置方法。

1 modprobe bonding miimon=100

2 ifconfig bond0 192.168.0.1 netmask 255.255.255.0

3 ifenslave bond0 eth0 eth1

二:重起仍然生效的配置方法一。

1关闭要绑定的物理网卡

修改ifcfg-eth0和ifcfg-eth1的启动项

BOOTPROTO=none

ONBOOT=no

2建立虚拟网卡

在/etc/sysconfig/network-scripts/ 目录下建立 ifcfg-bond0,并修改 /etc/modprobe.conf文件实现开机自动挂载。Centos6之后的版本在/etc目录下可能找不到这个文件,是默认没有生成可以vi创建一个,并添加相应需要开机启动的设备或者模块。

在/etc/modprobe.conf文件中添加bond0,bond1:

#cat /etc/modprobe.conf

alias bond0 bonding

options bond0 miimon=100 mode=1 或options bonding miimon=100 mode=1 (总)

/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.d/dist.conf 配置如下:

alias bond0 bonding

options bonding miimon=100 mode=0(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=0 miimon=100 max_bonds=2

最后执行测试, REBOOT确认bond0和bond1是否启动,如果启动,配置成功。

查看bonding状态at

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

alias bond1 bonding

options bonding miimon=100 mode=0 (全包括) 或options bond0 miimon=100 mode=0

options bondi1miimon=100 mode=0

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=0

说明: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。

***注意事项***

这里/etc/modprobe.conf这个文件很关键,关乎重启后能否加载bonding,如果/etc目录下没有此文件,请创建并把相应语句加进去。以上三种绑定网卡的方法都经过亲测。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值