RHEL6 双网卡绑定

RHEL6 双网卡绑定

为了提供网络的高可用性,我们可能需要将多块网卡绑定成一块虚拟网卡对外提供服务,这样即使其中的一块物理网卡出现故障,也不会导致连接中断。多网卡绑定这个词在不同的平台有不同叫法,在Linux下叫bonding,IBM称为etherchanel,broadcom叫team,但是名字怎么变,效果都是将两块或更多的网卡当做一块网卡使用,在增加带宽的同时也可以提高冗余性。比如我们在RHEL6下可以将eth0和eth1绑定成虚拟网卡bond0。

 

1、  添加虚拟网卡

# vim /etc/sysconfig/network-scripts/ifcfg-bond0

# cat /etc/sysconfig/network-scripts/ifcfg-bond0

DEVICE=bond0

BOOTPROTO=static

ONBOOT=yes

IPADDR=192.168.12.128

NETMASK=255.255.255.0

USERCTL=no

#

 

2、  配置本地网卡信息

# vim /etc/sysconfig/network-scripts/ifcfg-eth0

# vim /etc/sysconfig/network-scripts/ifcfg-eth1

# cat /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE="eth0"

TYPE=Ethernet

BOOTPROTO=static

ONBOOT="yes"

MASTER=bond0

SLAVE=yes

USERCTL=no

# cat /etc/sysconfig/network-scripts/ifcfg-eth1

DEVICE="eth1"

TYPE=Ethernet

BOOTPROTO=static

ONBOOT="yes"

MASTER=bond0

SLAVE=yes

USERCTL=no

#

 

3、  模块加载

# vim /etc/modprobe.d/dist.conf

# grep bond0 /etc/modprobe.d/dist.conf

alias bond0 bonding

options bond0 miimon=100 mode=1

//miimon是指多久时间要检查网络一次,单位是ms(毫秒)这边的100,是100ms,即是0.1秒

//mode共有七种(0~6),这里解释两个常用的选项。

Ø  mode=0:平衡负载模式,两块网卡都在工作。

Ø  mode=1:自动主备模式,其中一块网卡在工作(若eth0断掉),则自动切换到另一个块网卡(eth1做备份)。

 

4、  重启网络服务,使配置生效

# service network restart

# cat /proc/net/bonding/bond0

Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)

 

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

Speed: 100 Mbps

Duplex: full

Link Failure Count: 0

Permanent HW addr: 00:0c:29:45:bf:a0

Slave queue ID: 0

 

Slave Interface: eth1

MII Status: up

Speed: 100 Mbps

Duplex: full

Link Failure Count: 0

Permanent HW addr: 00:0c:29:45:bf:aa

Slave queue ID: 0

# route  -n

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

192.168.128.0   0.0.0.0         255.255.255.0   U     0      0        0 bond0

169.254.0.0     0.0.0.0         255.255.0.0     U     1004   0        0 bond0

# lsmod | grep bond

bonding               109558  0

#

 

5、  测试

选择一台Linux机器ping测试机,然后停掉当前使用的网卡eth0,查看是否能够继续ping通

# ifdown eth0

# cat /proc/net/bonding/bond0

//发现此时激活的网卡为eth1了,如果测试可以ping通,则实验完成

Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)

 

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

Speed: 100 Mbps

Duplex: full

Link Failure Count: 0

Permanent HW addr: 00:0c:29:45:bf:aa

Slave queue ID: 0

#


posted @ 2012-10-18 17:22  枯木-Linux  阅读(399)  评论(0编辑  收藏  举报