標籤:bond 雙網卡
說明:兩個網卡做成一個虛擬網卡,一個壞掉以後不影響業務
1.
兩個網卡 eth0
eth1
備忘:沒有eth1的話添加一塊網卡,複製的虛擬機器要配置好
2.bond的主機 bond0
3.第一步:配置設定檔案 [[email protected] network-scripts]# vim /etc/sysconfig/network-scripts/ifcfg-bond0
內容:
[[email protected] ~]# cat /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.33.128
NETMASK=255.255.25.0
GATEWAY=192.168.33.2
DNS1=192.168.33.2
DNS2=8.8.8.8
BROADCAST=192.168.33.255
USERCTL=no
[[email protected] ~]#
4.第二步:編輯eth0網卡
[[email protected] network-scripts]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
[[email protected] network-scripts]#
5.編輯eth1網卡
[[email protected] network-scripts]# vim /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
6.因為linux的虛擬網卡是在核心模組中實現的,所以需要安裝的時候已經裝好該module。在/etc/modules.conf檔案中添加如下內容(如果沒有該檔案,則建立一個):
[[email protected] ~]# cat /etc/modules.conf
alias bond0 bonding
options bond0 miimon=100 mode=1 primary=eth0
[[email protected] ~]#
7開機配置文檔的配置
[[email protected] ~]# tail -n 1 /etc/rc.local
modprobe bonding miimon=100 mode=1
[[email protected] ~]#
8.重啟網路,確認bond的狀況
①
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/7F/5D/wKioL1ccKHTCRtZpAAAesG61OUw414.png" title="clipboard.png" alt="wKioL1ccKHTCRtZpAAAesG61OUw414.png" />
②查看bond狀況啟動
650) this.width=650;" src="/e/u261/themes/default/images/spacer.gif" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" alt="spacer.gif" />650) this.width=650;" src="http://s5.51cto.com/wyfs02/M02/7F/5F/wKiom1ccJ8XTqzrEAAArqBtOyFo258.png" title="clipboard.png" alt="wKiom1ccJ8XTqzrEAAArqBtOyFo258.png" />
9.查看一下狀態
[[email protected] ~]# ifconfig | grep HWaddr
bond0 Link encap:Ethernet HWaddr 00:0C:29:07:7E:B1
eth0 Link encap:Ethernet HWaddr 00:0C:29:07:7E:B1
eth1 Link encap:Ethernet HWaddr 00:0C:29:07:7E:B1
[[email protected] ~]#
10.系統自動綁定,設定預設的網關
[[email protected] ~]# echo "ifenslave bond0 eth0 eth1">>/etc/rc.d/rc.local
[[email protected] ~]# echo "route add default gw 192.168.33.2">>/etc/rc.d/rc.local
[[email protected] ~]#
11.重啟生效
[[email protected] ~]# ping www.baidu.com
PING www.baidu.com (119.75.218.70) 56(84) bytes of data.
64 bytes from 119.75.218.70: icmp_seq=1 ttl=128 time=4.80 ms
64 bytes from 119.75.218.70: icmp_seq=2 ttl=128 time=4.48 ms
64 bytes from 119.75.218.70: icmp_seq=3 ttl=128 time=8.40 ms
^C
--- www.baidu.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2063ms
rtt min/avg/max/mdev = 4.484/5.899/8.409/1.779 ms
[[email protected] ~]#
12.測試:
(複製會話)
Last login: Mon Apr 18 21:26:23 2016 from 192.168.33.1
[[email protected] ~]# ifdown eth0
[[email protected] ~]#
[[email protected] ~]#
(測試)
[[email protected] ~]# ping www.baidu.com
PING www.a.shifen.com (220.181.111.188) 56(84) bytes of data.
64 bytes from 220.181.111.188: icmp_seq=1 ttl=128 time=10.3 ms
64 bytes from 220.181.111.188: icmp_seq=2 ttl=128 time=5.30 ms
64 bytes from 220.181.111.188: icmp_seq=3 ttl=128 time=8.88 ms
64 bytes from 220.181.111.188: icmp_seq=4 ttl=128 time=5.94 ms
64 bytes from 220.181.111.188: icmp_seq=5 ttl=128 time=16.7 ms
64 bytes from 220.181.111.188: icmp_seq=6 ttl=128 time=5.97 ms
64 bytes from 220.181.111.188: icmp_seq=7 ttl=128 time=35.3 ms
64 bytes from 220.181.111.188: icmp_seq=8 ttl=128 time=5.69 ms
64 bytes from 220.181.111.188: icmp_seq=9 ttl=128 time=16.1 ms
***********************************************************************************
其中miimon=100表示每100ms檢查一次鏈路串連狀態,如果不通則會切換物理網卡
mode=1表示主備模式,也就是只有一塊網卡是active的,只提供失效保護。如果mode=0則是負載平衡模式的,所有的網卡都是active,還有其他一些模式很少用到
primary=eth0表示主備模式下eth0為預設的active網卡
miimon是毫秒數,每100毫秒觸發檢測線路穩定性的事件。
mode 是ifenslave的工作狀態。
一共有7種方式:
=0: (balance-rr) Round-robin policy: (平衡掄迴圈策略):傳輸資料包順序是依次傳輸,直到最後一個傳輸完畢, 此模式提供Server Load Balancer和容錯能力。
=1: (active-backup) Active-backup policy:(主-備份策略):只有一個裝置處於活動狀態。 一個宕掉另一個馬上由備份轉換為主裝置。mac地址是外部可見得。 此模式提供了容錯能力。
=2:(balance-xor) XOR policy:(平衡 策略): 傳輸根據原地址布爾值選擇傳輸裝置。 此模式提供Server Load Balancer和容錯能力。
=3:(broadcast) broadcast 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 在本地系統發送出的請求,用其中之一的硬體地址覆蓋從屬裝置的原地址。就像是在伺服器上不同的人使用不同的硬體地址一樣。
本文出自 “linux” 部落格,請務必保留此出處http://wsxxsl.blog.51cto.com/9085838/1767173
bond 雙網卡綁定