基於centos6.8配置多網卡綁定

     Linux 自帶的軟件bonding 可以把多個網絡接口設備捆綁爲單個的網絡接口設置來使用,用於網絡負載均衡及網絡冗餘。其中網絡負載均衡常用於我們的文件服務器中,文件服務器在多用戶同時使用的情況下,網絡壓力非常大的,所以爲了解決同一個IP突破流量的限制,使用多網卡綁定是一個極好的辦法。網絡冗餘在生產環境中也特別重要,特別是在網卡在可能發生物理性質損壞而無法同時使用同一IP快速響應的情況下多網卡綁定就顯得特別重要了,bonding爲網卡提供了冗餘的支持,把多網卡綁定到一個IP,即使其中一塊網卡發生物理損壞的情況下,另一塊網卡自動啓用,並且提供正常服務。


下面我們先來了解一下bonding的常用mode種類:

    mode=0 ,即:(balance-rr) Round-robin policy(平衡掄循環策略)數據包的傳輸方式輪詢傳輸,第一個包傳輸給eth0 ,第二個包傳輸給eth1,就這樣循環下去,直到傳輸完畢,這裏需要注意的是mode0能作爲負載均衡作用,不提供容錯功能,如果第一張網卡出現故障網絡將面臨癱瘓。

 

    mode=1,即: (active-backup) Active-backup policy(主-備份策略)只有一個處於活動狀態,當主網卡出現故障時,備網卡馬上由備轉變成主。這個模式提供了較高的容錯能力。但是資源利用率較低。

 

    mode=3,即:broadcast(廣播策略)在每個slave接口上傳輸每個數據包,此模式提供了容錯能力

 

演示環境:VMware 11 版本 ,系統centos 6.8

     第一步:  

     首先我們新添加一張網卡,重啓並生效

wKioL1fIGc7Rf9bDAADr0U3dNFw622.png-wh_50


    第二步:關閉NetworkManager服務(在centos6系列版本中開啓NetworkManager與bonding會產生衝突)


[root@centos6 ~]# service NetworkManager stop
Stopping NetworkManager daemon:                            [  OK  ]
[root@centos6 ~]# chkconfig NetworkManager off


    第三步:創建虛擬網卡bond0,在/etc/sysconfig/network-scripts目錄下新建虛擬網卡band0,在這裏使用的mode是1,文件內容如圖所示


wKioL1fIISHS-VsgAABW-64qQ98915.png-wh_50

[root@centos6 ~]# vim /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
BOOTPROTO=none
BONDING_OPTS="miimon=100,mode=1"
IPADDR=10.1.45.181
PREFIX=16
GATEWAY=10.1.0.1


    第四步:配置網卡參數,網卡參數中需要標註網卡名,網卡的角色及虛擬主卡名稱。


wKiom1fIJMySYt1QAAAzHyIq56I471.png-wh_50

[root@centos6 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
SLAVE=yes
MASTER=bond0
[root@centos6 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
SLAVE=yes
MASTER=bond0


    第五步:重啓網卡,查看狀態


wKioL1fIJn-ThzUVAAGUARobtDE910.png-wh_50

wKiom1fIJp6B19i9AACeJwJIAeE878.png-wh_50

使用我另一臺主機ping狀態爲通

Connecting to 10.1.45.180:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.

Last login: Thu Sep  1 14:51:24 2016 from 10.1.250.31
Welcome to the home of snowbamboo ^ ^ 
[root@localhost ~]# ping 10.1.45.181
PING 10.1.45.181 (10.1.45.181) 56(84) bytes of data.
64 bytes from 10.1.45.181: icmp_seq=1 ttl=64 time=1.63 ms
64 bytes from 10.1.45.181: icmp_seq=2 ttl=64 time=0.354 ms
64 bytes from 10.1.45.181: icmp_seq=3 ttl=64 time=0.250 ms
64 bytes from 10.1.45.181: icmp_seq=4 ttl=64 time=0.514 ms
64 bytes from 10.1.45.181: icmp_seq=5 ttl=64 time=0.282 ms
64 bytes from 10.1.45.181: icmp_seq=6 ttl=64 time=0.252 ms
64 bytes from 10.1.45.181: icmp_seq=7 ttl=64 time=0.361 ms
64 bytes from 10.1.45.181: icmp_seq=8 ttl=64 time=0.310 ms
64 bytes from 10.1.45.181: icmp_seq=9 ttl=64 time=0.426 ms
64 bytes from 10.1.45.181: icmp_seq=10 ttl=64 time=0.439 ms
64 bytes from 10.1.45.181: icmp_seq=11 ttl=64 time=0.506 ms
64 bytes from 10.1.45.181: icmp_seq=12 ttl=64 time=0.502 ms
64 bytes from 10.1.45.181: icmp_seq=13 ttl=64 time=0.423 ms
64 bytes from 10.1.45.181: icmp_seq=14 ttl=64 time=0.230 ms
64 bytes from 10.1.45.181: icmp_seq=15 ttl=64 time=0.494 ms
64 bytes from 10.1.45.181: icmp_seq=16 ttl=64 time=0.417 ms
64 bytes from 10.1.45.181: icmp_seq=17 ttl=64 time=0.522 ms


現在我關閉一張網卡,看網絡是否有波動


wKiom1fI61PgDH3GAAC8nGLC0_A929.png-wh_50wKiom1fI64LBeCQYAAATuwlgfEs216.png-wh_50


總結:

    在使用bonding的mode1時,必須至少要有兩塊網卡,一張爲活動網卡,另一張爲備用狀態,當主卡發生故障時備卡馬上接替工作,繼續完成數據傳輸。mode0模式時需要注意的是,mode0只支持負載均衡,加速網絡數據包傳輸,沒有容錯功能。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章