歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux技術 >> Debian 雙網卡bond

Debian 雙網卡bond

日期:2017/3/1 18:08:18   编辑:Linux技術
1. 安裝ifenslave
ifenslave的作用是網卡的負載均衡
# apt-get install ifenslave
2. 修改/etc/network/interface

復制代碼代碼如下:
{root@b01 359 ~}
# cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
auto <A onclick="tagshow('bond');return false;" href="/tag/bond/">bond</A>0
iface bond0 inet static
address 192.168.1.5
netmask 255.255.255.0
gateway 192.168.1.1
up ifenslave bond0 eth0 eth1
down ifenslave -d bond0 eth0 eth1
dns-nameservers 8.8.8.8
iface eth0 inet static
iface eth1 inet static

3. 加載bonding模塊(這塊費了大部分時間)

復制代碼代碼如下:
# cat /etc/modprobe.d/aliases-bond
install bond0 /sbin/modprobe bonding miimon=100 mode=0

bond的mode一共有七種:

復制代碼代碼如下:
0: (balance-rr) Round-robin policy: (平衡掄循環策略):傳輸數據包順序是依次傳輸,直到最後一個傳輸完畢, 此模式提供負載平衡和容錯能力。
1: (active-backup) Active-backup policy:(主-備份策略):只有一個設備處於活動狀態。 一個宕掉另一個馬上由備份轉換為主設備。mac地址是外部可見得。 此模式提供了容錯能力。
2:(balance-xor) XOR policy:(廣播策略):將所有數據包傳輸給所有接口。 此模式提供了容錯能力。
3:(balance-xor) XOR policy:(平衡策略): 傳輸根據原地址布爾值選擇傳輸設備。 此模式提供負載平衡和容錯能力。
4:(802.3ad) IEEE 802.3ad Dynamic link aggregation.IEEE 802.3ad 動態鏈接聚合:創建共享相同的速度和雙工設置的聚合組。
5:(balance-tlb) Adaptive transmit load balancing(適配器傳輸負載均衡):沒有特殊策略,第一個設備傳不通就用另一個設備接管第一個設備正在處理的mac地址,幫助上一個傳。
6:(balance-alb) Adaptive load balancing:(適配器傳輸負載均衡):大致意思是包括mode5,bonding驅動程序截獲 ARP 在本地系統發送出的請求,用其中之一的硬件地址覆蓋從屬設備的原地址。就像是在服務器上不同的人使用不同的硬件地址一樣

一個小技巧:
為了防止修改網卡配置或其他配置錯誤導致不能連接服務器,寫一個crontab, 將正確的網卡配置文件恢復後重新network restart或者
重啟機器 (iptable等類似風險操作也可以這樣來處理)

復制代碼代碼如下:
{root@b01 361 ~}
# crontab -l
# m h dom mon dow command
#20 * * * * cp -pr /etc/network/interfaces.org /etc/network/interfaces
#21 * * * * /sbin/init 6
Copyright © Linux教程網 All Rights Reserved