在esxi5.5中建立的虛拟機,系統為Centos6.4,原來隻有一塊網卡,名稱為ifcfg-eth0。為實作網絡備援,登陸VMware vSphere Client後給虛拟機添加了一塊網卡,網卡名為ifcfg-eth1。
2.1 修改/etc/sysconfig/network-scripts/ifcfg-eth0配置文檔,修改後的内容如下:
DEVICE=eth0
HWADDR=78:2B:CB:30:66:29 #網卡MAC位址,可去掉
TYPE=Ethernet #可去掉
ONBOOT=yes #系統啟動時自動啟用該裝置
SLAVE=yes
MASTER=bond0
BOOTPROTO=none #啟動時不使用任何協定
2.2 修改/etc/sysconfig/network-scripts/ifcfg-eth1配置文檔,修改後的内容如下:
DEVICE=eth1
HWADDR=78:2B:CB:30:66:2B #網卡MAC位址,可去掉
TYPE=Ethernet #類型,可去掉
ONBOOT=yes #系統啟動時自動啟用該裝置
BOOTPROTO=none #啟動時不使用任何協定
2.3 建立一個綁定網卡的配置文檔/etc/sysconfig/network-scripts/ifcfg-bond0,内容如下:
DEVICE=bond0
TYPE=Ethernet
ONBOOT=yes
BONDING_OPTS="miimon=100 mode=0"
# mode=0表示"round-robin"政策,表示負載均衡方式,兩塊網卡都工作
#mode=1表示"active-backup"政策,表示備援方式,隻有一個網卡在工作,若出問題則啟用另一個
#也可以在/etc/modprobe.d/dist.conf檔案最後加入以下兩行
#alias bond0 bonding
#options bond0 miimon=100 mode=1
BOOTPROTO=static
IPADDR=10.240.210.233
NETMASK=255.255.255.0
GATEWAY=10.240.210.4
DNS1=8.8.8.8
2.4 修改的是/etc/rc.local,負責在系統啟動時将虛拟網卡和兩張實體網卡相綁定
ifenslave bond0 eth2 eth3
service network restart
任何一塊網卡關閉後,不影響伺服器的正常通訊
cat /etc/sysconfig/network-scripts/ifcfg-eth0
1
2
3
4
<code>DEVICE=eth0</code>
<code>BOOTPROTO=none</code>
<code>MASTER=bond0</code>
<code>SLAVE=yes</code>
cat /etc/sysconfig/network-scripts/ifcfg-eth1
<code>DEVICE=eth1</code>
cat /etc/sysconfig/network-scripts/ifcfg-bond0
5
6
7
8
9
10
<code>DEVICE=bond0</code>
<code>TYPE=Ethernet</code>
<code>ONBOOT=yes</code>
<code>BONDING_OPTS="miimon=100 mode=1"</code>
<code>BOOTPROTO=static</code>
<code>IPADDR=10.240.210.60</code>
<code>PREFIX=24</code>
<code>GATEWAY=10.240.210.4</code>
<code>DNS1=10.240.210.61</code>
<code>DNS1=10.240.210.62</code>
【測試】
模式一: mode1 ,備援,隻有一個網卡在工作,若出問題則啟用另一個,預設為第一塊網卡在工作。
檢視目前正在使用的網卡
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
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth1
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:6b:63:ec
Slave queue ID: 0
Slave Interface: eth0
Permanent HW addr: 00:0c:29:6b:63:e2
關閉網卡1,ifdown eth1,繼續檢視目前正在使用的網卡,可以看到預設使用的網卡為eth0
Currently Active Slave: eth0
【小結】
bond剛開始預設走eth1,當把eth1關閉後,則走eth0。
模式零: mode0,表示負載均衡方式,兩塊網卡都工作
将bond配置檔案中BONDING_OPTS="miimon=100 mode=1"的mode=1改為mode=0
檢視bond運作狀态
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<code>root@oldboy network-scripts$cat /proc/net/bonding/bond0 </code>
<code>Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)</code>
<code>Bonding Mode: fault-tolerance (active-backup)</code>
<code>Primary Slave: None</code>
<code>Currently Active Slave: eth1</code>
<code>MII Status: up</code>
<code>MII Polling Interval (ms): 100</code>
<code>Up Delay (ms): 0</code>
<code>Down Delay (ms): 0</code>
<code>Slave Interface: eth1</code>
<code>Speed: 1000 Mbps</code>
<code>Duplex: full</code>
<code>Link Failure Count: 0</code>
<code>Permanent HW addr: 00:0c:29:6b:63:ec</code>
<code>Slave queue ID: 0</code>
<code>Slave Interface: eth0</code>
<code>Permanent HW addr: 00:0c:29:6b:63:e2</code>
可以看到,兩塊網卡同時在工作。
關閉任何一個網卡後不影響伺服器正常通訊。
<code>root@oldboy network-scripts$ifdown eth0</code>
<code>Bonding Mode: load balancing (round-robin)</code>
<a href="http://s3.51cto.com/wyfs02/M01/73/E4/wKiom1YJFiXA70RoAAIOQfz1f-E246.jpg" target="_blank"></a>
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<code>root@oldboy network-scripts$ifup eth0</code>
<code>root@oldboy network-scripts$ifdown eth1</code>
本文轉自 xoyabc 51CTO部落格,原文連結:http://blog.51cto.com/xoyabc/1697525,如需轉載請自行聯系原作者