Debian7 bonding配置詳解


Linux雙網卡綁定一個IP地址,實質工作就是使用兩塊網卡虛擬為一塊,使用同一個IP地址,是我們能夠得到更好的更快的服務。其實這項技術在Sun和Cisco中早已存在,被稱為Trunking和Etherchannel技術,在Linux的2.4.x的內核中也采用這這種技術,被稱為bonding。

bonding的原理

在正常情況下,網卡只接收目的硬件地址(MAC Address)是自身Mac的以太網幀,對於別的數據幀都過濾掉,以減輕驅動程序的負擔。

但是網卡也支持另外一種被稱為混雜的模式,可以接收網絡上所有的幀,比如說很多用抓包工具就需要讓網卡運行在這個模式下。

bonding也運行在這個混雜模式下,而且修改了驅動程序中的MAC地址,將兩塊網卡的MAC地址改成相同,可以接收特定MAC的數據幀。然后把相應的數據幀傳送給bond驅動程序處理。

bonding模塊工作方式

bonding有0-6七種模式,常用的工作方式為0、1、6三種:

mode=0:表示load balancing(round-robin)為負載均衡模式(兩塊網卡都要工作),但需要交換機支持並需要在交換機上進行相應配置。
mode=1:表示fault-tolerance(active-backup)提供冗余功能,工作方式是主輔的方式,也就是說默認情況下只有一塊網卡工作,另一塊做備份。
mode=6:表示load balancing(round-robin)為負載均衡模式(兩塊網卡都要工作),不需要交換機支持。

bonding配置

使用如下命令安裝bonding。

apt-get install ifenslave

使用如下命令讓系統開機自動加載模塊bonding。

sh -c "echo bonding mode=6 miimon=100 >> /etc/modules"

其中miimon參數是用於進行鏈路監測的。比如:miimon=100,那么系統每100ms監測一次鏈路連接狀態,如果有一條線路不通就轉入另一條線路;mode的值表示bonding工作模式。

修改/etc/network/interfaces文件為如下內容。

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address 192.168.1.20
netmask 255.255.255.0

auto eth1
iface eth1 inet static
address 192.168.1.30
netmask 255.255.255.0

auto bond0
iface bond0 inet static  # 虛擬網卡的TCP/IP配置
address 192.168.1.10
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 192.168.1.1
post-up ifenslave bond0 eth0 eth1
pre-down ifenslave -d bond0 eth0 eth1

如果在安裝ifenslave后沒有重新啟動計算機,必須手動加載bonding模塊。

modprobe bonding mode=6 miimon=100

使用如下命令重新啟動網卡。

/etc/init.d/networking restart

虛擬網卡綁定虛擬網橋配置

auto br0
iface br0 inet static
bridge_ports bond0
address 192.168.1.10
netmask 255.255.255.0
gateway 192.168.1.1

auto bond0
iface bond0 inet manual
up ip address add 0/0 dev $IFACE
up ip link set $IFACE up
down ip link set $IFACE down
post-up ifenslave bond0 eth0 eth1
pre-down ifenslave -d bond0 eth0 eth1


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM