首頁 > 軟體

Linux下快速設定ip bond

2020-06-16 18:04:53

在計算機網路普及的初期,很多OS系統都使用的為單網絡卡方式,即一個網絡卡使用一個IP地址。隨著網路要求的不斷提高,我們可以對多個網絡卡進行系結聚合當一個邏輯網路介面來使用,從而大幅提升伺服器的網路吞吐(I/O),同時也可以根據不同的場景和需求來設定其系結模式。本文簡要描述一下其設定過程。

1. 編輯ifcfg-bond0檔案
###本文演示環境CentOS release 5.11,對eth0以及eth1進行bond
# vi /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0             
BOOTPROTO=static
IPADDR=192.168.9.33     
NETMASK=255.255.255.0
BROADCAST=192.168.9.255
GATEWAY=192.168.9.250
ONBOOT=yes
TYPE=Ethernet

2. 編輯eth0、eth1檔案
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
### Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet
DEVICE=eth0
BOOTPROTO=none
HWADDR=xx:xx:xx:xx:xx:xx  #此處為對應的mac地址
ONBOOT=yes
MASTER=bond0
SLAVE=yes

# vi /etc/sysconfig/network-scripts/ifcfg-eth1
### Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet
DEVICE=eth1
BOOTPROTO=none
HWADDR=xx:xx:xx:xx:xx:xx
ONBOOT=yes
HOTPLUG=no
MASTER=bond0
SLAVE=yes

3. 編輯modprobe.conf檔案
# vi /etc/modprobe.conf
新增:
alias bond0 bonding
options bond0 miimon=100 mode=0

說明:
1).miimon=100 用來設定鏈路監測的間隔時間。即每100ms監測一次鏈路狀態。bonding只監測主機與交換機之間鏈路。如果交換機出去的鏈路出問題而本身沒有問題,那麼bonding認為鏈路沒有問題而繼續使用。
2).mode=1 表示提供冗餘功能。除此之外還可以為0、2、3,共四種模式。0表示負載均衡
3).更詳細的可參考:深度分析Linux下雙網絡卡系結七種模式  http://www.linuxidc.com/Linux/2014-10/107515.htm

4. 重新啟動網路
# service network restart

5. 驗證
通過其它機器ping 係結的ip,ping的過程中拔掉eth0或eth1網線,確認網路是否持續正常

###參考如下的驗證為啟動bond後的結果
# less /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.4.0-2 (October 7, 2008)

Bonding Mode: load balancing (round-robin)
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: 44:a8:42:0b:a7:a5

Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 44:a8:42:0b:a7:a6

###檢視當前主機的IP設定資訊
# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
      valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 qlen 1000
    link/ether 44:a8:42:0b:a7:a5 brd ff:ff:ff:ff:ff:ff
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 qlen 1000
    link/ether 44:a8:42:0b:a7:a5 brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop qlen 1000
    link/ether 44:a8:42:0b:a7:a7 brd ff:ff:ff:ff:ff:ff
5: eth3: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 44:a8:42:0b:a7:a8 brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.15/24 brd 192.168.10.255 scope global eth3
6: sit0: <NOARP> mtu 1480 qdisc noop
    link/sit 0.0.0.0 brd 0.0.0.0
7: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue
    link/ether 44:a8:42:0b:a7:a5 brd ff:ff:ff:ff:ff:ff
    inet 192.168.9.33/24 brd 192.168.9.255 scope global bond0
    inet6 fe80::46a8:42ff:fe0b:a7a5/64 scope link
      valid_lft forever preferred_lft forever


IT145.com E-mail:sddin#qq.com