Linux雙網路卡負載均衡

byfree發表於2008-04-23

Linux雙網路卡負載均衡

[root@localhost ~]# uname -a
Linux localhost.localdomain 2.6.9-55.EL #1 Fri Apr 20 16:35:59 EDT 2007 i686 i686 i386 GNU/Linux
檢視linux是否支援bonding,如下資訊表示已支援
[root@localhost ~]# modinfo bonding
filename:       /lib/modules/2.6.9-55.EL/kernel/drivers/net/bonding/bonding.ko
parm:           max_bonds:Max number of bonded devices
parm:           miimon:Link check interval in milliseconds
parm:           updelay:Delay before considering link up, in milliseconds
parm:           downdelay:Delay before considering link down, in milliseconds
parm:           use_carrier:Use netif_carrier_ok (vs MII ioctls) in miimon; 0 for off, 1 for on (default)
parm:           mode:Mode of operation : 0 for round robin, 1 for active-backup, 2 for xor
parm:           primary:Primary network device to use
parm:           lacp_rate:LACPDU tx rate to request from 802.3ad partner (slow/fast)
parm:           xmit_hash_policy:XOR hashing method : 0 for layer 2 (default), 1 for layer 3+4
parm:           arp_interval:arp interval in milliseconds
parm:           arp_ip_target:arp targets in n.n.n.n form
license:        GPL
version:        2.6.3-rh BEB2ABDD4B642BA33CF1587
description:    Ethernet Channel Bonding Driver, v2.6.3-rh
author:         Thomas Davis, tadavis@lbl.gov and many others
vermagic:       2.6.9-55.EL 686 REGPARM 4KSTACKS gcc-3.4
depends:       

1.編輯虛擬網路介面配置檔案,指定網路卡IP
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost ~]# cp ifcfg-eth0 ifcfg-bond0
[root@localhost ~]# vi ifcfg-bond0 
DEVICE=bond0
BOOTPROTO=none
ONBOOT=yes
TYPE=Ethernet
NETMASK=255.255.255.0
IPADDR=192.168.1.30
USERCTL=no
IPV6INIT=no
PEERDNS=yes

[root@localhost network-scripts]# less ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
MASTER=bond0
SLAVE=yes

[root@localhost network-scripts]# less ifcfg-eth1
DEVICE=eth1
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes

2.編輯/etc/moprobe.conf檔案,加入如下一行內容,以使系統在啟動時載入bonding模組,對外虛擬網路介面裝置為 bond0
[root@localhost ~]# vi /etc/moprobe.conf
加入下列行
alias bond0 bonding
options bond0 miimon=100 mode=1

說明:miimon是用來進行鏈路監測的。 比如:miimon=100,那麼系統每100ms監測一次鏈路連線狀態,如果有一條線路不通就轉入另一條線路;mode的值表示工作模式,他共有0,1,2,3四種模式,常用的為0,1兩種。
mode=0表示load balancing (round-robin)為負載均衡方式,兩塊網路卡都工作。
mode=1表示fault-tolerance (active-backup)提供冗餘功能,工作方式是主備的工作方式,也就是說預設情況下只有一塊網路卡工作,另一塊做備份。
bonding只能提供鏈路監測,即從主機到交換機的鏈路是否接通。如果只是交換機對外的鏈路down掉了,而交換機本身並沒有故障,那麼bonding會認為鏈路沒有問題而繼續使用。

3.編輯/etc/rc.d/rc.local
[root@localhost ~]# vi /etc/rc.d/rc.local
加入
ifenslave bond0 eth0 eth1

重啟後我們用ifconfig檢視網路卡資訊,可以看到多出一個bond0網路卡
bond0     Link encap:Ethernet  HWaddr 00:1D:0F:14:7D:1A 
          inet addr:192.168.1.30  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::21d:fff:fe14:7d1a/64 Scope:Link
          UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1
          RX packets:4537 errors:0 dropped:0 overruns:0 frame.:0
          TX packets:482 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:472954 (461.8 KiB)  TX bytes:51396 (50.1 KiB)

eth0      Link encap:Ethernet  HWaddr 00:1D:0F:14:7D:1A 
          inet6 addr: fe80::21d:fff:fe14:7d1a/64 Scope:Link
          UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:2186 errors:0 dropped:0 overruns:0 frame.:0
          TX packets:220 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:227915 (222.5 KiB)  TX bytes:23294 (22.7 KiB)
          Interrupt:185 Base address:0xc000

eth1      Link encap:Ethernet  HWaddr 00:1D:0F:14:7D:1A 
          inet6 addr: fe80::21d:fff:fe14:7d1a/64 Scope:Link
          UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:2353 errors:0 dropped:0 overruns:0 frame.:0
          TX packets:270 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:245159 (239.4 KiB)  TX bytes:29194 (28.5 KiB)
          Interrupt:209 Base address:0xc400

此時網路卡已繫結成功!!

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/17997/viewspace-249070/,如需轉載,請註明出處,否則將追究法律責任。

相關文章