系統(tǒng)環(huán)境:
操作系統(tǒng): RedHat EL55
雙網(wǎng)卡綁定單個IP 地址為了提供網(wǎng)絡(luò)的高可用性,我們可能需要將多塊網(wǎng)卡綁定成一塊虛擬網(wǎng)卡對外提供服務(wù),這樣即使其中的一塊物理網(wǎng)卡出現(xiàn)故障,也不會導(dǎo)致連接中斷。
為了提供網(wǎng)絡(luò)的高可用性,我們可能需要將多塊網(wǎng)卡綁定成一塊虛擬網(wǎng)卡對外提供服務(wù),這樣即使其中的一塊物理網(wǎng)卡出現(xiàn)故障,也不會導(dǎo)致連接中斷。在Linux下叫bonding,IBM稱為etherchanel,broadcom叫team
1、查看內(nèi)核是否支持網(wǎng)卡綁定
[root@bjsrv ~]# modinfo bonding
filename: /lib/modules/2.6.18-194.el5xen/kernel/drivers/net/bonding/bonding.ko
author: Thomas Davis, tadavis@lbl.gov and many others
description: Ethernet Channel Bonding Driver, v3.4.0
version: 3.4.0
license: GPL
srcversion: A2FB5CCCDB38BE9A099CC9C
depends: ipv6
vermagic: 2.6.18-194.el5xen SMP mod_unload 686 REGPARM 4KSTACKS gcc-4.1
parm: max_bonds:Max number of bonded devices (int)
parm: num_grat_arp:Number of gratuitous ARP packets to send on failover event (int)
parm: num_unsol_na:Number of unsolicited IPv6 Neighbor Advertisements packets to send on failover event (int)
parm: miimon:Link check interval in milliseconds (int)
parm: updelay:Delay before considering link up, in milliseconds (int)
parm: downdelay:Delay before considering link down, in milliseconds (int)
parm: use_carrier:Use netif_carrier_ok (vs MII ioctls) in miimon; 0 for off, 1 for on (default) (int)
parm: mode:Mode of operation : 0 for balance-rr, 1 for active-backup, 2 for balance-xor, 3 for broadcast, 4 for 802.3ad, 5 for balance-tlb, 6 for balance-alb (charp)
parm: primary:Primary network device to use (charp)
parm: primary_reselect:Reselect primary slave once it comes up; 0 for always (default), 1 for only if speed of primary is better, 2 for only on active slave failure (charp)
parm: lacp_rate:LACPDU tx rate to request from 802.3ad partner (slow/fast) (charp)
parm: xmit_hash_policy:XOR hashing method: 0 for layer 2 (default), 1 for layer 3+4 (charp)
parm: arp_interval:arp interval in milliseconds (int)
parm: arp_ip_target:arp targets in n.n.n.n form (array of charp)
parm: arp_validate:validate src/dst of ARP probes: none (default), active, backup or all (charp)
parm: fail_over_mac:For active-backup, do not set all slaves to the same MAC. none (default), active or follow (charp)
parm: debug:Print debug messages; 0 for off (default), 1 for on (int)
module_sig: 883f3504ba03af81e1fa4939f6a629311282410a0c9263f8f3007023d923512d2ecbb7e81cefc609f41f79cd9bf13e480d0b17e94899d3c4408c6a6
[root@bjsrv ~]#
2、配置虛擬網(wǎng)卡
[root@bjsrv ~]# cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-bond0
[root@bjsrv ~]#
[root@bjsrv ~]# cat /etc/sysconfig/network-scripts/ifcfg-bond0
# Intel Corporation 82540EM Gigabit Ethernet Controller
DEVICE=bond0
BOOTPROTO=static
IPADDR=192.168.10.254
NETMASK=255.255.255.0
GATEWAY=192.168.10.1
ONBOOT=yes
[root@bjsrv ~]#
[root@bjsrv ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
# Intel Corporation 82540EM Gigabit Ethernet Controller
DEVICE=eth1
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
[root@bjsrv ~]#
[root@bjsrv ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth2
# Intel Corporation 82540EM Gigabit Ethernet Controller
DEVICE=eth2
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=none
[root@bjsrv ~]#
[root@bjsrv ~]# grep bond /etc/modprobe.d/modprobe.conf.dist
alias bond0 bonding
options bond0 miimon=100 mode=1
[root@bjsrv ~]# grep bond /etc/modprobe.conf
alias bond0 bonding
options bond0 miimon=100 mode=1
三、參數(shù)說明
options bond0 miimon=100 mode=1
如果達(dá)到負(fù)載均衡的目的,應(yīng)該是0,1是熱備狀態(tài)。
miimon是毫秒數(shù),每100毫秒觸發(fā)檢測線路穩(wěn)定性的事件。
mode= 是ifenslave的工作狀態(tài)。
一共有7種方式:
=0: (balance-rr) Round-robin policy: (平衡掄循環(huán)策略):傳輸數(shù)據(jù)包順序是依次傳輸,直到最后一個傳輸完畢,
此模式提供負(fù)載平衡和容錯能力,這需要設(shè)置交換機(jī)的配合才能完成。
=1: (active-backup) Active-backup policy:(主-備份策略):只有一個設(shè)備處于活動狀態(tài)。
一個宕掉另一個馬上由備份轉(zhuǎn)換為主設(shè)備。mac地址是外部可見得。 此模式提供了容錯能力。
=2:(balance-xor) XOR policy:(廣播策略):將所有數(shù)據(jù)包傳輸給所有接口。 此模式提供了容錯能力。
=3:(balance-xor) XOR policy: (平衡 策略): 傳輸根據(jù)原地址布爾值選擇傳輸設(shè)備。
此模式提供負(fù)載平衡和容錯能力。
=4:(802.3ad) IEEE 802.3ad Dynamic link aggregation.
IEEE 802.3ad 動態(tài)鏈接聚合:創(chuàng)建共享相同的速度和雙工設(shè)置的聚合組。
=5:(balance-tlb) Adaptive transmit load balancing(適配器傳輸負(fù)載均衡)
:沒有特殊策略,第一個設(shè)備傳不通就用另一個設(shè)備接管第一個設(shè)備正在處理的mac地址,幫助上一個傳。
=6:(balance-alb) Adaptive load balancing: (適配器傳輸負(fù)載均衡):大致意思是包括mode5,bonding驅(qū)動程序截獲 ARP 在本地系統(tǒng)發(fā)送出的請求,用其中之一的硬件地址覆蓋從屬設(shè)備的原地址。就像是在服務(wù)器上不同的人使用不同的硬件地址一樣。
四、重新啟動網(wǎng)絡(luò)服務(wù)
[root@bjsrv ~]#service 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 ]
五、查看虛擬網(wǎng)卡信息
[root@bjsrv ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.4.0 (October 7, 2008)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth1
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: 08:00:27:99:ce:df
Slave Interface: eth2
MII Status: up
Link Failure Count: 0
Permanent HW addr: 08:00:27:ce:7a:4d
[root@bjsrv ~]#
[root@bjsrv ~]# netstat -nr
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
192.168.10.0 0.0.0.0 255.255.255.0 U 0 0 0 bond0
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
192.168.8.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 192.168.10.1 0.0.0.0 UG 0 0 0 bond0
[root@bjsrv ~]#
六、down 掉主網(wǎng)卡測試
在測試中,主網(wǎng)卡down 后,會有連接超時,但會立刻聯(lián)通備份網(wǎng)卡!
查看虛擬網(wǎng)卡狀態(tài):
[root@bjsrv ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.4.0 (October 7, 2008)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth2
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth1
MII Status: down
Link Failure Count: 1
Permanent HW addr: 08:00:27:99:ce:df
Slave Interface: eth2
MII Status: up
Link Failure Count: 0
Permanent HW addr: 08:00:27:ce:7a:4d
[root@bjsrv ~]#
下一篇:AIX常用命令