首頁 > 運維 > linux運維 > 主體

關於網路介面配置Bonding的實例教程

PHP中文网
發布: 2017-06-21 13:46:03
原創
2265 人瀏覽過

Bonding

就是講到快網卡綁定到同一IP位址對外服務,可以實現高可用或負載平衡。當然,直接為兩塊網卡設定相同IP位址是不可能的。透過bonding,虛擬一塊網卡對外提供連接,實體網卡修改為同一MAC位址。

一Bonding 的工作模式

    Mode 0 (balance-rr)

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

    Mode 1 (active-backuop)

活動-備份(主備)策略:在綁定中,只有一個slave被激活,當且僅活動的slave介面失敗是才會激活其他的slave。為了避免交換器發生混亂此時綁定的MAC位址只有一個外部連接埠上可見。

    Mode 3 (broadcast)

廣播策略:在所有的slave介面上傳送所有的封包。本模式提供容錯能力。

二Bonding設定

#1 建立bonding裝置的設定檔

[root@CentOS68 ~]# vim /etc/sysconfig/network-scripts/ifcfg-bond0
登入後複製

DEVICE=bond0

BOOTPROTO=none

BONDING_OPTS="miimon=100 mode=0"

IPADDR=200.200.200.200

PREFIX= 24

GATEWAY=200.200.200.1

miimon是設定偵測連結的時間,單位為毫秒。如果miimon=100,那麼系統每100毫秒偵測一側連結的連接狀態,如果有一條線路不通就轉入另一條線路。

mode用來指定模式

2 建立slave的設定檔

既就是要加入的網卡的設定文件,這裡使用eth1、eth2兩塊網路卡,下來修改兩塊網路卡的設定

[root@CentOS68 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth1
登入後複製

DEVICE=eth1

TYPE=Ethernet

BOOTPROTO=none

MASTER=bond0

SLAVE=yes

USERCTL=0

MASTER指定測網卡屬於哪個bond。 SLAVE指定從屬關係。 USERCTL指定使用者是否有控制權限。

eth2和eth1配置類似

[root@CentOS68 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth2
登入後複製

DEVICE=eth2

TYPE=Ethernet

BOOTPROTO=none

MASTER=bond0

SLAVE=yes

USERCTL=0

3 重新啟動網路服務

[root@CentOS68 ~]# service NetworkManager stop #centos6上不稳定,建议关闭
[root@CentOS68 ~]# service network restart
登入後複製

Shutting down interface bond0: [ OK ]

##Shutting down interface eth0: [ OK ]

Shutting down loopback interface: [ OK ]

Bringing up loopback interface: [ OK ]

Bringing up interface bond0: Determining if ip address 200.200.200.200 is already in use for device bond0...

[ OK ]

Bringing up interface bond0...

[ OK ]

Bringing up interface eth0: Deter

#[ OK ]

Bringing up interface eth0: Deter

#。 if ip address 192.168.29.68 is already in use for device eth0...
[ OK ]

 

#可以看到已經啟動成功,再來看下IP位址和MAC

[root@CentOS68 ~]# ip a
登入後複製

[……]

7: eth1: mtu 1500 qdisc pfifo_fast master bond0 state UP qgt; mtu 1500 qdisc pfifo_fast master bond0 state UP qlen 1000

link/ether 00:0c:29:74:74:45 brd ff:ff:ff:ff:ff:ff

8: eth2: mtu 1500 qdisc pfifo_fast master bond0 state UP qlen 1000

link/ether 00:0c:29:74:74:45 brd ff:ff:ff:ff:ff:ff

9: bond0: mtu 1500 qdisc noqueue state UP

#link/ether 00:0c:29:74:74:45 brd ff#link/ether 00:0c:29:74:74:45 brd ff#link/ether:ff. :ff:ff:ff

inet 200.200.200.200/24 brd 200.200.200.255 scope global bond0

inet6 fe80::20c:29ff:fe74:745/64 #valid_lft forever preferred_lft forever

可以看到IP位址已經生效,並且MAC位址都相同。

4 看bond0的狀態

[root@CentOS68 ~]# cat /proc/net/bonding/bond0
登入後複製

Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

# Bonding Mode: load balancing (round-robin)

MII Status: up

MII Polling Interval (ms): 100

#Up Delay (ms): 0

Down Delay (ms): 0

Slave Interface: eth1

MII Status: up

Speed: 1000 Mbps

Duplex: full

Link Failure Count: 0

Permanent HW addr: 00:0c:29:74:74:45

Slave queue ID: 0

#Slave Interface : eth2

MII Status: up

Speed: 1000 Mbps

Duplex: full

Link Failure Count: 0

Permanent HW addr: 00:0c:29:74:74:4fSlave queue ID: 0

好了,一切都很順利

#5 刪除bond
###
[root@CentOS68 ~]# ifconfig bond0 down

[root@CentOS68 ~]# rmmod bonding
登入後複製
######看下是否刪除成功,######
[root@CentOS68 ~]# ifconfig bond0
登入後複製
###

bond0: error fetching interface information: Device not found

已经找不到bond0,说明删除成功。

详细帮助:/etc/share/doc/kernel-doc-version/Documentation/networking/bonding.txt

三 nmcli实现bonding

1 添加bonding接口

[root@centos7 ~]# nmcli connection add type bond con-name mybond0 ifname bond0 mode active-backup
登入後複製

Connection 'mybond0' (cc101e79-3dcb-49ee-8164-89c9e877c315) successfully added.

2添加从属接口

[root@centos7 ~]# nmcli connection add type bond-slave ifname ens34 master mybond0
登入後複製

Connection 'bond-slave-ens34' (9c8ff11a-72ef-4d63-a950-2ab777d2a1ea) successfully added.

[root@centos7 ~]# nmcli connection add type bond-slave ifname ens38 master mybond0
登入後複製

Connection 'bond-slave-ens38' (c40b3e6f-32f4-4d1a-a323-aed2519cf865) successfully added.

注意:如没有指定从属接口连接名,则该名称是接口名称加类型构成

3 启动从属接口

[root@centos7 ~]# nmcli connection up bond-slave-ens34
登入後複製

Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/40)

[root@centos7 ~]# nmcli connection up bond-slave-ens38
登入後複製

Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/41)

4 启动bonding 绑定

[root@centos7 ~]# nmcli connection up mybond0
登入後複製

Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/48)

5 查看绑定

[root@centos7 ~]# nmcli connection show
登入後複製

NAME UUID TYPE DEVICE

bond-slave-ens34 9c8ff11a-72ef-4d63-a950-2ab777d2a1ea 802-3-ethernet ens34

bond-slave-ens38 c40b3e6f-32f4-4d1a-a323-aed2519cf865 802-3-ethernet ens38

mybond0 cc101e79-3dcb-49ee-8164-89c9e877c315 bond bond0

6 添加IP地址

[root@centos7 ~]# nmcli connection modify mybond0 ipv4.method manual ipv4.addresses 200.1.1.1/24
登入後複製

7 删除bond绑定

(1)关闭bond

[root@centos7 ~]# nmcli connection down mybond0
登入後複製

Connection 'mybond0' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/18)

[root@centos7 ~]#

(2)删除bond

[root@centos7 ~]# nmcli connection delete mybond0
登入後複製

Connection 'mybond0' (9ed2f027-bbb1-44d1-87fc-7f7275d7fe70) successfully deleted.

(3)删除从属接口

[root@centos7 ~]# nmcli connection delete bond-slave-ens34
登入後複製

Connection 'bond-slave-ens34' (a46ad620-d4b5-43f9-a73a-447785504a17) successfully deleted.

[root@centos7 ~]# nmcli connection delete bond-slave-ens38

Connection 'bond-slave-ens38' (66b1f44d-ad71-4576-8061-f6cba2b976e8) successfully deleted.

 

好了

以上是關於網路介面配置Bonding的實例教程的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!