您的当前位置:首页正文

在linu下双网卡负载均衡(lacp)

2020-01-26 来源:步旅网
(一) linux 配置

#cat

/boot/config-kernel-version |grep -i bonding

CONFIG_BONDING=m

返回

CONFIG_BONDING表示支持,否则需要编译内核使它支持

也可以用:查看一下内核是否已经支持

第一步:创建一个 ifcfg-bondX

#

touch

/etc/sysconfig/network-scripts/ifcfg-bond0 新建一个 bond0

配 置文件

# cat

/etc/sysconfig/network-scripts/ifcfg-bond0 DEVICE=bond0 BOOTPROTO=static IPADDR=1.1.1.2 NETMASK=255.255.255.0

BROADCAST=1.1.1.255

NETWORK=1.1.1.0 GATEWAY=1.1.1.1 ONBOOT=yes TYPE=Ethernet 编辑 ifcfg-bond0 如上

第二步:修改 /etc/sysconfig/

bonding :bonding

modinfo bonding

network-scripts/ifcfg-ethX 这个实

验中把网卡 1 和 2 绑定,修改

/etc/sysconfig/network-scripts/ifcfg-ethX 相

应网卡配置 如下:

# cat

/etc/sysconfig/network-scripts/ifcfg-eth1 TYPE=Ethernet DEVICE=eth1 HWADDR=00:d0:f8:40:f1:a0 网卡 1mac BOOTPROTO=none ONBOOT=yes

USERCTL=no MASTER=bond0 SLAVE=yes

# cat /etc/sysconfig/network-scripts/ifcfg-eth2 TYPE=Ethernet DEVICE=eth2 HWADDR=00:d0:f8:00:0c:0c 网卡 2mac BOOTPROTO=none ONBOOT=yes USERCTL=no MASTER=bond0 SLAVE=yes

第三步: 配置/etc/modprobe.conf ,添加 alias bondO bonding

# cat /etc/modprobe.conf alias ethO e1OO alias snd-card-O snd-intel8xO

options snd-card-O index=O options snd-intel8xO index=O -r remove snd-intel8xO { /usr/sbin/alsactl store O >/dev/null 2>&1 || : ; }; /sbin/modprobe --ignore-remove snd-intel8xO

alias eth1 8139too options 3c5O1 irq=3 alias eth2 tulip 上面是三网卡本身的配置

lacp 只要再加上下面两条配

如果要绑定和做 alias bondO bonding

置 绑定 mode=4 是 lacp

options bondO miimon=1OO mode=4

第四步:配置 /etc/rc.d/rc.local ,添加需要绑定的网卡

# cat /etc/rc.d/rc.local

touch /var/lock/subsys/local 配置本身就有这条命令

ifenslave bondO eth1 eth2 这条命令是添加需要绑定的网卡 1 和 2

到这里就完成 bonding 的配置了可以查看一下 第五步:重启网络服务和重启#service network restart

重启网络服务

# shutdown -r now

重启 pc

重启后可以查看 bonding 情况:网卡 1 和 2 都绑定上了,模式为 8O2.3ad

# cat /proc/net/bonding/bondO

Ethernet Channel Bonding Driver: v3.O.3 (March 23, 2OO6) Bonding Mode: IEEE 8O2.3ad Dynamic link aggregation Transmit Hash Policy: layer2 (O) MII Status: up

MII Polling Interval (ms): 1OO Up Delay (ms): O Down Delay (ms): O

8O2.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

pc

Link Failure Count: 0

Permanent HW addr: 00:d0:f8:00:0c:0c Aggregator ID: 1

接口配置信息:新增了 bond0的配置信息,接口 bondO和ethl , eth2,绑定后三个接口使用 的 mac 都是同一个: 00:D0:F8:40:F1:A0

# ifconfig

bondO Link encap:Ethernet HWaddr OO:DO:F8:4O:F1:AO

inet addr:1.1.1.2 Bcast:1.1.1.255 Mask:255.255.255.O inet6 addr: fe8O::2dO:f8ff:fe4O:f1aO/64 Scope:Link

UP BROADCAST RUNNING MASTER MULTICASTMTU:15OO Metric:1 RX packets:128 errors:O dropped:O overruns:O frame:O TX packets:259 errors:O dropped:O overruns:O carrier:O collisions:O txqueuelen:O

RX bytes:15466 (15.1 KiB) TX bytes:39679 (38.7 KiB)

ethO Link encap:Ethernet HWaddr OO:11:11:EB:71:E2

inet addr:192.168.18O.8 Bcast:192.168.18O.15 Mask:255.255.255.24O inet6 addr: fe8O::211:11ff:feeb:71e2/64 Scope:Link UP BROADCAST RUNNING MULTICASTMTU:15OO Metric:1 RX packets:311 errors:O dropped:O overruns:O frame:O TX packets:228 errors:O dropped:O overruns:O carrier:O collisions:O txqueuelen:1OOO

RX bytes:3O565 (29.8 KiB) TX bytes:35958 (35.1 KiB)

eth1

Link encap:Ethernet HWaddr OO:DO:F8:4O:F1:AO inet6 addr: fe8O::2dO:f8ff:fe4O:f1aO/64 Scope:Link

UP BROADCAST RUNNING SLAVE MULTICASMTTU: 1 5OO Metric:1 RX packets:54 errors:O dropped:O overruns:O frame:O TX packets:97 errors:O dropped:O overruns:O carrier:O collisions:O txqueuelen:1OOO

RX bytes:6696 (6.5 KiB) TX bytes:13821 (13.4 KiB) Interrupt:2O9 Base address:Ox2eOO

eth2 Link encap:Ethernet HWaddr OO:DO:F8:4O:F1:AO inet6 addr: fe8O::f8ff:fe4O:f1aO/64 Scope:Link

UP BROADCAST RUNNING SLAVE MULTICASMTTU: 1 5OO Metric:1 RX packets:74 errors:O dropped:O overruns:O frame:O TX packets:162 errors:O dropped:O overruns:O carrier:O

2dO:

collisions:O txqueuelen:1OOO

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 system-priority 100 interface GigabitEthernet 0/23 no switchport lacp port-priority 100 port-group 1 mode active interface GigabitEthernet 0/24 no switchport lacp port-priority 100 port-group 1 mode active interface AggregatePort 1

全局配置 lacp 优先级

接口的 lacp 优先级 接口下开启 lacp 主动模式

二)锐捷交换机配置:

no switchport no ip proxy-arp

ip address 1.1.1.1 255.255.255.0

和 linux 成功建立 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 Priority

Port Gi0/23 Gi0/24

Oper Key Port Port

Number State

Flags SA SA

State bndl bndl LACP port

100 100

0x1 0x1

0x17 0x18

0x3d 0x3d Port State 0x3d 0x3d

Partner information:

Flags SA

Priority 255

Dev ID 00d0.f840.f1a0

Oper Port Key Number

Port Gi0/23

0x9 0x2

Gi0/24 SA 255 00d0.f840.f1a0 0x9 0x1

State 表示状态信息: bndl 表示 lacp 建立成功, sup 表示不成功。

建立成功后在交换机上去 ping linux 1.1.1.2

Ruijie#ping 1.1.1.2

Sending 5, 100-byte ICMP Echoes to 1.1.1.2, timeout is 2 seconds:

< press Ctrl+C to break > !!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms 在 linux 上 ping 交换机 [root@localhost ~]# ping 1.1.1.1

PING 1.1.1.1 (1.1.1.1) 56(84) bytes of data.

64 bytes from 1.1.1.1: icmp_seq=1 ttl=64 time=0.601 ms 64 bytes from 1.1.1.1: icmp_seq=2 ttl=64 time=0.606 ms 64 bytes from 1.1.1.1: icmp_seq=3 ttl=64 time=0.608 ms 64 bytes from 1.1.1.1: icmp_seq=4 ttl=64 time=0.607 ms --- 1.1.1.1 ping statistics --

4 packets transmitted, 4 received, 0% packet loss, time 3002ms rtt min/avg/max/mdev = 0.601/0.605/0.608/0.024 ms [root@localhost ~]#

可以 ping 通, lacp 建立正常。

把原传输数据的那个网卡 shut down 异常测试时, 需要等到 lacp 状态超时才能切换到另一条 链路。

Ruijie#sh 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. Aggregate port 1: Local information:

LACP port Priority 100 100

Oper Key

0x1 0x1

Port

State

Number

0x17 0x18

Port

P - Device is in passive mode.

Port Flags State sups bndl LACP port Priority

Gi0/23 SA Gi0/24 SA

Partner information:

0x45

0x3d Port State

Oper Port Key Number

Dev ID

Port Gi0/23

Gi0/24

Flags SP SA

0 255

0000.0000.0000 00d0.f840.f1a0 0x0 0x9 0x0 0x1 0x0 0x3d

因篇幅问题不能全部显示,请点此查看更多更全内容