CentOS 6.9下雙網卡綁定單個IP地址及裝網卡綁定到一個網橋(轉)


 

說明:經過查閱,原來雙網卡綁定一個IP的專業名詞叫做bond,可以實現負載均衡;如果想要實現兩張網卡綁定到一個網橋,基本思路是兩張網卡設置同一個網橋是行不通的,但如果先實現bond,然后將bond綁定到這個網橋上是行的。關鍵看你配置的思路。網橋一般情況用不到,主要是用在KVM上。

雙網卡綁定單個IP地址為了提供網絡的高可用性,我們可能需要將多塊網卡綁定成一塊虛擬網卡對外提供服務,這樣即使其中的一塊物理網卡出現故障,也不會導致連接中斷。

在Linux下叫bonding,IBM稱為etherchanel,broadcom叫team,但是名字怎么變,效果都是將兩塊或更多的網卡當做一塊網卡使用,在增加帶寬的同時也可以提高冗余性。比如我們在CentOS 6.9下可以將eth0和eth1綁定成虛擬網卡bond0。

如圖:

 

實驗配置:

mode=1:表示fault-tolerance (active-backup)提供冗余功能,工作方式是主備的工作方式,其中一塊網卡在工作(若eth0斷掉),則自動切換到另一個塊網卡(eth1做備份)。

系 統

設備名稱

IP地址

子網掩碼

 

CentOS 6.9_64bit

eth0

 

 

eth1

 

 

bond0

10.1.3.210

255.255.255.0

1、查看主機網卡

[root@web ~]# cd /etc/sysconfig/network-scripts/
[root@web1 network-scripts]# ll
total 200
-rw-r--r--. 1 root root   212 Mar 20 22:15 ifcfg-eth0
-rw-r--r--  1 root root   212 Mar 23 19:10 ifcfg-eth1

2、復制ifcfg-bond0

[root@web network-scripts]# cp ifcfg-eth0 ifcfg-bond0
[root@web network-scripts]# ll
total 204
-rw-r--r--  1 root root   212 Mar 23 19:12 ifcfg-bond0
-rw-r--r--. 1 root root   212 Mar 20 22:15 ifcfg-eth0
-rw-r--r--  1 root root   212 Mar 23 19:10 ifcfg-eth1 

3、編輯ifcfg-bond0、ifcfg-eth0、ifcfg-eth1

[root@web network-scripts]# vim ifcfg-bond0
DEVICE=bond0
BOOTPROTO=static
IPADDR=10.1.3.210
NETMASK=255.255.255.0
GATEWAY=10.1.3.254
ONBOOT=yes
USERCTL=no

[root@web1 network-scripts]# vim ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
USERCTL=no

[root@web1 network-scripts]# vim ifcfg-eth1
DEVICE=eth1
ONBOOT=yes
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
USERCTL=no

4、模塊加載

[root@web1 ~]# vim /etc/modprobe.d/dist.conf 

在最后添加以下內容:

#加載bonding模塊,對外虛擬網絡接口設備為bond0

alias bond0 bonding
options bond0 miimon=100 mode=1

查看

[root@web1 ~]# grep bond0 /etc/modprobe.d/dist.conf
alias bond0 bonding
options bond0 miimon=100 mode=1 

說明:

miimon是用來進行鏈路監測的。 比如:miimon=100,單位是ms(毫秒)這邊的100,是100ms,即是0.1秒那么系統每100ms監測一次鏈路連接狀態,如果有一條線路不通就轉入另一條線路;mode的值表示工作模式,他共有0,1,2,3四種模式,常用的為0、1兩種。 

mode共有七種(0~6),這里解釋兩個常用的選項。

mode=0:表示load balancing (round-robin)為負載均衡方式,兩塊網卡都在工作。

mode=1:表示fault-tolerance (active-backup)提供冗余功能,工作方式是主備的工作方式,其中一塊網卡在工作(若eth0斷掉),則自動切換到另一個塊網卡(eth1做備份)。

bonding只能提供鏈路監測,即從主機到交換機的鏈路是否接通。如果只是交換機對外的鏈路down掉了,而交換機本身並沒有故障,那么bonding會認為鏈路沒有問題而繼續使用。

5、重啟網絡服務,使配置生效

[root@web1 ~]# service network restart
Shutting down interface eth0:                              [  OK  ]
Shutting down interface eth1:                              [  OK  ]
Shutting down loopback interface:                           [  OK  ]
Bringing up loopback interface:                             [  OK  ]
Bringing up interface bond0:  RTNETLINK answers: File exists
Error adding address 10.1.3.210 for bond0.
RTNETLINK answers: File exists                              [  OK  ]

6、查看bond0接口狀態

[root@web1 ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth0       // eth0主模式
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth0
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:c9:6d:18
Slave queue ID: 0
Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:c9:6d:22
Slave queue ID: 0

7、查看中路由表狀態:

[root@web1 ~]#  route  -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.1.3.0        0.0.0.0         255.255.255.0   U     0      0        0 bond0
169.254.0.0     0.0.0.0         255.255.0.0     U     1004   0        0 bond0
0.0.0.0         10.1.3.254      0.0.0.0         UG    0      0        0 bond0

[root@web1 ~]# lsmod | grep bond
bonding               127060  0

8、測試

選擇一台windows 7機器ping測試機,然后停掉當前使用的網卡eth0,查看是否能夠繼續ping通;

測試結果:丟失一個包。

 

查看bond0接口狀態

[root@web1 ~]#cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth1      //eth1為主模式
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth0
MII Status: down
Speed: Unknown
Duplex: Unknown
Link Failure Count: 1
Permanent HW addr: 00:0c:29:c9:6d:18
Slave queue ID: 0
Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 1
Permanent HW addr: 00:0c:29:c9:6d:22
Slave queue ID: 0

配置完成!

9、支持NetworkManager的centos系統

只需要通過界面配置即可以完成多塊網卡的綁定

 

10、一個網橋、bond實例

/etc/sysconfig/network-scripts/下的文件:

ifcfg-ebr:

vi 

DEVICE=ebr  
STP=yes  
BRIDGING_OPTS=priority=128  
TYPE=Bridge  
BOOTPROTO=none  
IPADDR=192.168.1.2  
NETMASK=255.255.255.0  
GATEWAY=192.168.1.1  
DNS1=  
DNS2=  
DEFROUTE=yes  
IPV4_FAILURE_FATAL=no  
NAME=ebr  
UUID=1ce71742-a273-42fe-b358-3b0a0ee77c50  
ONBOOT=yes  
 ifcfg-ebrbond:
DEVICE=ebrbond  
BONDING_OPTS="miimon=100 mode=balance-alb"  
TYPE=Bond  
BONDING_MASTER=yes  
BRIDGING_OPTS="priority=50 path_cost=33"  
NAME=ebrbond  
UUID=d0baebf0-282b-4dfe-b6d4-f6ff30ad81d1  
ONBOOT=yes  
BRIDGE=ebr

ifcfg-eth0

DEVICE=eth0  
HWADDR=90:B1:1C:6E:AE:09  
TYPE=Ethernet  
NAME=eth0  
UUID=c2eee5d8-34ee-4c0c-8d77-90029520b249  
ONBOOT=yes  
MASTER=ebrbond  
SLAVE=yes  

ifcfg-eth1

DEVICE=eth1  
HWADDR=00:10:18:EA:9E:FC  
TYPE=Ethernet  
NAME=eth1  
UUID=71ee5282-ce19-49f4-972d-37ab030b8011  
ONBOOT=yes  
MASTER=ebrbond  
SLAVE=yes  

 

參考:

http://blog.csdn.net/taiyang1987912/article/details/46550857(以上內容轉自此篇文章)

https://www.cnblogs.com/wonux/p/5555953.html

https://www.cnblogs.com/weifeng1463/p/7549951.html

 


免責聲明!

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



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