通常我们知道cisco交换机下的portchannl,但是现在需要主机两块网卡才能满足带宽需求呢,除了上端交换机的端口聚合。下面的linux该怎么做?
下面就来看看linux是怎么做端口聚合的。
1,
首先down掉要聚合的接口
[root@localhost ~]# ifconfig eth1 down
[root@localhost ~]# ifconfig eth2 down
2,加载bonding模块
[root@localhost ~]# modprobe bonding arp_interval=2 mode=802.3ad miimon=10 max_bonds=1 lacp_rate=1
查看一下模块加载情况
[root@localhost ~]# lsmod | grep bond
bonding 81197 0
查看一下刚刚聚合的端口,还没有UP。现在这个接口就相当于port-channl
[root@localhost ~]# ifconfig -a
bond0 Link encap:Ethernet HWaddr 00:00:00:00:00:00
BROADCAST MASTER MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
eth0 Link encap:Ethernet HWaddr 00:0C:29:05:EA:AF
inet addr:172.16.13.201 Bcast:172.16.255.255 Mask:255.255.0.0
inet6 addr: 2001:470:19:d8f:20c:29ff:fe05:eaaf/64 Scope:Global
inet6 addr: fe80::20c:29ff:fe05:eaaf/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:16882 errors:0 dropped:0 overruns:0 frame:0
TX packets:456 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1884640 (1.7 MiB) TX bytes:59896 (58.4 KiB)
Interrupt:67 Base address:0x2080
eth1 Link encap:Ethernet HWaddr 00:0C:29:05:EA:B9
inet addr:192.168.128.10 Bcast:192.168.128.255 Mask:255.255.255.0
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:23 errors:0 dropped:0 overruns:0 frame:0
TX packets:54 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:6483 (6.3 KiB) TX bytes:9416 (9.1 KiB)
Interrupt:59 Base address:0x2000
eth2 Link encap:Ethernet HWaddr 00:0C:29:05:EA:C3
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:24 errors:0 dropped:0 overruns:0 frame:0
TX packets:29 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:5039 (4.9 KiB) TX bytes:6883 (6.7 KiB)
Interrupt:75 Base address:0x2400
现在把需要聚合的端口加到bond0
[root@localhost ~]# ifenslave bond0 eth1 eth2
Illegal operation; the specified master interface 'bond0' is not up.
提示bond0没有UP,下面起来
[root@localhost ~]# ifconfig bond0 up
[root@localhost ~]# ifenslave bond0 eth1 eth2
现在看一下聚合的MAC地址已经相同了
bond0 Link encap:Ethernet HWaddr 00:0C:29:05:EA:B9
inet6 addr: fe80::20c:29ff:fe05:eab9/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:1046 errors:0 dropped:0 overruns:0 frame:0
TX packets:445 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:140014 (136.7 KiB) TX bytes:66061 (64.5 KiB)
eth0 Link encap:Ethernet HWaddr 00:0C:29:05:EA:AF
inet addr:172.16.13.201 Bcast:172.16.255.255 Mask:255.255.0.0
inet6 addr: 2001:470:19:d8f:20c:29ff:fe05:eaaf/64 Scope:Global
inet6 addr: fe80::20c:29ff:fe05:eaaf/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:20319 errors:0 dropped:0 overruns:0 frame:0
TX packets:565 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2272671 (2.1 MiB) TX bytes:76238 (74.4 KiB)
Interrupt:67 Base address:0x2080
eth1 Link encap:Ethernet HWaddr 00:0C:29:05:EA:B9
inet6 addr: fe80::20c:29ff:fe05:eab9/64 Scope:Link
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:524 errors:0 dropped:0 overruns:0 frame:0
TX packets:235 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:71437 (69.7 KiB) TX bytes:34216 (33.4 KiB)
Interrupt:59 Base address:0x2000
eth2 Link encap:Ethernet HWaddr 00:0C:29:05:EA:B9
inet6 addr: fe80::20c:29ff:fe05:eab9/64 Scope:Link
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:522 errors:0 dropped:0 overruns:0 frame:0
TX packets:210 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:68577 (66.9 KiB) TX bytes:31845 (31.0 KiB)
Interrupt:75 Base address:0x2400
下面给配上IP地址
[root@localhost ~]# ifconfig bond0 192.168.128.10 up
[root@localhost ~]# ifconfig
bond0 Link encap:Ethernet HWaddr 00:0C:29:05:EA:B9
inet addr:192.168.128.10 Bcast:192.168.128.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe05:eab9/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:249796 errors:0 dropped:0 overruns:0 frame:0
TX packets:87949 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:30670748 (29.2 MiB) TX bytes:10670595 (10.1 MiB)
eth0 Link encap:Ethernet HWaddr 00:0C:29:05:EA:AF
inet addr:172.16.13.201 Bcast:172.16.255.255 Mask:255.255.0.0
inet6 addr: 2001:470:19:d8f:20c:29ff:fe05:eaaf/64 Scope:Global
inet6 addr: fe80::20c:29ff:fe05:eaaf/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:189131 errors:5 dropped:333 overruns:0 frame:0
TX packets:3024 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:20977453 (20.0 MiB) TX bytes:659208 (643.7 KiB)
Interrupt:67 Base address:0x2080
eth1 Link encap:Ethernet HWaddr 00:0C:29:05:EA:B9
inet6 addr: fe80::20c:29ff:fe05:eab9/64 Scope:Link
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:130565 errors:0 dropped:0 overruns:0 frame:0
TX packets:47927 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:15877867 (15.1 MiB) TX bytes:5716962 (5.4 MiB) Interrupt:59 Base address:0x2000
eth2 Link encap:Ethernet HWaddr 00:0C:29:05:EA:B9
inet6 addr: fe80::20c:29ff:fe05:eab9/64 Scope:Link
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:119231 errors:0 dropped:0 overruns:0 frame:0
TX packets:40022 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:14792881 (14.1 MiB) TX bytes:4953633 (4.7 MiB)
Interrupt:75 Base address:0x2400
这里可以看见eth1 与eth2 流量做了分担
[root@localhost ~]# ping 192.168.128.1
PING 192.168.128.1 (192.168.128.1) 56(84) bytes of data.
64 bytes from 192.168.128.1: icmp_seq=1 ttl=64 time=0.699 ms
64 bytes from 192.168.128.1: icmp_seq=2 ttl=64 time=0.838 ms
64 bytes from 192.168.128.1: icmp_seq=3 ttl=64 time=0.395 ms
64 bytes from 192.168.128.1: icmp_seq=4 ttl=64 time=0.310 ms
以上配置过程可以通过dmesg可以查看到内核信息,或者在配置时使用tail –f /var/log/messages,可以快速判断问题