網卡接口配置——bonding

Bonding就是將多塊網卡綁定同一IP地址對外提供服務,可以實現高可用或者負載均衡。當然,直接給兩塊網卡設置同一IP地址是不可能的。通過bonding,虛擬一塊網卡對外提供連接,物理網卡的被修改爲相同的MAC地址。

一、Bonding的常用工作模式

Mode 0 (balance-rr)

輪轉( Round-robin)策略:從頭到尾順序的在每一個slave接口上面發送數據包。本模式提供負載均衡和容錯的能力。

Mode 1 (active-backup)

活動-備份(主備)策略:在綁定中,只有一個slave被激活。當且僅當活動的slave接口失敗時纔會激活其他slave。爲了避免交換機發生混亂此時綁定的MAC地址只有一個外部端口上可見。

Mode 3 (broadcast)

廣播策略:在所有的slave接口上傳送所有的報文。本模式提供容錯能力。

二、Bonding配置

創建bonding設備的配置文件:

#vim /etc/sysconfig/network-scripts/ifcfg-bond0

DEVICE=bond0

BOOTPROTO=none

BONDING_OPTS=“miimon=100 mode=0”

#vim /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0

BOOTPROTO=none

MASTER=bond0

SLAVE=yes

USERCTL=no

說明:miimon是用來進行鏈路監測的。如果miimon=100,那麼系統每100ms 監測一次鏈路連接狀態,如果有一條線路不通就轉入另一條線路

查看bond0狀態cat /proc/net/bonding/bond

關於bonding的詳細配置請參照:

/usr/src/linux-3.18.41/Documentation/networking/bonding.txt

三、bonding實驗演示

步驟1:首先確定自己的操作系統是否支持bonding

[root@CentOS6 ~]# modinfo bonding
filename:       /lib/modules/2.6.32-642.el6.x86_64/kernel/drivers/net/bonding/bonding.ko
author:         Thomas Davis, [email protected] and many others
description:    Ethernet Channel Bonding Driver, v3.7.1
version:        3.7.1
...

如果沒有消息返回,說明內核不支持bonding,需要重新編譯內核。

步驟2:創建bonding配置文件

[root@CentOS network-scripts]# cat ifcfg-bond0 
DEVICE=bond0
BOOTPROTO=none
IPADDR=192.168.1.9
GATEWAY=192.168.1.1
PREFIX=24
DNS1=8.8.8.8
BONDING_OPTS="miimon=100 mode=1"

步驟3:修改網卡配置文件

[root@CentOS network-scripts]# cat ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
[root@CentOS network-scripts]# cat ifcfg-eth1
DEVICE=eth1
BOOTOPRO=none
MASTER=bond0
SLAVE=yes

步驟4:重啓網絡服務

[root@CentOS network-scripts]# service network restart
Shutting down interface bond0:
...

步驟5:查看配置情況

[root@CentOS network-scripts]# ifconfig
bond0     Link encap:Ethernet  HWaddr 00:0C:29:30:84:C4  
          inet addr:192.168.1.9  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe30:84c4/64 Scope:Link
          UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1
          RX packets:1000 errors:0 dropped:0 overruns:0 frame:0
          TX packets:488 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:82884 (80.9 KiB)  TX bytes:56939 (55.6 KiB)

eth0      Link encap:Ethernet  HWaddr 00:0C:29:30:84:C4  
          UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:1095 errors:0 dropped:0 overruns:0 frame:0
          TX packets:677 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:95368 (93.1 KiB)  TX bytes:75001 (73.2 KiB)

eth1      Link encap:Ethernet  HWaddr 00:0C:29:30:84:C4  
          UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:243 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:14734 (14.3 KiB)  TX bytes:614 (614.0 b)
...


[root@CentOS network-scripts]# cat /proc/net/bonding/bond0 
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: 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:30:84:c4
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:30:84:ce
Slave queue ID: 0

步驟6:測試

8c206d556336b6d2.png


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