最新消息:

Linux网口绑定

未分类 admin 3465浏览 0评论

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

前提约定:
2个物理网口分别是:eth0,eth1
绑定后的虚拟口是:bond0
服务器IP是:192.168.0.100

第一步,配置设定文件:
/etc/sysconfig/network-scripts/ifcfg-bond0

DEVICE=bond0
BOOTPROTO=none
ONBOOT=yes
IPADDR=192.168.0.100
NETMASK=255.255.255.0
NETWORK=192.168.0.0
BROADCAST=192.168.0.255

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

DEVICE=eth0
BOOTPROTO=none
MASTER=bond0
SLAVE=yes

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

DEVICE=eth1
BOOTPROTO=none
MASTER=bond0
SLAVE=yes

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

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

[root@aikaiyuan ~]# vi /etc/modprobe.d/bonding.conf
#追加
alias bond0 bonding
options bonding mode=1 miimon=200

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

[root@aikaiyuan ~]# modprobe bonding

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

[root@aikaiyuan ~]# lsmod | grep bonding
bonding               100065  0

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

[root@aikaiyuan ~]# /etc/init.d/network restart
[root@aikaiyuan ~]# 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
MII Status: up
MII Polling Interval (ms): 200
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth0
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:16:36:1b:bb:74

Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:16:36:1b:bb:80
[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的物理地址相同,这样是为了避免上位交换机发生混乱。

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

留心:前面只是2个网口绑定成一个bond0的情况,如果我们要设置多个bond口,比如物理网口eth0和eth1组成bond0,eth2和eth3组成bond1,
那么网口设置文件的设置方法和上面第1步讲的方法相同,只是/etc/modprobe.d/bonding.conf的设定就不能像下面这样简单的叠加了:

Linux bond 网卡模式

转载请注明:爱开源 » Linux网口绑定

您必须 登录 才能发表评论!