RHEL7.X雙網卡綁定


       為了提高網絡容錯或吞吐量,一般服務器都會采取多網卡綁定的策略,在RHEL6中使用的是Bonding,而RHEL7提供了一項新的實現技術Teaming,具體原理和對比列表大家可以參考擴展閱讀中的RedHat官方博客。配置Teaming有兩種方式,第一種是使用nmclii命令,第二種是直接修改配置文件。

2.原理

      這里介紹兩種最常見的雙網卡綁定模式:
        (1) roundrobin - 輪詢模式
            所有鏈路處於負載均衡狀態,這種模式的特點增加了帶寬,同時支持容錯能力。
        (2) activebackup - 主備模式
            一個網卡處於活動狀態,另一個處於備份狀態,所有流量都在主鏈路上處理,當活動網卡down掉時,啟用備份網卡 

3.配置

      在RHEL7和Centos7中使用nmtui命令來配置網絡,系統默認使用NetworkManager來提供網絡服務,這是一種動態管理網絡的守護進程,能夠讓網絡設備保持連接狀態。可以使用 nmcli 命令來管理 Network Manager 服務。

[root@localhost ~]# nmtui

 

查看網卡連接信息

[root@localhost ~]# nmcli connection show
NAME    UUID                                  TYPE    DEVICE
virbr0  b286b35c-cb10-4d7c-980c-af2778929b66  bridge  virbr0

 

查看物理網卡信息

[root@localhost ~]# nmcli dev
設備         類型      狀態    CONNECTION
eno16777736  ethernet  已斷開  --        
eno33554960  ethernet  已斷開  --        
lo           loopback  未管理  -- 

 

上面信息可以查看到連接只有virbr0,物理網卡有兩個未連接,首先刪除無用連接

[root@localhost ~]# nmcli connection delete b91bbba9-5019-48a5-a873-5e1b13df2a7d

 

建立兩個連接

[root@localhost ~]# nmcli connection add type ethernet con-name eno16777736 ifname eno16777736
Connection 'eno16777736' (86cc9bf6-5492-4c41-bfd8-ab89cde271e8) successfully added.
[root@localhost ~]# nmcli connection add type ethernet con-name eno33554960 ifname eno33554960
Connection 'eno33554960' (48db52c1-0449-41c8-9a2b-da3951ea4076) successfully added.

 

再次查看連接信息

[root@localhost ~]# nmcli connection show
名稱         UUID                                  類型            設備       
eno33554960  48db52c1-0449-41c8-9a2b-da3951ea4076  802-3-ethernet  eno33554960
eno16777736  86cc9bf6-5492-4c41-bfd8-ab89cde271e8  802-3-ethernet  eno16777736

 

網絡連接和配置文件都成功生成,接下來通過eno33554960和eno16777736使用teaming模式進行雙網卡綁定

 

3.1 roundrobin - 輪詢模式

roundrobin模式也稱為輪詢模式,它 基於每一個包 ,當某一台服務器的兩張網卡設置為roundrobin模式teaming,此時服務器發出的數據包,就會在兩個物理
    網卡上進行輪詢,即第一個數據包走一張網卡,第二個數據包走第二張網卡,依次輪詢。
    注意:
        (1)roundrobin具有容錯性,當一張網卡down掉,數據包依然發送成功。
        (2)在使用roundrobin模式必須要在交換機上做以太通道,不然會出現網絡無法連通。

 

使用nmcli命令操作,創建team接口team0,同時設置teaming模式為roundrobin

[root@localhost ~]# nmcli connection add type team con-name team0 ifname team0 config '{"runner":{"name": "roundrobin"}}'
Connection 'team0' (283eb25f-7212-4cc2-a5b5-85d6aa5f2152) successfully added.

 

給team0設置IP地址,IP模式為手動

[root@localhost ~]# nmcli connection mod team0 ipv4.addresses 192.168.1.20/24 ipv4.gateway 192.168.1.1 ipv4.method manual connectio.autoconnect yes

 

將兩張物理網卡加入到team中

[root@localhost ~]# nmcli connection add type team-slave con-name team0-port1 ifname eno33554960 master team0
Connection 'team0-port1' (96f914fa-f43a-4bc9-8458-10e3923c62f9) successfully added.
[root@localhost ~]# nmcli connection add type team-slave con-name team0-port2 ifname eno16777736 master team0
Connection 'team0-port2' (b1eb81ce-d190-44bb-83a5-deba333fa7b2) successfully added.

 

重新載入連接配置

[root@192 jun]# nmcli connection reload 

 

啟動team0 

[root@192 jun]# nmcli connection up team0
成功激活(主服務器等待從服務器)連接(D-Bus 激活路徑:/org/freedesktop/NetworkManager/ActiveConnection/8)

 

查看狀態

[root@192 jun]# teamdctl team0 state
setup:
runner: activebackup
runner:
active port:

[root@192 jun]# nmcli connection show
名稱 UUID 類型 設備
ens33 f1ce3db1-bea6-44a9-94be-1bc13c1a7a8b 802-3-ethernet ens33
ens38 a2dbd32a-af3f-4c69-82a2-160ae3af95f8 802-3-ethernet ens38
team0 5b68aca4-cd1f-4204-889a-2f7d7467afbc team team0
virbr0 7fbf45c9-eee4-4742-8188-c4c51603f4fa bridge virbr0
team0-port1 027eef4c-52c4-4ce9-a0f0-25acd901beff 802-3-ethernet --
team0-port2 f05ff513-b7de-4729-8b2c-7b886aa22dc6 802-3-ethernet --
[root@192 jun]# nmcli dev

發現發現team0-port1 team0-port2沒有添加成功物理網卡

 

刪除掉沒有添加成功team0-port1 team0-port2兩張網卡

[root@192 jun]# nmcli connection delete team0-port1
成功刪除連接 'team0-port1'(7df353c3-b279-4641-9fb9-b9f6276077d1)。
[root@192 jun]# nmcli connection delete team0-port2
成功刪除連接 'team0-port2'(0cff2fae-5aa0-4158-8bf4-660ab1445399)。

 

刪除兩張物理網卡ens33,ens38

[root@192 jun]# nmcli connection delete ens33 ens38
成功刪除連接 'ens38'(a2dbd32a-af3f-4c69-82a2-160ae3af95f8)。
成功刪除連接 'ens33'(f1ce3db1-bea6-44a9-94be-1bc13c1a7a8b)。

 

再次添加team0-port1 team0-port2兩張網卡

[root@192 jun]# nmcli connection add type team-slave con-name team0-port1 ifname ens33 master team0
連接“team0-port1”(964b7117-a6e6-4d52-a9bf-d12378aa7eae) 已成功添加。
[root@192 jun]# nmcli connection add type team-slave con-name team0-port2 ifname ens38 master team0
連接“team0-port2”(12794ede-75c1-4737-8a46-69738943f4b2) 已成功添加。

 

再次查看狀態

[root@192 jun]# teamdctl team0 state
setup:
runner: activebackup
ports:
ens33
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up
down count: 0
ens38
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up
down count: 0
runner:
active port: ens33

 

3.2 activebackup-主備模式

一個網卡處於活動狀態,另一個處於備份狀態,所有流量都在主鏈路上處理,當活動網卡down掉時,啟用備份網卡。

[root@localhost ~]# nmcli connection add type team con-name team0 ifname team0 config '{"runner":{"name": "activebackup"}}'

其余命令一樣。

 

總結:

知道兩張物理網卡連接名則:

nmcli connection add type team ifname team0 con-name team0 config '{"runner":{"name":"activebackup"}}'

nmcli connection mod team0 ipv4.addresses 192.168.1.20/24 ipv4.gateway 192.168.1.1

nmcli connection modify team0 ipv4.method manual

nmcli connection add type team-slave con-name team0-port1 ifname ens33 master team0

nmcli connection add type team-slave con-name team0-port2 ifname ens38 master team0

systemctl restart network

teamdctl team0 state


免責聲明!

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



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