Bonding 可以把多张网卡汇聚成一张,可以提供负载平衡(load-balancing),容错(fault-tolerance)等功能。
Bonding 提供了下面几种模式,但要注意的是其中的 active-backup (mode=1),balance-tlb (mode=5) , balance-alb (mode=6) 是不需要 switch 特别支持设定的。但是其它模式 round-robin(mode=0), XOR(mode=2), broadcast(mode=3), 802.3ad policies(mode=4)则需要特别 switch 来支持.如果在设定 Bonding 时没有指定预设将会使用 mode 0 balance-rr(round-robin).
1.balance-rr or 0
假设将两张网络卡设成Balance时, 同时间Balance包含容错功能如果一张网卡故障另一张依然运作。
2.active-backup or 1
假设有两张网卡时一张是PRIMARY另一张是STANDBY 这时候流量只在PRIMARY上跑,当PRIMARY挂掉时STANDBY会自动启用接手变成PRIMARY ,如果原来PRIMARY恢复时会
自动变成STANDBY 。
至于下面几种模式我实在也搞不清楚,如果希望了解更详细的讯息,可以参考 ‘/usr/src/linux-[version]/Documentation/networking/bonding.txt。
3.balance-xor or 2
XOR policy: Transmit based on [(source MAC address XOR'd with destination MAC address) modula slave count]. This selects the same slave for each
destination MAC address. This mode provides load balancing and fault tolerance.
4.broadcast or 3
Broadcast policy: transmits everything on all slave interfaces. This mode provides fault tolerance.
5.802.3ad or 4 (Dynamic Link Aggregation)
假设将两张网络卡设成Dynamic Link Aggregation时 , 进来流量为200M出去流量为200M, 这时候需接往支持Dynamic Link Aggregation的交换器(switch),同时间
Dynamic Link Aggregation包含容错功能如果一张网卡故障另一张依然运作。
6.balance-tlb or 5(Transmit load balancing)
Adaptive transmit load balancing: channel bonding that does not require any special switch support. The outgoing traffic is distributed according
to the current load(computed relative to the speed) on each slave. Incoming traffic is received by the current slave. If the receiving slave
fails, another slave takes over the MAC address of the failed receiving slave.
进来流量为100M出去流量为200M
7.balance-alb or 6(Adaptive load balancing)
Adaptive load balancing: includes balance-tlb + receive load balancing (rlb) for IPV4 traffic and does not require any special switch support. The
receive load balancing is achieved by ARP negotiation. The bonding driver intercepts the ARP Replies sent by the server on their way out and
overwrites the src hw address with the unique hw address of one of the slaves in the bond such that different clients use different hw addresses
for the server.
进来流量为100M出去流量为200M
以下实例以eth1和eth2组成bonding:
一,各网卡的设置。
[root@localhost network-scripts]# more ifcfg-eth*
::::::::::::::
ifcfg-eth0
::::::::::::::
# Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet
DEVICE=eth0
BOOTPROTO=static
IPADDR=10.35.14.124
NETMASK=255.255.255.0
GATEWAY=10.35.14.254
ONBOOT=yes
::::::::::::::
ifcfg-eth1
::::::::::::::
# Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet
DEVICE=eth1
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
ONBOOT=yes
::::::::::::::
ifcfg-eth2
::::::::::::::
# Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet
DEVICE=eth2
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
ONBOOT=yes
[root@localhost network-scripts]# vi ifcfg-bond0
# Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet
DEVICE=bond0
BOOTPROTO=static
IPADDR=192.168.35.1
NETMASK=255.255.255.0
ONBOOT=yes
二,进行绑定:
[root@localhost network-scripts]# modprobe bonding miimon=100 mode=0
说明:miimon=100,miimon是指多久时间要检查网络一次,单位是ms(毫秒) ,这边的100,是100ms,即是0.1秒 ,
意思是假设其中有一条网络断线,会在0.1秒内自动备援。
mode=0 即balance-rr(round-robin). 这个模式主要是做负载平衡(load-balancing)。
[root@localhost network-scripts]# /etc/init.d/network restart
Shutting down interface bond0: [ OK ]
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface bond0: [ OK ]
Bringing up interface eth0: [ OK ]
三,设置好的状态:
[root@localhost network-scripts]# ifconfig
bond0 Link encap:Ethernet HWaddr 78:2B:CB:12:3B:B8
inet addr:192.168.35.1 Bcast:192.168.35.255 Mask:255.255.255.0
inet6 addr: fe80::7a2b:cbff:fe12:3bb8/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:137 errors:0 dropped:0 overruns:0 frame:0
TX packets:34 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:29346 (28.6 KiB) TX bytes:8938 (8.7 KiB)
eth0 Link encap:Ethernet HWaddr 78:2B:CB:12:3B:B6
inet addr:10.35.14.124 Bcast:10.35.14.255 Mask:255.255.255.0
inet6 addr: fe80::7a2b:cbff:fe12:3bb6/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:40 errors:0 dropped:0 overruns:0 frame:0
TX packets:43 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:5333 (5.2 KiB) TX bytes:11214 (10.9 KiB)
Interrupt:106 Memory:d6000000-d6012800
eth1 Link encap:Ethernet HWaddr 78:2B:CB:12:3B:B8
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:68 errors:0 dropped:0 overruns:0 frame:0
TX packets:18 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:14960 (14.6 KiB) TX bytes:4220 (4.1 KiB)
Interrupt:114 Memory:d8000000-d8012800
eth2 Link encap:Ethernet HWaddr 78:2B:CB:12:3B:B8
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:69 errors:0 dropped:0 overruns:0 frame:0
TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:14386 (14.0 KiB) TX bytes:4718 (4.6 KiB)
Interrupt:122 Memory:da000000-da012800
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:136 errors:0 dropped:0 overruns:0 frame:0
TX packets:136 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:20638 (20.1 KiB) TX bytes:20638 (20.1 KiB)
四,加入到modprobe里面:
[root@localhost network-scripts]# vi /etc/modprobe.conf
alias eth0 bnx2
alias eth1 bnx2
alias eth2 bnx2
alias eth3 bnx2
alias eth2 bnx2
alias bond0 bonding
options bond0 miimon=100 mode=0
[root@localhost ~]# modprobe -r bonding
[root@localhost ~]# modprobe bonding miimon=100 mode=4
[root@localhost ~]# /etc/init.d/network restart
Shutting down interface bond0: [ OK ]
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface bond0: [ OK ]
Bringing up interface eth0: [ OK ]
[root@localhost ~]# more /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.4.0 (October 7, 2008)
Bonding Mode: IEEE 802.3ad Dynamic link aggregation
Transmit Hash Policy: layer2 (0)
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
802.3ad info
LACP rate: slow
Active Aggregator Info:
Aggregator ID: 3
Number of ports: 1
Actor Key: 9
Partner Key: 1
Partner Mac Address: 00:00:00:00:00:00
Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: 78:2b:cb:12:3b:b8
Aggregator ID: 3
Slave Interface: eth2
MII Status: up
Link Failure Count: 0
Permanent HW addr: 78:2b:cb:12:3b:ba
Aggregator ID: 4