一定要在服务管理中关闭NetworkManager服务并禁用自动启动。

 

第一步:先查看下本机网卡,使用命令到network-scripts 

[root@root~]# cd /etc/sysconfig/network-scripts/

[root@root network-scripts~]#  ll    

total 202

-rw-r--r--1 root root   212 Mar 15 15:40 ifcfg-eth0

-rw-r--r--  1 root root   212 Mar 15 15:40 ifcfg-eth1

 

第二步:复制ifcfg-bond0或者自己创造一个都可以,下面我介绍复制的命令

[root@root network-scripts]# cp ifcfg-eth0 ifcfg-bond0

复制好了查看一下

[root@root network-scripts]# ll

total 204

-rw-r--r--  1 root root   212 Mar 23 15.42 ifcfg-bond0

-rw-r--r--1 root root   212 Mar 15 15:40 ifcfg-eth0

-rw-r--r--  1 root root   212 Mar 15 15:40 ifcfg-eth1

 

第三步:编辑ifcfg-bond0、ifcfg-eth0、ifcfg-eth1  把里面内容替换一下内容

[root@root network-scripts]# vim ifcfg-bond0    //(IP、MASK、子网掩码按自己服务器的需求来)

BOOTPROTO=none

DEVICE=bond0

ONBOOT=yes

IPADDR=172.26.5.16

NETMASK=255.255.255.128

GATEWAY=172.26.5.126

USERCTL=no

TYPE=Ethernet

IPV6INIT=no

DNS1=172.26.1.1

[root@root network-scripts]# vim ifcfg-eth0

BOOTPROTO=none

DEVICE=eth0

ONBOOT=yes

MASTER=bond0

SLAVE=yes

USERCTL=no

TYPE=Ethernet

IPV6INIT=no

 

[root@root network-scripts]# vim ifcfg-eth1

BOOTPROTO=none

DEVICE=eth1

ONBOOT=yes

MASTER=bond0

SLAVE=yes

USERCTL=no

TYPE=Ethernet

IPV6INIT=no

 

第四步:模块加载

[root@root ~]# cd /etc/modprobe.d/

切换到modprobe.d目录下

[root@root ~modprobe.d]#vi dist.conf

#加载bonding模块,对外虚拟网络接口设备为bond0,在最后加入以下2行

alias bond0 bonding

options bond0 mode=1 miimon=100

(备注本人试用mode=0,因为本人的交换机上做了双活)

说明:(这个是上网抄的,自己最好了解下)

miimon是用来进行链路监测的。比如:miimon=100,单位是ms(毫秒)这边的100,是100ms,即是0.1秒那么系统每100ms监测一次链路连接状态,如果有一条线路不通就转入另一条线路;mode的值表示工作模式,他共有0,1,2,3四种模式,常用的为0、1两种。

mode共有七种(0~6),这里解释两个常用的选项。

mode=0:表示load balancing (round-robin)为负载均衡方式,两块网卡都在工作。

mode=1:表示fault-tolerance (active-backup)提供冗余功能,工作方式是主备的工作方式,其中一块网卡在工作(若eth0断掉),则自动切换到另一个块网卡(eth1做备份)。

bonding只能提供链路监测,即从主机到交换机的链路是否接通。如果只是交换机对外的链路down掉了,而交换机本身并没有故障,那么bonding会认为链路没有问题而继续使用。

 

第六步:启动eth0eth1网卡(有的人可以不用做这一步,因为本人的服务器是刚刚装的,eth0eth1网卡都没有启动)

[root@root network-scripts]# ifconfig eth0 up

[root@root network-scripts]# ifconfig eth1 up

 

第七步:重启网络服务,使配置生效

[root@root network-scripts]# service network restart

Shutting down interface bond0:                              [正确]

Shutting down interface eth0:                             [正确]

Shutting down interface eth1:                             [正确]

Shutting down loopback interface:                           [正确]

Bringing up loopback interface:                           [正确]

Error adding address 10.1.3.210 for bond0.

RTNETLINK answers: File exists                             [正确]

 

第八步:验证是否双网卡绑定成功方法一:

[root@root network-scripts]#ifconfig   成功的话显示的内容是bond0em1em2网卡的MAC地址是一样的

方法二:

[root@root network-scripts]# cat /proc/net/bonding/bond0

Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)

Bonding Mode: fault-tolerance (active-backup)

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: em1

MII Status: up

Speed: 1000 Mbps

Duplex: full

Link Failure Count: 0

Permanent HW addr: 00:0c:29:c9:6d:18

Slave queue ID: 0

 

Slave Interface: em2

MII Status: up

Speed: 1000 Mbps

Duplex: full

Link Failure Count: 0

Permanent HW addr: 00:0c:29:c9:6d:22

Slave queue ID: 0