您的位置:首页 > 运维架构 > Linux

RedHat下利用bonding实现linux服务器网卡绑定

2012-08-13 18:50 441 查看
RedHat下利用bonding实现linux服务器网卡绑定

Linux系统提供了网卡绑定(NIC Bonding)功能,关于网卡绑定的设置中中有6种mode,以下主要对mode 0 和 mode 1进行说明和实验。

1. mode 1

Active Backup: 此模式下Bonding中只有一块网卡处于激活状态,其余网卡只有在处于工作状态的网卡出错时才会激活。为了不扰乱交换机,Bonding的MAC地址只有一个是外部可见的。

2. mode 0

Balance-rr(Round-robin policy): 此模式下,数据包传输将按顺序发送到Bonding中的各个网卡上。此模式提供负载均衡和容错。

拓扑图





一、 主备模式 mode=1

linux服务器网卡端口配置

调用bonding模块

[root@localhost ~]# modprobe bonding

进入network-scripts目录

[root@localhost ~]# cd /etc/sysconfig/network-scripts/

编辑配置端口eth0

[root@localhost network-scripts]# vim ifcfg-eth0

1 # Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]

2 DEVICE=eth0

3 BOOTPROTO=dhcp

4 ONBOOT=yes

编辑配置端口eth1

[root@localhost network-scripts]# vim ifcfg-eth1

1 # Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]

2 DEVICE=eth1

3 BOOTPROTO=dhcp

4 ONBOOT=yes

把eth0的配置拷贝到bond0

[root@localhost network-scripts]# cp ifcfg-eth0 ifcfg-bond0

编辑配置端口bon0

[root@localhost network-scripts]# vim ifcfg-bond0

1 # Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]

2 DEVICE=bond0

3 BOOTPROTO=none

4 IPADDR=192.168.101.100-----------------------------------------配置IP地址

5 NETWORK=255.255.255.0

6 ONBOOT=yes

编辑bonding模块

[root@localhost network-scripts]# vim /etc/modprobe.conf

1 alias eth0 pcnet32

2 alias bond0 bonding----------------------------------------------指明bond0使用的模块为bonding

3 alias scsi_hostadapter mptbase

4 alias scsi_hostadapter1 mptspi

5 alias scsi_hostadapter2 ata_piix

6 alias snd-card-0 snd-ens1371

7 options snd-card-0 index=0

8 options snd-ens1371 index=0 9 remove snd-ens1371 { /usr/sbin/alsactl store 0 >/dev/null 2>&1 || : ; }; /sbin/mo dprobe -r --ignore-remove snd-ens1371

10 alias eth1 pcnet32

11 options bond0 miimon=100 mode=1--------------------------使用bonding的1模式(主备模式)

编辑开机脚本文件,使eth0和eth1指向bond0

[root@localhost network-scripts]# vim /etc/rc.local

1 #!/bin/sh

2 #

3 # This script will be executed *after* all the other init scripts.

4 # You can put your own initialization stuff in here if you don't

5 # want to do the full Sys V style init stuff.

6

7 touch /var/lock/subsys/local

8 ifenslave bond0 eth0 eth1--------------------------------------使eth0和eth1指向bond0

重启服务器

[root@localhost ~]# init 6

测试数据接收情况

Xshell:\> ping 192.168.101.100 -t

正在 Ping 192.168.101.100 具有 32 字节的数据:

来自 192.168.101.100 的回复: 字节=32 时间<1ms TTL=64

来自 192.168.101.100 的回复: 字节=32 时间<1ms TTL=64

来自 192.168.101.100 的回复: 字节=32 时间<1ms TTL=64------------数据显示正常通信

来自 192.168.101.100 的回复: 字节=32 时间<1ms TTL=64

来自 192.168.101.100 的回复: 字节=32 时间<1ms TTL=64

来自 192.168.101.100 的回复: 字节=32 时间<1ms TTL=64

查看bonding模块使用情况

[root@localhost ~]# cat /proc/net/bonding/bond0

Ethernet Channel Bonding Driver: v3.4.0 (October 7, 2008)

Bonding Mode: fault-tolerance (active-backup)----------------现在使用的boding模式为主备模式

Primary Slave: None

Currently Active Slave: eth0----------------------------------------当前激活的端口是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:0c:29:0e:84:dd

Slave Interface: eth1---------------------------------------------------备用端口是eth1

MII Status: up

Link Failure Count: 0

Permanent HW addr: 00:0c:29:0e:84:e7

测试一下把eth0端口关闭,看一下数据通信情况

来自 192.168.101.100 的回复: 字节=32 时间<1ms TTL=64

来自 192.168.101.100 的回复: 字节=32 时间<1ms TTL=64

来自 192.168.101.100 的回复: 字节=32 时间<1ms TTL=64

请求超时。---------------------------------------------会看到数据包暂时会丢包,但马上又恢复通信

来自 192.168.101.100 的回复: 字节=32 时间<1ms TTL=64

来自 192.168.101.100 的回复: 字节=32 时间<1ms TTL=64

来自 192.168.101.100 的回复: 字节=32 时间<1ms TTL=64

查看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: eth1-------------------------------------当前激活端口已经变为eth1

MII Status: up

MII Polling Interval (ms): 100

Up Delay (ms): 0

Down Delay (ms): 0

Slave Interface: eth0----------------------------------------------eth0变为备用端口

MII Status: down

Link Failure Count: 1

Permanent HW addr: 00:0c:29:0e:84:dd

Slave Interface: eth1

MII Status: up

Link Failure Count: 0

Permanent HW addr: 00:0c:29:0e:84:e7

上述测试证明此次实验配置成功实现了bonding的主备模式

二、平衡负载模式 mode=0

仅修改一下modprobe.conf文件

[root@localhost network-scripts]# vim /etc/modprobe.conf

1 alias eth0 pcnet32

2 alias bond0 bonding----------------------------------------------指明bond0使用的模块为bonding

3 alias scsi_hostadapter mptbase

4 alias scsi_hostadapter1 mptspi

5 alias scsi_hostadapter2 ata_piix

6 alias snd-card-0 snd-ens1371

7 options snd-card-0 index=0

8 options snd-ens1371 index=0 9 remove snd-ens1371 { /usr/sbin/alsactl store 0 >/dev/null 2>&1 || : ; }; /sbin/mo dprobe -r --ignore-remove snd-ens1371

10 alias eth1 pcnet32

11 options bond0 miimon=100 mode=0--------------------使用bonding的0模式(负载均衡模式)

重启服务器

[root@localhost ~]# init 6

测试数据接收情况

Xshell:\> ping 192.168.101.100 -t

正在 Ping 192.168.101.100 具有 32 字节的数据:

来自 192.168.101.100 的回复: 字节=32 时间<1ms TTL=64

来自 192.168.101.100 的回复: 字节=32 时间<1ms TTL=64

来自 192.168.101.100 的回复: 字节=32 时间<1ms TTL=64------------------数据显示正常通信

来自 192.168.101.100 的回复: 字节=32 时间<1ms TTL=64

来自 192.168.101.100 的回复: 字节=32 时间<1ms TTL=64

来自 192.168.101.100 的回复: 字节=32 时间<1ms TTL=64

查看bonding模块使用情况

[root@localhost ~]# cat /proc/net/bonding/bond0

Ethernet Channel Bonding Driver: v3.4.0 (October 7, 2008)

Bonding Mode: load balancing (round-robin)

MII Status: up

MII Polling Interval (ms): 100

Up Delay (ms): 0

Down Delay (ms): 0

Slave Interface: eth0

MII Status: up--------------------------------------------------------eth0显示为开启状态

Link Failure Count: 0

Permanent HW addr: 00:0c:29:0e:84:dd

Slave Interface: eth1

MII Status: up-------------------------------------------------------eth1也显示为开启状态

Link Failure Count: 0

Permanent HW addr: 00:0c:29:0e:84:e7

测试一下把eth0端口关闭,看一下数据通信情况

来自 192.168.101.100 的回复: 字节=32 时间<1ms TTL=64

来自 192.168.101.100 的回复: 字节=32 时间<1ms TTL=64

请求超时。---------------------------------------------会看到数据包暂时会丢包,但马上又恢复通信

来自 192.168.101.100 的回复: 字节=32 时间<1ms TTL=64

来自 192.168.101.100 的回复: 字节=32 时间<1ms TTL=64

查看bonding模块使用情况

[root@localhost ~]# cat /proc/net/bonding/bond0

Ethernet Channel Bonding Driver: v3.4.0 (October 7, 2008)

Bonding Mode: load balancing (round-robin)

MII Status: up

MII Polling Interval (ms): 100

Up Delay (ms): 0

Down Delay (ms): 0

Slave Interface: eth0

MII Status: down----------------------------------------------------------eth0已显示为关闭状态

Link Failure Count: 1

Permanent HW addr: 00:0c:29:0e:84:dd

Slave Interface: eth1

MII Status: up----------------------------------------------------------------eth1显示为开启状态

Link Failure Count: 0

Permanent HW addr: 00:0c:29:0e:84:e7

上述测试证明此次实验配置成功实现了bonding的负载均衡模式
本文出自 “这就是我博客” 博客,请务必保留此出处http://mh3570.blog.51cto.com/5636160/962496
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: