zoukankan      html  css  js  c++  java
  • 多网卡绑定。。。bond实现

    Linux 多网卡绑定

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

    常用的有三种

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

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

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

    添加多网卡

    vi /etc/sysconfig/network-scripts/ifcfg-bond0

    DEVICE=bond0
    NAME=bond0
    TYPE=Bond
    BONDING_MASTER=yes
    IPADDR=192.168.1.142
    NETMASK=255.255.255.0
    GATEWAY=192.168.1.1
    DNS1=192.168.1.1
    ONBOOT=yes
    BOOTPROTO=none
    USERCTL=no
    BONDING_OPTS="mode=6 miimon=100"

    vi /etc/sysconfig/network-scripts/ifcfg-eth0

    DEVICE="eth0"
    ONBOOT="yes"
    MASTER=bond0
    SLAVE=yes
    USERCTL=no

    vi /etc/sysconfig/network-scripts/ifcfg-eth1

    DEVICE="eth1"
    ONBOOT="yes"
    MASTER=bond0
    SLAVE=yes
    USERCTL=no

    vi /etc/modprobe.d/bonding.conf

    alias bond0 bonding
    options bond0 miimon=100 mode=6

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

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

    #追加

    alias bond0 bonding

    options bonding mode=0 miimon=200

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

    [root@test ~]# modprobe bonding

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

    [root@test ~]# lsmod | grep bonding

    bonding 100065 0

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

    [root@test ~]# /etc/init.d/network restart

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

    Ethernet Channel Bonding Driver: v3.5.0 (November 4, 2008)

    Bonding Mode: fault-tolerance (active-backup)

    Primary Slave: None

    Currently Active Slave: eth0

    ……

     [root@test ~]# ifconfig | grep HWaddr

    bond0 Link encap:Ethernet HWaddr 00:16:36:1B:BB:74

    eth0 Link encap:Ethernet HWaddr 00:16:36:1B:BB:74

    eth1 Link encap:Ethernet HWaddr 00:16:36:1B:BB:74

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

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

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

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

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

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

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

    #追加

    ifenslave bond0 eth0 eth1

    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的设定就不能像下面这样简单的叠加了:

    alias bond0 bonding

    options bonding mode=1 miimon=200

    alias bond1 bonding

    options bonding mode=1 miimon=200

    正确的设置方法有2种:

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

    alias bond0 bonding

    alias bond1 bonding

    options bonding max_bonds=2 miimon=200 mode=1

    第二种,这种方式,不同的bond口的mode可以设成不一样:

    alias bond0 bonding

    options bond0 miimon=100 mode=1

    install bond1 /sbin/modprobe bonding -o bond1 miimon=200 mode=0

    仔细看看上面这2种设置方法,现在如果是要设置3个,4个,甚至更多的bond口,你应该也会了吧!

    后记:简单的介绍一下上面在加载bonding模块的时候,options里的一些参数的含义:

    miimon 监视网络链接的频度,单位是毫秒,我们设置的是200毫秒。

    max_bonds 配置的bond口个数

    mode bond模式,主要有以下几种,在一般的实际应用中,0和1用的比较多,

    如果你要深入了解这些模式各自的特点就需要靠读者你自己去查资料并做实践了。

    from:http://support.huawei.com/ecommunity/bbs/10155553.html

  • 相关阅读:
    [转载]必须Mark!最佳HTML5应用开发工具推荐
    [转载]JavaScript 的轻框架开发
    [转载]Browser Link feature in Visual Studio Preview 2013
    回溯算法
    双指针法总结
    链表中的快慢指针法
    快慢指针之原地处理数组/链表
    滑动窗口法
    左右指针法:二分查找-其它应用
    左右指针法:二分查找-寻找数
  • 原文地址:https://www.cnblogs.com/han1094/p/6500855.html
Copyright © 2011-2022 走看看