美文网首页Linux
linux绑定bond的七种模式

linux绑定bond的七种模式

作者: cf6d95617c55 | 来源:发表于2018-03-29 21:47 被阅读0次

    目前网卡绑定mode共有七种(0~6)bond0、bond1、bond2、bond3、bond4、bond5、bond6

    常用的有三种:

    mode=0:平衡负载模式,有自动备援,但需要”Switch”支援及设定。

    mode=1:自动备援模式,其中一条线若断线,其他线路将会自动备援。

    mode=6:平衡负载模式,有自动备援,不必”Switch”支援及设定。

    Linux网口绑定:

    通过网口绑定(bond)技术,可以很容易实现网口冗余,负载均衡,从而达到高可用高可靠的目的。前提约定:

    2个物理网口分别是:eth0,eth1

    绑定后的虚拟口是:bond0

    服务器IP是:10.10.10.1

    第一步,配置设定文件:

    [root@woo ~]# vi  /etc/sysconfig/network-scripts/ifcfg-bond0  

    DEVICE=bond0  

    BOOTPROTO=none  

    ONBOOT=yes  

    IPADDR=10.10.10.1  

    NETMASK=255.255.255.0  

    NETWORK=192.168.0.0 

    [root@woo ~]# vi  /etc/sysconfig/network-scripts/ifcfg-eth0  

    DEVICE=eth0  

    BOOTPROTO=none  

    MASTER=bond0  

    SLAVE=yes 

    [root@woo ~]# vi  /etc/sysconfig/network-scripts/ifcfg-eth1  

    DEVICE=eth1  

    BOOTPROTO=none  

    MASTER=bond0  

    SLAVE=yes  

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

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

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

    alias bond0 bonding  

    options bonding mode=0 miimon=200 

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

    [root@woo ~]# modprobe bonding 

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

    [root@woo ~]# lsmod | grep bonding  

    bonding 100065 0  

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

    [root@db01 ~]# service network restart  

    Shutting down interface bond0:  [  OK  ]  

    Shutting down loopback interface:  [  OK  ]  

    Bringing up loopback interface:  [  OK  ]  

    Bringing up interface bond0:  [  OK  ] 

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

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

    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: 1000 Mbps  

    Duplex: full  

    Link Failure Count: 0  

    Permanent HW addr: 40:f2:e9:db:c9:c2 

    Slave Interface: eth1  

    MII Status: up  

    Speed: 1000 Mbps  

    Duplex: full  

    Link Failure Count: 0  

    Permanent HW addr: 40:f2:e9:db:c9:c3  

    [root@db01 ~]#  ifconfig | grep HWaddr  

    bond0     Link encap:Ethernet  HWaddr 40:F2:E9:DB:C9:C2    

    eth0      Link encap:Ethernet  HWaddr 40:F2:E9:DB:C9:C2    

    eth1      Link encap:Ethernet  HWaddr 40:F2:E9:DB:C9:C2    

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

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

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

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

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

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

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

    #追加  

    ifenslave bond0 eth0 eth1  

    route add default gw 10.10.10.1 

    相关文章

      网友评论

        本文标题:linux绑定bond的七种模式

        本文链接:https://www.haomeiwen.com/subject/gwbvcftx.html