您好,登錄后才能下訂單哦!
本篇內(nèi)容主要講解“Centos7/RHEL7雙網(wǎng)卡怎么綁定”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來(lái)帶大家學(xué)習(xí)“Centos7/RHEL7雙網(wǎng)卡怎么綁定”吧!
1. 簡(jiǎn)要
雙網(wǎng)卡綁定技術(shù)在centos7中使用了teaming技術(shù),而在rhel6/centos7中使用的是bonding技術(shù),在centos7中雙網(wǎng)卡綁定既能使用teaming也可以使用bonding,這里推薦使用teaming技術(shù),方便與查看和監(jiān)控。
2. 原理
這里介紹兩種最常見(jiàn)的雙網(wǎng)卡綁定模式:
(1) roundrobin - 輪詢模式
所有鏈路處于負(fù)載均衡狀態(tài),這種模式的特點(diǎn)增加了帶寬,同時(shí)支持容錯(cuò)能力。
(2) activebackup - 主備模式
一個(gè)網(wǎng)卡處于活動(dòng)狀態(tài),另一個(gè)處于備份狀態(tài),所有流量都在主鏈路上處理,當(dāng)活動(dòng)網(wǎng)卡down掉時(shí),啟用備份網(wǎng)卡。
3. 基礎(chǔ)環(huán)境
系統(tǒng):centos7
在centos7中,關(guān)閉虛擬機(jī)添加網(wǎng)卡,再開(kāi)啟虛擬機(jī),系統(tǒng)是不會(huì)自動(dòng)生成網(wǎng)卡的配置文件:
在centos7中要生成網(wǎng)卡配置文件的方法很簡(jiǎn)單,使用如下命令:
# 查看物理網(wǎng)卡信息 [root@localhost ~]# nmcli dev device type state connection eno16777736 ethernet connected eno16777736 eno33554984 ethernet connected wired connection 1 eno50332208 ethernet connected wired connection 2 lo loopback unmanaged --
上面的信息可以看到,一共有四張網(wǎng)卡,其中l(wèi)o是本地回環(huán)網(wǎng)卡,另外三張為物理網(wǎng)卡。
# 查看網(wǎng)卡連接信息 [root@localhost ~]# nmcli con sh name uuid type device wired connection 2 9a1314bf-d273-406a-930a-dc4160dee4ec 802-3-ethernet eno50332208 wired connection 1 47eef4a3-7fa4-4a73-83ef-1485bda9b950 802-3-ethernet eno33554984 eno16777736 51d00668-2cf5-41da-ad8d-5019d62e98ad 802-3-ethernet eno16777736
上面的信息可以查看到一共有3個(gè)連接,其中兩個(gè)有線連接,表示沒(méi)有設(shè)置過(guò)的網(wǎng)卡連接,還有一個(gè)enoxx連接。接下來(lái)要修改兩個(gè)有線連接的命名方法,并生成網(wǎng)卡配置文件:
# 首先,刪除兩個(gè)無(wú)用的有線連接 [root@localhost ~]# nmcli con del 9a1314bf-d273-406a-930a-dc4160dee4ec connection 'wired connection 2' (9a1314bf-d273-406a-930a-dc4160dee4ec) successfully deleted. [root@localhost ~]# nmcli con del 47eef4a3-7fa4-4a73-83ef-1485bda9b950 connection 'wired connection 1' (47eef4a3-7fa4-4a73-83ef-1485bda9b950) successfully deleted.
# 再次創(chuàng)建新的連接并生成配置文件 [root@localhost ~]# nmcli conn add type ethernet con-name eno50332208 ifname eno50332208 connection 'eno50332208' (eea2a115-63f8-4f33-be84-12559f02542c) successfully added. [root@localhost ~]# nmcli conn add type ethernet con-name eno33554984 ifname eno33554984 connection 'eno33554984' (32d2389e-4e82-4419-9d18-5aff8f0be003) successfully added.
# 最后,查看下 [root@localhost ~]# nmcli con sh name uuid type device eno16777736 51d00668-2cf5-41da-ad8d-5019d62e98ad 802-3-ethernet eno16777736 eno33554984 32d2389e-4e82-4419-9d18-5aff8f0be003 802-3-ethernet eno33554984 eno50332208 eea2a115-63f8-4f33-be84-12559f02542c 802-3-ethernet eno50332208 [root@localhost ~]# ll /etc/sysconfig/network-scripts/ifcfg-eno* -rw-r--r--. 1 root root 394 nov 26 05:59 /etc/sysconfig/network-scripts/ifcfg-eno16777736 -rw-r--r--. 1 root root 288 dec 26 08:44 /etc/sysconfig/network-scripts/ifcfg-eno33554984 -rw-r--r--. 1 root root 288 dec 26 08:44 /etc/sysconfig/network-scripts/ifcfg-eno50332208
網(wǎng)絡(luò)連接和配置文件都成功生成了。 接下來(lái)通過(guò)eno33554984 和 eno50332208 使用teaming模式進(jìn)行雙網(wǎng)卡綁定
4. roundrobin模式:
roundrobin模式也稱為輪詢模式,它 基于每一個(gè)包 ,當(dāng)某一臺(tái)服務(wù)器的兩張網(wǎng)卡設(shè)置為roundrobin模式teaming,此時(shí)服務(wù)器發(fā)出的數(shù)據(jù)包,就會(huì)在兩個(gè)物理網(wǎng)卡上進(jìn)行輪詢,即第一個(gè)數(shù)據(jù)包走一張網(wǎng)卡,第二個(gè)數(shù)據(jù)包走第二張網(wǎng)卡,依次輪詢。
注意:
(1)roundrobin具有容錯(cuò)性,當(dāng)一張網(wǎng)卡down掉,數(shù)據(jù)包依然發(fā)送成功。
(2)在使用roundrobin模式必須要在交換機(jī)上做以太通道,不然會(huì)出現(xiàn)網(wǎng)絡(luò)無(wú)法連通。
實(shí)際操作:
# 使用nmcli命令操作,創(chuàng)建team接口team0,同時(shí)設(shè)置teaming模式為roundrobin [root@localhost ~]# nmcli con add type team con-name team0 ifname team0 config '{"runner":{"name": "roundrobin"}}' connection 'team0' (9dc48bd6-54b9-48db-b7dd-ecf34ae9196f) successfully added.
# 給接口team0設(shè)置ip地址 [root@localhost ~]# nmcli con modify team0 ipv4.address '10.0.0.2/24' ipv4.gateway '10.0.0.1' # 設(shè)置為手動(dòng)模式,取消dhcp [root@localhost ~]# nmcli con modify team0 ipv4.method manual
# 將兩張物理網(wǎng)卡加入到team中 [root@localhost ~]# nmcli con add type team-slave con-name team0-port1 ifname eno33554984 master team0 connection 'team0-port1' (22d3640e-f5c8-499c-b0dd-913c8970d800) successfully added. [root@localhost ~]# nmcli con add type team-slave con-name team0-port2 ifname eno50332208 master team0 connection 'team0-port2' (12660d2a-0e1f-41e6-96b2-53de4fc6b78c) successfully added. [root@localhost ~]# nmcli con sh name uuid type device team0-port2 12660d2a-0e1f-41e6-96b2-53de4fc6b78c 802-3-ethernet -- eno16777736 51d00668-2cf5-41da-ad8d-5019d62e98ad 802-3-ethernet eno16777736 team0-port1 22d3640e-f5c8-499c-b0dd-913c8970d800 802-3-ethernet -- team0 9dc48bd6-54b9-48db-b7dd-ecf34ae9196f team team0 eno33554984 32d2389e-4e82-4419-9d18-5aff8f0be003 802-3-ethernet eno33554984 eno50332208 eea2a115-63f8-4f33-be84-12559f02542c 802-3-ethernet eno50332208
# 查看team0的狀態(tài) [root@localhost ~]# teamdctl team0 st setup: runner: roundrobin
4.1 roundrobin問(wèn)題排查
第一次查看出現(xiàn)的是這樣的結(jié)果,檢查下配置:
# 通過(guò)直接查看網(wǎng)卡發(fā)現(xiàn)team0并沒(méi)有啟動(dòng) [root@localhost ~]# ip a | grep team0 5: team0: <no-carrier,broadcast,multicast,up> mtu 1500 qdisc noqueue state down # 使用ifup 啟動(dòng)team0并沒(méi)有成功,繼續(xù)排查 [root@localhost ~]# ifup team0 [root@localhost ~]# ip a | grep team0 5: team0: <no-carrier,broadcast,multicast,up> mtu 1500 qdisc noqueue state down
直接sysetmctl restart network 也沒(méi)有成功。
# 發(fā)現(xiàn)team0-port1 team0-port2沒(méi)有添加成功物理網(wǎng)卡,怎么回事呢? [root@localhost ~]# nmcli con sh name uuid type device team0-port2 ec96c1e1-d268-4ba1-a2f9-0133a9f02655 802-3-ethernet -- eno16777736 51d00668-2cf5-41da-ad8d-5019d62e98ad 802-3-ethernet eno16777736 team0-port1 22d3640e-f5c8-499c-b0dd-913c8970d800 802-3-ethernet -- team0 9dc48bd6-54b9-48db-b7dd-ecf34ae9196f team team0 eno33554984 32d2389e-4e82-4419-9d18-5aff8f0be003 802-3-ethernet eno33554984 eno50332208 eea2a115-63f8-4f33-be84-12559f02542c 802-3-ethernet eno50332208
# 刪除掉 [root@localhost ~]# nmcli con del team0-port1 connection 'team0-port1' (22d3640e-f5c8-499c-b0dd-913c8970d800) successfully deleted. [root@localhost ~]# nmcli con del team0-port2 connection 'team0-port2' (ec96c1e1-d268-4ba1-a2f9-0133a9f02655) successfully deleted. # 刪除兩張物理網(wǎng)卡的連接 [root@localhost ~]# nmcli con sh name uuid type device eno16777736 51d00668-2cf5-41da-ad8d-5019d62e98ad 802-3-ethernet eno16777736 team0 9dc48bd6-54b9-48db-b7dd-ecf34ae9196f team team0 eno33554984 32d2389e-4e82-4419-9d18-5aff8f0be003 802-3-ethernet eno33554984 eno50332208 eea2a115-63f8-4f33-be84-12559f02542c 802-3-ethernet eno50332208 [root@localhost ~]# nmcli con del eno33554984 eno50332208 connection 'eno33554984' (32d2389e-4e82-4419-9d18-5aff8f0be003) successfully deleted. connection 'eno50332208' (eea2a115-63f8-4f33-be84-12559f02542c) successfully deleted. # 刪除成功 [root@localhost ~]# nmcli con sh name uuid type device eno16777736 51d00668-2cf5-41da-ad8d-5019d62e98ad 802-3-ethernet eno16777736 team0 9dc48bd6-54b9-48db-b7dd-ecf34ae9196f team team0
# 再次將兩張物理網(wǎng)卡添加到team [root@localhost ~]# nmcli con add type team-slave con-name team0-port1 ifname eno33554984 master team0 connection 'team0-port1' (0331ea43-95c0-4106-b388-8484d4c3940d) successfully added. [root@localhost ~]# nmcli con add type team-slave con-name team0-port2 ifname eno50332208 master team0 connection 'team0-port2' (880f2146-fe93-42dd-8d28-7d0dd50b4011) successfully added. [root@localhost ~]# nmcli con sh name uuid type device team0-port1 0331ea43-95c0-4106-b388-8484d4c3940d 802-3-ethernet eno33554984 eno16777736 51d00668-2cf5-41da-ad8d-5019d62e98ad 802-3-ethernet eno16777736 team0 9dc48bd6-54b9-48db-b7dd-ecf34ae9196f team team0 team0-port2 880f2146-fe93-42dd-8d28-7d0dd50b4011 802-3-ethernet eno50332208
現(xiàn)在成功將兩張物理網(wǎng)卡綁定到了team組中
# 現(xiàn)在查看team0的狀態(tài)就出現(xiàn)了,模式是:roundrobin [root@localhost ~]# teamdctl team0 st setup: runner: roundrobin ports: eno33554984 link watches: link summary: up instance[link_watch_0]: name: ethtool link: up down count: 0 eno50332208 link watches: link summary: up instance[link_watch_0]: name: ethtool link: up down count: 0
這樣,team模式的roundrobin搭建成功。
總結(jié):
在做鏈路聚合的時(shí)候,所要使用到的物理網(wǎng)卡不能獨(dú)立存在連接,也就是在nmcli con sh查看時(shí),不能獨(dú)立存在,否則就無(wú)法綁定到team模式中。
4.2 測(cè)試
因?yàn)檫@里是虛擬機(jī)環(huán)境,只能通過(guò)down掉網(wǎng)卡進(jìn)行查看。
[root@localhost ~]# teamdctl team0 st setup: runner: roundrobin ports: eno33554984 link watches: link summary: up instance[link_watch_0]: name: ethtool link: up down count: 0 eno50332208 link watches: link summary: up instance[link_watch_0]: name: ethtool link: up down count: 0
兩張網(wǎng)卡同時(shí)在線,現(xiàn)在down掉其中一張網(wǎng)卡,
[root@localhost ~]# nmcli con del team0-port1 connection 'team0-port1' (0331ea43-95c0-4106-b388-8484d4c3940d) successfully deleted. [root@localhost ~]# nmcli con sh name uuid type device eno16777736 51d00668-2cf5-41da-ad8d-5019d62e98ad 802-3-ethernet eno16777736 team0 9dc48bd6-54b9-48db-b7dd-ecf34ae9196f team team0 team0-port2 880f2146-fe93-42dd-8d28-7d0dd50b4011 802-3-ethernet eno50332208 [root@localhost ~]# teamdctl team0 st setup: runner: roundrobin ports: eno50332208 link watches: link summary: up instance[link_watch_0]: name: ethtool link: up down count: 0
這樣就發(fā)現(xiàn)eno33554984網(wǎng)卡已經(jīng)down掉了。
[root@localhost ~]# nmcli con add type team-slave con-name team0-port1 ifname eno33554984 master team0 connection 'team0-port1' (59acd6bf-affc-4994-a050-83c45816859a) successfully added. [root@localhost ~]# [root@localhost ~]# teamdctl team0 st setup: runner: roundrobin ports: eno33554984 link watches: link summary: up instance[link_watch_0]: name: ethtool link: up down count: 0 eno50332208 link watches: link summary: up instance[link_watch_0]: name: ethtool link: up down count: 0
虛擬機(jī)環(huán)境就這樣測(cè)試了吧,至于生產(chǎn)環(huán)境就直接拔網(wǎng)線,ping測(cè)試。
資料有說(shuō)linux下roundrobin具有容錯(cuò)的效果,為了測(cè)試是否有容錯(cuò)的效果,虛擬機(jī)做了下更改來(lái)驗(yàn)證:
這一次網(wǎng)卡全部改成橋接模式,為了更好的測(cè)試是否具有容錯(cuò)性。
roundrobin已經(jīng)配置完畢。接下來(lái)我們down掉一張網(wǎng)卡檢查是否具有容錯(cuò)性。
通過(guò)虛擬機(jī)測(cè)試,容錯(cuò)性是存在的。
5. 雙網(wǎng)卡綁定activebackup的實(shí)現(xiàn)
[root@localhost ~]# nmcli con sh name uuid type device team0-port2 2a1aa534-e021-4452-bb0a-2002dabcbc08 802-3-ethernet eno50332208 team0-port1 9a10c9ef-ee9c-4151-9a47-59b4668e8934 802-3-ethernet -- eno16777736 51d00668-2cf5-41da-ad8d-5019d62e98ad 802-3-ethernet eno16777736 team0 c2278f3f-5c6b-4e1d-b925-514d3c3832b6 team team0 [root@localhost ~]# nmcli con del team0 team0-port1 team0-port2 connection 'team0' (c2278f3f-5c6b-4e1d-b925-514d3c3832b6) successfully deleted. connection 'team0-port1' (9a10c9ef-ee9c-4151-9a47-59b4668e8934) successfully deleted. connection 'team0-port2' (2a1aa534-e021-4452-bb0a-2002dabcbc08) successfully deleted. [root@localhost ~]# nmcli con sh name uuid type device eno16777736 51d00668-2cf5-41da-ad8d-5019d62e98ad 802-3-ethernet eno16777736 # 以上操作就刪除了roundrobin模式,恢復(fù)到初始狀態(tài)。
# 添加邏輯網(wǎng)卡team0,并啟用activebackup模式 [root@localhost ~]# nmcli con add type team con-name team0 ifname team0 config '{"runner":{"name":"activebackup"}}' connection 'team0' (f0794e59-419d-4c2a-96b9-464610b6321a) successfully added. # 綁定ip [root@localhost ~]# nmcli con modify team0 ipv4.address 192.168.118.122/24 ipv4.gateway 192.168.118.1 [root@localhost ~]# nmcli con modify team0 ipv4.method manual # 添加物理網(wǎng)卡到activebackup模式 [root@localhost ~]# nmcli con add type team-slave con-name team0-port1 ifname eno33554984 master team0 connection 'team0-port1' (52656904-6e85-4a04-98b4-2b19773fa290) successfully added. [root@localhost ~]# nmcli con add type team-slave con-name team0-port2 ifname eno50332208 master team0 connection 'team0-port2' (44d96e3a-014a-481f-9122-4ca2d3be9f7a) successfully added.
[root@localhost ~]# teamdctl team0 st setup: runner: activebackup ports: eno33554984 link watches: link summary: up instance[link_watch_0]: name: ethtool link: up down count: 0 eno50332208 link watches: link summary: up instance[link_watch_0]: name: ethtool link: up down count: 0 runner: active port: eno33554984
成功,處于活動(dòng)中的網(wǎng)卡為 eno33554984
5.1 測(cè)試
通過(guò)down掉活動(dòng)網(wǎng)卡測(cè)試網(wǎng)絡(luò)是否仍然處于連通狀態(tài)
測(cè)試成功。
注意: 在做網(wǎng)卡綁定的時(shí)候,如果發(fā)現(xiàn)物理網(wǎng)卡總是無(wú)法綁定到team0,請(qǐng)檢查該物理網(wǎng)卡是否處于up狀態(tài)。
到此,相信大家對(duì)“Centos7/RHEL7雙網(wǎng)卡怎么綁定”有了更深的了解,不妨來(lái)實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。