Linux双网卡负载均衡(转)

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.govand 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/7201003/viewspace-269195/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/7201003/viewspace-269195/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值