linux 下綁定雙網卡
系統環境:
作業系統: RedHat EL55
<a href="http://s3.51cto.com/wyfs02/M02/23/90/wKiom1M6fhKwdgYLAAA4kMgRAJE381.jpg" target="_blank"></a>
雙網卡綁定單個IP 位址為了提供網絡的高可用性,我們可能需要将多塊網卡綁定成一塊虛拟網卡對外提供服務,這樣即使其中的一塊實體網卡出現故障,也不會導緻連接配接中斷。
為了提供網絡的高可用性,我們可能需要将多塊網卡綁定成一塊虛拟網卡對外提供服務,這樣即使其中的一塊實體網卡出現故障,也不會導緻連接配接中斷。在Linux下叫bonding,IBM稱為etherchanel,broadcom叫team
1、檢視核心是否支援網卡綁定
[root@bjsrv ~]# modinfo bonding
filename: /lib/modules/2.6.18-194.el5xen/kernel/drivers/net/bonding/bonding.ko
author: Thomas Davis, [email protected] 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、配置虛拟網卡
[root@bjsrv ~]# cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-bond0
[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 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
[root@bjsrv ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth2
DEVICE=eth2
SLAVE=none
[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
三、參數說明
如果達到負載均衡的目的,應該是0,1是熱備狀态。
miimon是毫秒數,每100毫秒觸發檢測線路穩定性的事件。
mode= 是ifenslave的工作狀态。
一共有7種方式:
=0: (balance-rr) Round-robin policy: (平衡掄循環政策):傳輸資料包順序是依次傳輸,直到最後一個傳輸完畢,
此模式提供負載平衡和容錯能力,這需要設定交換機的配合才能完成。
=1: (active-backup) Active-backup policy:(主-備份政策):隻有一個裝置處于活動狀态。
一個宕掉另一個馬上由備份轉換為主裝置。mac位址是外部可見得。 此模式提供了容錯能力。
=2:(balance-xor) XOR policy:(廣播政策):将所有資料包傳輸給所有接口。 此模式提供了容錯能力。
=3:(balance-xor) XOR policy: (平衡 政策): 傳輸根據原位址布爾值選擇傳輸裝置。
此模式提供負載平衡和容錯能力。
=4:(802.3ad) IEEE 802.3ad Dynamic link aggregation.
IEEE 802.3ad 動态連結聚合:建立共享相同的速度和雙工設定的聚合組。
=5:(balance-tlb) Adaptive transmit load balancing(擴充卡傳輸負載均衡)
:沒有特殊政策,第一個裝置傳不通就用另一個裝置接管第一個裝置正在處理的mac位址,幫助上一個傳。
=6:(balance-alb) Adaptive load balancing: (擴充卡傳輸負載均衡):大緻意思是包括mode5,bonding驅動程式截獲 ARP 在本地系統發送出的請求,用其中之一的硬體位址覆寫從屬裝置的原位址。就像是在伺服器上不同的人使用不同的硬體位址一樣。
四、重新啟動網絡服務
[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 ]
五、檢視虛拟網卡資訊
[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
Link Failure Count: 0
Permanent HW addr: 08:00:27:99:ce:df
Slave Interface: eth2
Permanent HW addr: 08:00:27:ce:7a:4d
[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
六、down 掉主網卡測試
在測試中,主網卡down 後,會有連接配接逾時,但會立刻聯通備份網卡!
檢視虛拟網卡狀态:
Currently Active Slave: eth2
MII Status: down
Link Failure Count: 1
本文轉自 客居天涯 51CTO部落格,原文連結:http://blog.51cto.com/tiany/1388453,如需轉載請自行聯系原作者