设为首页 收藏本站
查看: 507|回复: 0

[经验分享] RedHat下利用bonding实现linux服务器网卡绑定

[复制链接]

尚未签到

发表于 2018-5-12 10:44:17 | 显示全部楼层 |阅读模式
  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中的各个网卡上。此模式提供负载均衡和容错。
  拓扑图
DSC0000.gif

  一、 主备模式 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 时间&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模块使用情况
[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 时间&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模块使用情况
[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&gt;&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:\&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模块使用情况
[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 时间&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模块使用情况
[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的负载均衡模式

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-459030-1-1.html 上篇帖子: redhat各目录作用 下篇帖子: Redhat OpenShift架构剖析
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表