如何在Redhat 5.4下配置双网卡绑定实现网卡流量负载均衡

在没有写博客之前,我已经把redhat双网卡绑定的配置方法,共享到百度文库,不过我觉得还是有必要再我的博客上分享出来。本文主要讲述在redhat下配置双网卡绑定
检查linux配置上是否支持bonding:
[root@liujing ~]# cat /boot/config-2.6.32-220.el6.x86_64 |grep -i bonding
CONFIG_BONDING=m
返回CONFIG_BONDING=m表示支持,否则需要编译内核使它支持bonding

第一步:创建一个ifcfg-bondX
# vi/etc/sysconfig/network-scripts/ifcfg-bond0 新建一个bond0配置文件,在文件中添加如下信息。
DEVICE=bond0
BOOTPROTO=static
IPADDR=1.1.1.2 //给bond0接口配置ip,掩码和网关等基本信息。
NETMASK=255.255.255.0
BROADCAST=1.1.1.255
NETWORK=1.1.1.0
GATEWAY=1.1.1.1
ONBOOT=yes
TYPE=Ethernet
第二步:修改/etc/sysconfig/network-scripts/ifcfg-ethX
这个实验中把网卡1和2绑定,修改/etc/sysconfig/network-scripts/ifcfg-ethX相应网卡配置如下:
# cat /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
MASTER=bond0 //主接口为bond0
SLAVE=yes //设置成从接口
# cat /etc/sysconfig/network-scripts/ifcfg-eth2
DEVICE=eth2
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
MASTER=bond0
SLAVE=yes
第三步:配置/etc/modprobe.conf,添加alias bond0 bonding
# cat /etc/modprobe.conf
alias eth0 e100
alias snd-card-0 snd-intel8x0
options snd-card-0 index=0
options snd-intel8x0 index=0
remove snd-intel8x0 { /usr/sbin/alsactl store 0 >/dev/null 2>&1 || : ; }; /sbin/modprobe -r --ignore-remove snd-intel8x0
alias eth1 8139too
options 3c501 irq=3
alias eth2 tulip
上面是三网卡本身的配置如果要绑定和做lacp只要再加上下面两条配置
alias bond0 bonding 绑定 //给bond0接口设置别名
options bond0 miimon=100 mode=4 //配置绑定模式为 mode=4是lacp
第四步:配置/etc/rc.d/rc.local,添加需要绑定的网卡
# cat /etc/rc.d/rc.local
touch /var/lock/subsys/local 配置本身就有这条命令
ifenslave bond0 eth1 eth2 这条命令是添加需要绑定的网卡1和2
到这里就完成bonding的配置了。
第五步:重启网络服务和重启pc
#service network restart 重启网络服务
# shutdown -r now 重启pc
重启后可以查看bonding情况:网卡1和2 都绑定上了,模式为802.3ad
# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.0.3 (March 23, 2006)
Bonding Mode: IEEE 802.3ad Dynamic link aggregation //可以看到绑定配置成功,模式为LACP
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: 1
Number of ports: 2
Actor Key: 9
Partner Key: 1
Partner Mac Address: 00:d0:f8:22:33:ba
Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:d0:f8:40:f1:a0
Aggregator ID: 1
Slave Interface: eth2
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:d0:f8:00:0c:0c
Aggregator ID: 1
接口配置信息:新增了bond0的配置信息,接口bond0和eth1,eth2,绑定后三个接口使用的mac都是同一个:00:D0:F8:40:F1:A0
# ifconfig
bond0 Link encap:Ethernet HWaddr 00:D0:F8:40:F1:A0
inet addr:1.1.1.2 Bcast:1.1.1.255 Mask:255.255.255.0
inet6 addr: fe80::2d0:f8ff:fe40:f1a0/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:128 errors:0 dropped:0 overruns:0 frame:0
TX packets:259 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:15466 (15.1 KiB) TX bytes:39679 (38.7 KiB)
eth0 Link encap:Ethernet HWaddr 00:11:11:EB:71:E2
inet addr:192.168.180.8 Bcast:192.168.180.15 Mask:255.255.255.240
inet6 addr: fe80::211:11ff:feeb:71e2/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:311 errors:0 dropped:0 overruns:0 frame:0
TX packets:228 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:30565 (29.8 KiB) TX bytes:35958 (35.1 KiB)
eth1 Link encap:Ethernet HWaddr 00:D0:F8:40:F1:A0
inet6 addr: fe80::2d0:f8ff:fe40:f1a0/64 Scope:Link
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:54 errors:0 dropped:0 overruns:0 frame:0
TX packets:97 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:6696 (6.5 KiB) TX bytes:13821 (13.4 KiB)
Interrupt:209 Base address:0x2e00
eth2 Link encap:Ethernet HWaddr 00:D0:F8:40:F1:A0
inet6 addr: fe80::2d0:f8ff:fe40:f1a0/64 Scope:Link
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:74 errors:0 dropped:0 overruns:0 frame:0
TX packets:162 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:8770 (8.5 KiB) TX bytes:25858 (25.2 KiB)
Interrupt:201 Base address:0x2f00
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:6283 errors:0 dropped:0 overruns:0 frame:0
TX packets:6283 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:9783674 (9.3 MiB) TX bytes:9783674 (9.3 MiB)
这个模式需要交换机上也开启lacp功能:
交换机配置:
interface GigabitEthernet 0/23
no switchport
port-group 1 mode active 接口下开启lacp 主动模式
!
interface GigabitEthernet 0/24
no switchport
port-group 1 mode active
!
interface AggregatePort 1
no switchport
no ip proxy-arp
ip address 1.1.1.1 255.255.255.0
和linux成功建立lacp后状态信息如下,在交换机端查看,lacp的状态。
Show lacp summary
System Id:100, 00d0.f822.33ba
Flags: S - Device is requesting Slow LACPDUs F - Device is requesting Fast LACPDUs.
A - Device is in active mode. P - Device is in passive mode.
Aggregate port 1:
Local information:
LACP port Oper Port Port
Port Flags State Priority Key Number State
----------------------------------------------------------------------
Gi0/23 SA bndl 100 0x1 0x17 0x3d
Gi0/24 SA bndl 100 0x1 0x18 0x3d
Partner information:
LACP port Oper Port Port
Port Flags Priority Dev ID Key Number State
---------------------------------------------------------------------
Gi0/23 SA 255 00d0.f840.f1a0 0x9 0x2 0x3d
Gi0/24 SA 255 00d0.f840.f1a0 0x9 0x1 0x3d
State表示状态信息:bndl表示lacp建立成功,sup表示不成功。
到这里LINUX redhat 5.4版本的双网卡绑定就完成配置了。

weinxin
DC Farm小程序二维码
扫一扫添加博客小程序
Jim

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

目前评论:5   其中:访客  4   博主  1

    • avatar 行畔博客 3

      唔,好专业。那支持一个

      • avatar 小儿脑瘫治疗 0

        哇,真专业,我看到莫名其妙了。还是蚂蚁爬!!

        • avatar 必须滴 0

          欢迎常来~~必须滴!

          • avatar FeemyseskFows 0

            The war in Iraq has meant that many insurgents have fled the country and gone over to Afghanistan, which, according to the Afghan defense minister, accounts for the recent spike in violent incidents in Afghanistan.
            This article is in regards to the motorway police pakistan. You can find more resources about the Pakistan Motorway Police on maybenow.com Really Bad Credit Credit Card- News
            zetaclear reviews