Linux網路卡繫結實現頻寬翻倍

sundog315發表於2012-03-28

之前有過一篇BLOG,是介紹如何簡單的將Linux兩張網路卡進行繫結,已實現高可用。但在之前的模式裡,僅僅能實現高可用,當兩個網路卡中的一個失效時並不會影響伺服器的聯通性。

但是,如果有交換機的配合,是否可以時間負載均衡,同時達到頻寬翻倍的目的呢?

首先,需要先明確,繫結的各種模式

0 - Sets a round-robin policy for fault tolerance and load balancing. Transmissions are received and sent out sequentially on each bonded slave interface beginning with the first one available.

1 - Sets an active-backup policy for fault tolerance. Transmissions are received and sent out via the first available bonded slave interface. Another bonded slave interface is only used if the active bonded slave interface fails.

2 - Sets an XOR (exclusive-or) policy for fault tolerance and load balancing. Using this method, the interface matches up the incoming request's MAC address with the MAC address for one of the slave NICs. Once this link is established, transmissions are sent out sequentially beginning with the first available interface.

3 - Sets a broadcast policy for fault tolerance. All transmissions are sent on all slave interfaces.

4 - Sets an IEEE 802.3ad dynamic link aggregation policy. Creates aggregation groups that share the same speed and duplex settings. Transmits and receives on all slaves in the active aggregator. Requires a switch that is 802.3ad compliant.

5 - Sets a Transmit Load Balancing (TLB) policy for fault tolerance and load balancing. The outgoing traffic is distributed according to the current load on each slave interface. Incoming traffic is received by the current slave. If the receiving slave fails, another slave takes over the MAC address of the failed slave.

6 - Sets an Active Load Balancing (ALB) policy for fault tolerance and load balancing. Includes transmit and receive load balancing for IPV4 traffic. Receive load balancing is achieved through ARP negotiation.

需要注意的是MODE 0僅僅能實現網路卡輪詢,但同一時間只有一個網路卡生效,總體頻寬還是1個網路卡的頻寬。

這裡,我們需要開啟交換機的802.3ad,並設定mode=4來實現頻寬增倍

具體測試方法參見:

http://sundog315.itpub.net/post/308/525631

注意,在上面這個BLOG裡的mode需要改一下:

vi /etc/modprobe.conf

alias bond0 bonding
options bond0 miimon=100 mode=4 lacp_rate=1

我們用iperf工具來測試頻寬,由於mode 4模式使用mac地址分配那個網路卡參與工作,因此,需要多臺測試機進行測試

10.199.81.39作為server,10.199.81.40及10.199.81.42作為client,如果兩個client均能達到1000Mbits,那也就意味著頻寬是翻倍了。

server:

# iperf -s -w 1M
------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 2.00 MByte (WARNING: requested 1.00 MByte)
------------------------------------------------------------
[ 4] local 10.199.81.39 port 5001 connected with 10.199.81.40 port 9951
[ 5] local 10.199.81.39 port 5001 connected with 10.199.81.42 port 61211
[ ID] Interval Transfer Bandwidth
[ 4] 0.0-100.0 sec 11.1 GBytes 949 Mbits/sec
[ 5] 0.0-100.0 sec 11.1 GBytes 949 Mbits/sec

達到了頻寬翻倍的目的

[@more@]

# iperf -c 10.199.81.39 -w 1M -t 100 -i 2
------------------------------------------------------------
Client connecting to 10.199.81.39, TCP port 5001
TCP window size: 2.00 MByte (WARNING: requested 1.00 MByte)
------------------------------------------------------------
[ 3] local 10.199.81.40 port 9951 connected with 10.199.81.39 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0- 2.0 sec 228 MBytes 956 Mbits/sec
[ 3] 2.0- 4.0 sec 226 MBytes 949 Mbits/sec
[ 3] 4.0- 6.0 sec 226 MBytes 948 Mbits/sec
[ 3] 6.0- 8.0 sec 227 MBytes 952 Mbits/sec
[ 3] 8.0-10.0 sec 226 MBytes 948 Mbits/sec
[ 3] 10.0-12.0 sec 226 MBytes 949 Mbits/sec
[ 3] 12.0-14.0 sec 226 MBytes 948 Mbits/sec
[ 3] 14.0-16.0 sec 226 MBytes 948 Mbits/sec
[ 3] 16.0-18.0 sec 227 MBytes 952 Mbits/sec
[ 3] 18.0-20.0 sec 226 MBytes 948 Mbits/sec
[ 3] 20.0-22.0 sec 226 MBytes 948 Mbits/sec
[ 3] 22.0-24.0 sec 227 MBytes 951 Mbits/sec
[ 3] 24.0-26.0 sec 226 MBytes 949 Mbits/sec
[ 3] 26.0-28.0 sec 226 MBytes 948 Mbits/sec
[ 3] 28.0-30.0 sec 226 MBytes 949 Mbits/sec
[ 3] 30.0-32.0 sec 226 MBytes 948 Mbits/sec
[ 3] 32.0-34.0 sec 227 MBytes 951 Mbits/sec
[ 3] 34.0-36.0 sec 226 MBytes 948 Mbits/sec
[ 3] 36.0-38.0 sec 226 MBytes 949 Mbits/sec
[ 3] 38.0-40.0 sec 226 MBytes 948 Mbits/sec
[ 3] 40.0-42.0 sec 227 MBytes 952 Mbits/sec
[ 3] 42.0-44.0 sec 226 MBytes 948 Mbits/sec
[ 3] 44.0-46.0 sec 226 MBytes 949 Mbits/sec
[ 3] 46.0-48.0 sec 226 MBytes 948 Mbits/sec
[ 3] 48.0-50.0 sec 226 MBytes 949 Mbits/sec
[ 3] 50.0-52.0 sec 227 MBytes 952 Mbits/sec
[ 3] 52.0-54.0 sec 226 MBytes 949 Mbits/sec
[ 3] 54.0-56.0 sec 226 MBytes 948 Mbits/sec
[ 3] 56.0-58.0 sec 226 MBytes 949 Mbits/sec
[ 3] 58.0-60.0 sec 226 MBytes 948 Mbits/sec
[ 3] 60.0-62.0 sec 227 MBytes 952 Mbits/sec
[ 3] 62.0-64.0 sec 226 MBytes 948 Mbits/sec
[ 3] 64.0-66.0 sec 226 MBytes 948 Mbits/sec
[ 3] 66.0-68.0 sec 226 MBytes 948 Mbits/sec
[ 3] 68.0-70.0 sec 226 MBytes 949 Mbits/sec
[ 3] 70.0-72.0 sec 227 MBytes 952 Mbits/sec
[ 3] 72.0-74.0 sec 226 MBytes 948 Mbits/sec
[ 3] 74.0-76.0 sec 226 MBytes 949 Mbits/sec
[ 3] 76.0-78.0 sec 226 MBytes 948 Mbits/sec
[ 3] 78.0-80.0 sec 226 MBytes 948 Mbits/sec
[ 3] 80.0-82.0 sec 227 MBytes 952 Mbits/sec
[ 3] 82.0-84.0 sec 226 MBytes 949 Mbits/sec
[ 3] 84.0-86.0 sec 226 MBytes 948 Mbits/sec
[ 3] 86.0-88.0 sec 226 MBytes 948 Mbits/sec
[ 3] 88.0-90.0 sec 226 MBytes 949 Mbits/sec
[ 3] 90.0-92.0 sec 227 MBytes 952 Mbits/sec
[ 3] 92.0-94.0 sec 226 MBytes 948 Mbits/sec
[ 3] 94.0-96.0 sec 226 MBytes 948 Mbits/sec
[ 3] 96.0-98.0 sec 226 MBytes 949 Mbits/sec
[ 3] 98.0-100.0 sec 227 MBytes 952 Mbits/sec
[ 3] 0.0-100.0 sec 11.1 GBytes 949 Mbits/sec

# iperf -c 10.199.81.39 -w 1M -t 100 -i 2
------------------------------------------------------------
Client connecting to 10.199.81.39, TCP port 5001
TCP window size: 2.00 MByte (WARNING: requested 1.00 MByte)
------------------------------------------------------------
[ 3] local 10.199.81.42 port 61211 connected with 10.199.81.39 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0- 2.0 sec 228 MBytes 956 Mbits/sec
[ 3] 2.0- 4.0 sec 226 MBytes 949 Mbits/sec
[ 3] 4.0- 6.0 sec 226 MBytes 948 Mbits/sec
[ 3] 6.0- 8.0 sec 226 MBytes 948 Mbits/sec
[ 3] 8.0-10.0 sec 227 MBytes 952 Mbits/sec
[ 3] 10.0-12.0 sec 226 MBytes 949 Mbits/sec
[ 3] 12.0-14.0 sec 226 MBytes 948 Mbits/sec
[ 3] 14.0-16.0 sec 226 MBytes 949 Mbits/sec
[ 3] 16.0-18.0 sec 226 MBytes 948 Mbits/sec
[ 3] 18.0-20.0 sec 226 MBytes 949 Mbits/sec
[ 3] 20.0-22.0 sec 227 MBytes 952 Mbits/sec
[ 3] 22.0-24.0 sec 226 MBytes 948 Mbits/sec
[ 3] 24.0-26.0 sec 226 MBytes 948 Mbits/sec
[ 3] 26.0-28.0 sec 226 MBytes 948 Mbits/sec
[ 3] 28.0-30.0 sec 227 MBytes 952 Mbits/sec
[ 3] 30.0-32.0 sec 226 MBytes 948 Mbits/sec
[ 3] 32.0-34.0 sec 226 MBytes 948 Mbits/sec
[ 3] 34.0-36.0 sec 226 MBytes 948 Mbits/sec
[ 3] 36.0-38.0 sec 227 MBytes 952 Mbits/sec
[ 3] 38.0-40.0 sec 226 MBytes 948 Mbits/sec
[ 3] 40.0-42.0 sec 226 MBytes 949 Mbits/sec
[ 3] 42.0-44.0 sec 226 MBytes 948 Mbits/sec
[ 3] 44.0-46.0 sec 226 MBytes 949 Mbits/sec
[ 3] 46.0-48.0 sec 227 MBytes 951 Mbits/sec
[ 3] 48.0-50.0 sec 226 MBytes 948 Mbits/sec
[ 3] 50.0-52.0 sec 226 MBytes 949 Mbits/sec
[ 3] 52.0-54.0 sec 226 MBytes 948 Mbits/sec
[ 3] 54.0-56.0 sec 227 MBytes 951 Mbits/sec
[ 3] 56.0-58.0 sec 226 MBytes 948 Mbits/sec
[ 3] 58.0-60.0 sec 226 MBytes 948 Mbits/sec
[ 3] 60.0-62.0 sec 227 MBytes 952 Mbits/sec
[ 3] 62.0-64.0 sec 226 MBytes 948 Mbits/sec
[ 3] 64.0-66.0 sec 226 MBytes 948 Mbits/sec
[ 3] 66.0-68.0 sec 226 MBytes 948 Mbits/sec
[ 3] 68.0-70.0 sec 226 MBytes 949 Mbits/sec
[ 3] 70.0-72.0 sec 227 MBytes 952 Mbits/sec
[ 3] 72.0-74.0 sec 226 MBytes 948 Mbits/sec
[ 3] 74.0-76.0 sec 226 MBytes 948 Mbits/sec
[ 3] 76.0-78.0 sec 226 MBytes 949 Mbits/sec
[ 3] 78.0-80.0 sec 226 MBytes 949 Mbits/sec
[ 3] 80.0-82.0 sec 227 MBytes 951 Mbits/sec
[ 3] 82.0-84.0 sec 226 MBytes 948 Mbits/sec
[ 3] 84.0-86.0 sec 226 MBytes 949 Mbits/sec
[ 3] 86.0-88.0 sec 227 MBytes 951 Mbits/sec
[ 3] 88.0-90.0 sec 226 MBytes 949 Mbits/sec
[ 3] 90.0-92.0 sec 226 MBytes 948 Mbits/sec
[ 3] 92.0-94.0 sec 226 MBytes 949 Mbits/sec
[ 3] 94.0-96.0 sec 226 MBytes 948 Mbits/sec
[ 3] 96.0-98.0 sec 227 MBytes 951 Mbits/sec
[ 3] 98.0-100.0 sec 226 MBytes 948 Mbits/sec
[ 3] 0.0-100.0 sec 11.1 GBytes 949 Mbits/sec

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

相關文章