加入收藏 | 设为首页 | 会员中心 | 我要投稿 应用网_丽江站长网 (http://www.0888zz.com/)- 科技、建站、数据工具、云上网络、机器学习!
当前位置: 首页 > 站长资讯 > 外闻 > 正文

Linux 多网卡的7种bond模式原理

发布时间:2018-09-11 23:04:56 所属栏目:外闻 来源:talkwithtrend
导读:副标题#e# 9月15日技术沙龙 | 如何将智能化和运维工作相结合,实现智能运维! Linux 多网卡绑定 网卡绑定mode共有七种(0~6) bond0、bond1、bond2、bond3、bond4、bond5、bond6。 常用的有三种 mode=0:平衡负载模式,有自动备援,但需要Switch支援及设定。

第一步,配置设定文件:

  1. /etc/sysconfig/network-scripts/ifcfg-bond0  
  2. DEVICE=bond0  
  3. BOOTPROTO=none  
  4. ONBOOT=yes  
  5. IPADDR=192.168.0.100  
  6. NETMASK=255.255.255.0  
  7. NETWORK=192.168.0.0  
  8. BROADCAST=192.168.0.255  
  9. BROADCAST广播地址  
  10. /etc/sysconfig/network-scripts/ifcfg-eth0  
  11. DEVICE=eth0  
  12. BOOTPROTO=none  
  13. MASTER=bond0  
  14. SLAVE=yes  
  15. /etc/sysconfig/network-scripts/ifcfg-eth1  
  16. DEVICE=eth1  
  17. BOOTPROTO=none  
  18. MASTER=bond0  
  19. SLAVE=yes 

第二步,修改modprobe相关设定文件,并加载bonding模块:

1.在这里,我们直接创建一个加载bonding的专属设定文件/etc/modprobe.d/bonding.conf

  1. [root@test ~]# vi /etc/modprobe.d/bonding.conf 

追加

  1. alias bond0 bonding 
  2. options bonding mode=0 miimon=200 

2.加载模块(重启系统后就不用手动再加载了)

  1. [root@test ~]# modprobe bonding 

3.确认模块是否加载成功:

  1. [root@test ~]# lsmod | grep bonding 
  2. bonding 100065 0 

第三步,重启一下网络,然后确认一下状况:

  1. [root@test ~]# /etc/init.d/network restart  
  2. [root@test ~]# cat /proc/net/bonding/bond0  
  3. Ethernet Channel Bonding Driver: v3.5.0 (November 4, 2008)  
  4. Bonding Mode: fault-tolerance (active-backup)  
  5. Primary Slave: None  
  6. Currently Active Slave: eth0  
  7. …… 
  8.  
  9. [root@test ~]# ifconfig | grep HWaddr  
  10. bond0 Link encap:Ethernet HWaddr 00:16:36:1B:BB:74  
  11. eth0 Link encap:Ethernet HWaddr 00:16:36:1B:BB:74  
  12. eth1 Link encap:Ethernet HWaddr 00:16:36:1B:BB:74 

从上面的确认信息中,我们可以看到3个重要信息:

1.现在的bonding模式是active-backup

2.现在Active状态的网口是eth0

3.bond0,eth1的物理地址和处于active状态下的eth0的物理地址相同,这样是为了避免上位交换机发生混乱。

任意拔掉一根网线,然后再访问你的服务器,看网络是否还是通的。

第四步,系统启动自动绑定、增加默认网关:

  1. [root@test ~]# vi /etc/rc.d/rc.local 

追加

  1. ifenslave bond0 eth0 eth1 
  2. route add default gw 192.168.0.1 

如可上网就不用增加路由,0.1地址按环境修改.

留心:前面只是2个网口绑定成一个bond0的情况,如果我们要设置多个bond口,比如物理网口eth0和eth1组成bond0,eth2和eth3组成bond1,

那么网口设置文件的设置方法和上面第1步讲的方法相同,只是/etc/modprobe.d/bonding.conf的设定就不能像下面这样简单的叠加了:

  1. alias bond0 bonding  
  2. options bonding mode=1 miimon=200  
  3. alias bond1 bonding  
  4. options bonding mode=1 miimon=200 

正确的设置方法有2种:

第一种,你可以看到,这种方式的话,多个bond口的模式就只能设成相同的了:

  1. alias bond0 bonding  
  2. alias bond1 bonding  
  3. options bonding max_bonds=2 miimon=200 mode=1 

(编辑:应用网_丽江站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读