1. 程式人生 > >UbuntuBonding(16.04網卡綁定)

UbuntuBonding(16.04網卡綁定)

module etc ast using delay emc 配置 不同的 conf

UbuntuBonding(網卡綁定)

綁定,也稱為端口聚合或鏈路聚合,意味著將多個網絡接口(NIC)組合到單個鏈路,從而提供高可用性,負載平衡,最大吞吐量或這些組合。
註意bonding只能提供鏈路監測,即從主機到交換機的鏈路是否接通。如果只是交換機對外(如防火墻等)的鏈路down掉了,而交換機本身並沒有故障,那麽bonding會認為鏈路沒有問題而繼續使用。

一、安裝網卡綁定所需要的負載均衡軟件fenslave,它是一款linux下的負載均衡工具,可以將數據包有效的分配到bonding驅動。

1、查看軟件fenslave是否安裝
root@ubuntu:~# dpkg -l | grep fenslave


ii ifenslave 2.7ubuntu1 all configure network interfaces for parallel routing (bonding)

通過上面的信息可以知道軟件已經安裝

2、如果沒安裝,可以通過apt源安裝,有外網就用外網源,沒有的話用本地DVD源。
root@ubuntu:~# apt-get install ifenslave

三、檢查 bonding 模塊是否正常加載
root@ubuntu:~# lsmod | grep bonding
bonding 147456 0
root@ubuntu:~#

四、添加bonding模塊開機啟動,編輯/etc/modules配置文件如下


root@ubuntu:~# vi /etc/modules
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
bonding #添加的內容,使該模塊開機啟動

root@ubuntu:~#

五、配置網絡接口

1、確保您的網絡已關閉:
root@ubuntu:~# systemctl stop networking.service


2、然後加載綁定內核模塊:
root@ubuntu:~# modprobe bonding #如果上面查看模塊時已經加載,這裏可以不執行

3、編輯網絡配置文件

root@ubuntu:~# vi /etc/network/interfaces

舉例1:要使用簡單的主備模式設置,將enp4s0f0和enp4s0f1作為綁定網卡,綁定的接口為bond0,並將作為enp4s0f0主接口:
綁定前需要先通過ifconfig -a 命令查看可以的網卡,配置文件如下:
--------------------------------------------------------------------------
# enp4s0f0 is manually configured, and slave to the "bond0" bonded NIC
auto enp4s0f0 #要綁定的主網卡
iface enp4s0f0 inet manual
bond-master bond0
bond-primary enp4s0f0

# enp4s0f1 ditto, thus creating a 2-link bond.
auto enp4s0f1 #要綁定的備網卡
iface enp4s0f1 inet manual
bond-master bond0

# bond0 is the bonding NIC and can be used like any other normal NIC.
# bond0 is configured using static network information.
auto bond0 #綁定的網卡名
iface bond0 inet static #靜態地址
address 192.168.3.30 #IP
gateway 192.168.3.1 #網關
netmask 255.255.255.0 #子網
bond-mode active-backup #模式主備
bond-miimon 100 #miimon是100毫秒監測一次網卡狀態,如果有一條線路不通就切換另一條線路。
bond-slaves none
-------------------------------------------------------------------------

舉例2 :要使用自適應負載均衡模式(模式6)設置,將enp4s0f0和enp4s0f1作為綁定網卡,綁定的接口為bond0,
配置文件如下:

# enp4s0f0 is manually configured, and slave to the "bond0" bonded NIC
auto enp4s0f0
iface enp4s0f0 inet manual
bond-master bond0

# enp4s0f1 ditto, thus creating a 2-link bond.
auto enp4s0f1
iface enp4s0f1 inet manual
bond-master bond0

# bond0 is the bonding NIC and can be used like any other normal NIC.
# bond0 is configured using static network information.
auto bond0
iface bond0 inet static
address 13.181.3.30
gateway 13.181.3.254
netmask 255.255.255.0
bond-mode 6 #綁定模式為6
bond-miimon 100
bond-slaves enp4s0f0 enp4s0f1 #綁定的從屬的網卡
------------------------------------------------------------------------------

六、啟動網卡
root@ubuntu:~# systemctl start networking.service


七、查看bond0的工作情況

root@ubuntu:~# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: fault-tolerance (active-backup) #bond模式為主備
Primary Slave: enp4s0f0 (primary_reselect always)
Currently Active Slave: enp4s0f0
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: enp4s0f0
MII Status: up
Speed: 10000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 50:5d:ac:49:08:3f
Slave queue ID: 0

Slave Interface: enp4s0f1
MII Status: up
Speed: 10000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 50:5d:ac:49:08:40
Slave queue ID: 0
root@ubuntu:~#


八、bonding一共有7種工作模式(mode):

0:(balance-rr) Round-robin policy: (平衡輪詢策略):傳輸數據包順序是依次傳輸,直到最後一個傳輸完畢,此模式提供負載平衡和容錯能力。

1:(active-backup) Active-backup policy:(活動備份策略):只有一個設備處於活動狀態。一個宕掉另一個馬上由備份轉換為主設備。mac地址是外部可見得。此模式提供了容錯能力。

2:(balance-xor) XOR policy:(平衡策略):傳輸根據[(源MAC地址xor目標MAC地址)mod設備數量]的布爾值選擇傳輸設備。 此模式提供負載平衡和容錯能力。

3:(broadcast) Broadcast policy:(廣播策略):將所有數據包傳輸給所有設備。此模式提供了容錯能力。

4:(802.3ad) IEEE 802.3ad Dynamic link aggregation. IEEE 802.3ad 動態鏈接聚合:創建共享相同的速度和雙工設置的聚合組。此模式提供了容錯能力。每個設備需要基於驅動的重新獲取速度和全雙工支持;如果使用交換機,交換機也需啟用 802.3ad 模式。

5:(balance-tlb) Adaptive transmit load balancing(適配器傳輸負載均衡):通道綁定不需要專用的交換機支持。發出的流量根據當前負載分給每一個設備。由當前設備處理接收,如果接受的設 備傳不通就用另一個設備接管當前設備正在處理的mac地址。

6:(balance-alb) Adaptive load balancing: (適配器負載均衡):包括mode5,由 ARP 協商完成接收的負載。bonding驅動程序截獲 ARP在本地系統發送出的請求,用其中之一的硬件地址覆蓋從屬設備的原地址。就像是在服務器上不同的人使用不同的硬件地址一樣。


































UbuntuBonding(16.04網卡綁定)