不信网恋 发表于 2018-5-12 10:44:17

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

  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模块
# modprobe bonding
  进入network-scripts目录
# cd /etc/sysconfig/network-scripts/
  编辑配置端口eth0
# vim ifcfg-eth0
  1 # Advanced Micro Devices 79c970
  2 DEVICE=eth0
  3 BOOTPROTO=dhcp
  4 ONBOOT=yes
  编辑配置端口eth1
# vim ifcfg-eth1
  1 # Advanced Micro Devices 79c970
  2 DEVICE=eth1
  3 BOOTPROTO=dhcp
  4 ONBOOT=yes
  把eth0的配置拷贝到bond0
# cp ifcfg-eth0 ifcfg-bond0
  编辑配置端口bon0
# vim ifcfg-bond0
  1 # Advanced Micro Devices 79c970
  2 DEVICE=bond0
  3 BOOTPROTO=none
  4 IPADDR=192.168.101.100-----------------------------------------配置IP地址
  5 NETWORK=255.255.255.0
  6 ONBOOT=yes
  编辑bonding模块
# 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
# 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
  重启服务器
# 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 时间&lt;1ms TTL=64
  来自 192.168.101.100 的回复: 字节=32 时间&lt;1ms TTL=64------------数据显示正常通信
  来自 192.168.101.100 的回复: 字节=32 时间&lt;1ms TTL=64
  来自 192.168.101.100 的回复: 字节=32 时间&lt;1ms TTL=64
  来自 192.168.101.100 的回复: 字节=32 时间&lt;1ms TTL=64
  查看bonding模块使用情况
# 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 时间&lt;1ms TTL=64
  来自 192.168.101.100 的回复: 字节=32 时间&lt;1ms TTL=64
  来自 192.168.101.100 的回复: 字节=32 时间&lt;1ms TTL=64
  请求超时。---------------------------------------------会看到数据包暂时会丢包,但马上又恢复通信
  来自 192.168.101.100 的回复: 字节=32 时间&lt;1ms TTL=64
  来自 192.168.101.100 的回复: 字节=32 时间&lt;1ms TTL=64
  来自 192.168.101.100 的回复: 字节=32 时间&lt;1ms TTL=64
  查看bonding模块使用情况
# 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文件
# 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&gt;&1 || : ; }; /sbin/mo dprobe -r --ignore-remove snd-ens1371
  10 alias eth1 pcnet32
  11 options bond0 miimon=100 mode=0--------------------使用bonding的0模式(负载均衡模式)
  重启服务器
# init 6
  测试数据接收情况
  Xshell:\&gt; ping 192.168.101.100 -t
  正在 Ping 192.168.101.100 具有 32 字节的数据:
  来自 192.168.101.100 的回复: 字节=32 时间&lt;1ms TTL=64
  来自 192.168.101.100 的回复: 字节=32 时间&lt;1ms TTL=64
  来自 192.168.101.100 的回复: 字节=32 时间&lt;1ms TTL=64------------------数据显示正常通信
  来自 192.168.101.100 的回复: 字节=32 时间&lt;1ms TTL=64
  来自 192.168.101.100 的回复: 字节=32 时间&lt;1ms TTL=64
  来自 192.168.101.100 的回复: 字节=32 时间&lt;1ms TTL=64
  查看bonding模块使用情况
# 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 时间&lt;1ms TTL=64
  来自 192.168.101.100 的回复: 字节=32 时间&lt;1ms TTL=64
  请求超时。---------------------------------------------会看到数据包暂时会丢包,但马上又恢复通信
  来自 192.168.101.100 的回复: 字节=32 时间&lt;1ms TTL=64
  来自 192.168.101.100 的回复: 字节=32 时间&lt;1ms TTL=64
  查看bonding模块使用情况
# 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的负载均衡模式
页: [1]
查看完整版本: RedHat下利用bonding实现linux服务器网卡绑定