linux下的双网卡bonding配置

来源:互联网 发布:mac minila air 改键 编辑:程序博客网 时间:2024/05/09 17:09

1.检查你的系统是否支持bonding

    首先,执行命令:

    $rpm -qf  /sbin/ifup

     它会返回一行文本,以“initscripts”或"sysconfig"开头,他是提供网络初始化脚本的包。

    下一步,为了确定你的安装是否支持bonding,执行命令:

     $grep ifenslave /sbin/ifup

     如果返回任何匹配记录,则表示你的initscripts 或sysconfig 支持bonding


2.修改网络适配器的配置

     针对现在的网络适配器配置文件进行修改,配置文件都放在/etc/sysconfig/network-scripts目录下,如下:

     第一个网络适配器:

     vim /etc/sysconfig/network-scripts/eth0

      DEVICE=eth0

      ONBOOT=yes

       BOOTPROTO=none

       MASTER=bond0

       SLAVE=yes

      第二个网络适配器:

      vim /etc/sysconfig/network-scripts/eth1

       DEVICE=eth1

       USERCTL=no

       ONBOOT=yes

        MASTER=bond0

        SLAVE=yes

        BOOTPROTO=none

3.创建bonding的网络脚本

   vim /etc/sysconfig/network-scripts/bond0

    DEVICE=bond0 

    IPADDR=192.168.1.66

    NETMASK=255.255.255.0

     NETWORK=192.168.1.0

     BROADCAST=192.168.1.255

     ONBOOT=yes

     BOOTPROTO=none

     USERCTL=no

4.bond驱动的选项

     bonding驱动的选项是通过在加载时制定参数来设定的,通常在以下两个文件里面指定。

      编辑/etc/modprobe.conf,添加以下两行:

       alias bond0 bonding

        options bond0 mode=1 million=100

     说明:
     mode指定了bond0的工作模式,常用的是0和1,0表示负载均衡方式,1表示主从方式,可根据需要自行配置。常用的为0,1两种。mode=0表示 load balancing (round-robin)为负载均衡方式,两块网卡都工作。mode=1表示fault-tolerance (active-backup)提供冗余功能,工作方式是主备的工作方式,也就是说默认情况下只有一块网卡工作,另一块做备份。bonding只能提供链路监测,即从主机到交换机的链路是否接通。如果只是交换机对外的链路down掉了,而交换机本身并没有故障,那么bonding会认为链路没有问题而继续使用。 miimon是用来进行链路监测的。比如:miimon=100,那么系统每100ms监测一次链路连接状态,如果有一条线路不通就转入另一条线路。


5.启用bonding

    #service network restart

6.测试

   cat /proc/net/bonding/bond0

 Ethernet Channel Bonding Driver: v2.6.3-rh (June 8, 2005)  

 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 Link Failure Count: 0 

 Permanent HW addr: 00:0c:29:6e:40:9d  

 Slave Interface: eth1 

MII Status: up  

Link Failure Count: 0  

Permanent HW addr: 00:0c:29:6e:40:a7   

 如果这时把eth0连接的网线拔掉,eth1会接替变成active   

Currently Active Slave: eth0  

 Slave Interface: eth0 

MII Status: down   

Slave Interface: eth1 

 MII Status: up   

表明bonding的模式1,是一种主备HA的模式。 

Ethernet Channel Bonding Driver: v2.6.3-rh (June 8, 2005) 

 

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 

Link Failure Count: 0 

Permanent HW addr: 00:0c:29:6e:40:9d 

 

Slave Interface: eth1 

MII Status: up 

Link Failure Count: 0 

Permanent HW addr: 00:0c:29:6e:40:a7 

 

如果这时把

eth0

连接的网线拔掉,

eth1

会接替变成

active 

 

Currently Active Slave: eth0 

 

Slave Interface: eth0 

MII Status: down 

 

Slave Interface: eth1 

MII Status: up 

 

表明

bonding

的模式

1

,是一种主备

HA

的模式。

 

Ethernet Channel Bonding Driver: v2.6.3-rh (June 8, 2005) 

 

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 

Link Failure Count: 0 

Permanent HW addr: 00:0c:29:6e:40:9d 

 

Slave Interface: eth1 

MII Status: up 

Link Failure Count: 0 

Permanent HW addr: 00:0c:29:6e:40:a7 

 

如果这时把

eth0

连接的网线拔掉,

eth1

会接替变成

active 

 

Currently Active Slave: eth0 

 

Slave Interface: eth0 

MII Status: down 

 

Slave Interface: eth1 

MII Status: up 

 

表明

bonding

的模式

1

,是一种主备

HA

的模式。

 



  

   

原创粉丝点击