将两张网卡绑定,共用一个IP,实现冗余效果。实际上linux双网卡的绑定模式有7种: - mode=0 表示 load balancing (round-robin)为负载均衡方式,两块网卡都工作。
- mode=1 表示 fault-tolerance (active-backup)提供冗余功能,工作方式是主 从的工作方式,也就是说默认情况下只有一块网卡工作,另一块做备份。
- mode=2 表示 XOR policy 为平衡策略。此模式提供负载平衡和容错能力
- mode=3 表示 broadcast 为广播策略。此模式提供了容错能力
- mode=4 表示 IEEE 802.3ad Dynamic link aggregation 为 IEEE 802.3ad 为 动态链接聚合。该策略可以通过 xmit_hash_policy 选项从缺省的 XOR 策略改变到其他策略。
- mode=5 表示 Adaptive transmit load balancing 为适配器传输负载均衡。该 模式的必要条件:ethtool 支持获取每个 slave 的速率
- mode=6 表示 Adaptive load balancing 为适配器适应性负载均衡。该模式包含 了 balance-tlb 模式,同时加上针对 IPV4 流量的接收负载均衡(receive load balance, rlb),而且不需要任何 switch(交换机)的支持。
Centos 双网卡实现负载均衡。
- 新建/etc/sysconfig/network-scripts/ifcfg-bond0文件,vi ifcfg-bond0
1
2
3
4
5
6
7
| DEVICE=bond0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.0.23
NETMASK=255.255.255.224
GATEWAY=192.168.128.233
USERCTL=no
|
2.更改/etc/sysconfig/network-scripts/ifcfg-eth0网卡属性,vi ifcfg-eth0
1
2
3
4
5
| DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
MASTER=bond0
USERCTL=no
|
3.更改/etc/sysconfig/network-scripts/ifcfg-eth1网卡的属性,vi ifcfg-eth1
1
2
3
4
5
| DEVICE=eth1
ONBOOT=yes
BOOTPROTO=none
MASTER=bond0
USERCTL=no
|
4.编辑/etc/modprobe.conf文件,加入以下内容,vi modprobe.conf
1
2
| alias bond0 bonding
options bond0 miimon=100 mode=0
|
Esc退出编辑,:qw! 退出保存。
Ubuntu 双网卡实现负载均衡。
1
| apt-get install ifenslave
|
2.加载模块及配置负载,vi /etc/modules
1
2
| bonding mode=0 miimon=100
#miimon是10ms监测一次网卡状态
|
3.编辑接口,vi /etc/network/interfaces
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# This file describes the network interfaces available on your system# and how to activate them. For more information, see interfaces(5).
# The loopback network interfaceauto lo
iface lo inet loopback
#注释掉原来的eth0,eth1配置
# The primary network interface
#auto eth0
#iface eth0 inet dhcp
#auto eth1
#iface eth1 inet dhcp
#这里配置模式为轮询策略,模式代号是0,轮询间隔100ms(毫秒)。
up ifenslave bond0 eth0 eth1
down ifenslave bond0 -d eth0 eth1
bond-mode 0
bond-miimon 100
#配置bond的IPauto bond0
iface bond0 inet staticaddress 192.168.0.201
netmask 255.255.255.0
gateway 192.168.0.1
#配置bond的虚拟IP(非必须)auto bond0:1
iface bond0:1 inet staticaddress 192.168.1.201
netmask 255.255.255.0
gateway 192.168.1.1
|
3、加载bonding模块,sudo vi /etc/modules
4、重启计算机,如果成功,bond0、eth0、eth1的MAC地址均会变成原来eth0的MAC。
5、查看bonding状态
1
| cat /proc/net/bonding/bond0
|
|