linux虛擬網絡接口---bonding配置

 在平常生活中,你們會遇到這種狀況,在家裏能夠自動獲取ip地址,上班的時候公司可能會禁網,因此會提供一個私網地址供你們使用,可是須要你們手鍊接網絡,比較麻煩。這就須要爲設備配置兩套方案,設置一個網絡接口來回切換,就會很方便了。vim

1、首先了解一下bonding的定義centos

        bonding是經過將同一設備的多個物理網卡綁定到一個虛擬網卡上,再對外提供鏈接。對於外端來講,多個物理網卡共享虛擬網卡的IP和mac地址,也就表現爲一個網卡設備。經過bonding技術能夠實現高可用或者負載均衡。網絡

bonding的工做模式:負載均衡

       Mode 0    輪轉策略:從頭至尾順序的在每個slave接口上面發送數據包。本模式提供負載均衡和容錯的能力
       Mode 1 (active-backup)活動-備份(主備)策略:只有一個slave被激活,當且僅當活動的slave接口失敗時纔會激活其餘slave。 爲了不交換機發生混亂此時綁定的MAC地址只有一個外部端口上可見
       Mode 3 (broadcast)廣播策略:在全部的slave接口上傳送全部的報文,提供容錯能力
工具

2、Bonding的配置(centos6)oop

1.手工添加2塊網卡,並設置到同一個vmnet中(vmnet3)。用ifconfig查看兩個網卡是否加入進去性能

[root@centos6 network-scripts]#ifconfig
 eth2 Link encap:Ethernet HWaddr 00:0C:29:8F:26:2A UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500  Metric:1 RX packets:546 errors:0 dropped:0 overruns:0 frame:0 TX packets:13 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:164116 (160.2 KiB)  TX bytes:938 (938.0 b) eth3 Link encap:Ethernet HWaddr 00:0C:29:8F:26:2A UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500  Metric:1 RX packets:552 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:164476 (160.6 KiB)  TX bytes:0 (0.0 b) lo Link encap:Local Loopback inet addr:127.0.0.1  Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536  Metric:1 RX packets:4 errors:0 dropped:0 overruns:0 frame:0 TX packets:4 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:240 (240.0 b)  TX bytes:240 (240.0 b)

2.建立bonding設備bond0的配置文件centos7

[root@centos6 ~]# cd /etc/sysconfig/network-scripts/ [root@centos6 network-scripts]# cp ifcfg-eth0 ifcfg-bond0
[root@centos6 network-scripts]# vim ifcfg-bond0 
 DEVICE=bond0 ONBOOT=yes BONDING_OPTS="miimon=100 mode=1" IPADDR=10.8.8.8 NETMASK=255.255.255.0 NM_CONTROLLED=no

      miimon 是用來進行鏈路監測的。若是miimon=100,那麼系統每100ms 監測一次鏈路鏈接狀態,若是有一條線路不通就轉入另外一條線路spa

      mode 是bonding的模式3d

3.配置slave的配置文件

[root@centos6 network-scripts]# cp ifcfg-eth0 ifcfg-eth2
 [root@centos6 network-scripts]# vim ifcfg-eth2 
 DEVICE=eth2 TYPE=Ethernet ONBOOT=yes SLAVE=yes MASTER=bond0 NM_CONTROLLED=no [root@centos6 network-scripts]# cp ifcfg-eth0 ifcfg-eth3
 [root@centos6 network-scripts]# vim ifcfg-eth3 
 DEVICE=eth3 TYPE=Ethernet ONBOOT=yes SLAVE=yes MASTER=bond0 NM_CONTROLLED=no

4.重啓網絡服務

[root@centos6 network-scripts]# service network restart

5.查看bonding的狀態

[root@centos6 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: eth2 MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0 Slave Interface: eth2 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:8f:26:2a Slave queue ID: 0 Slave Interface: eth3 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:8f:26:20 Slave 

5. 更改bond0工做模式

    直接修改bond0配置文件中的mode,重啓網絡服務便可

6.如何刪除bond0(先關再刪)

[root@centos6 network-scripts]#ifconfig bond0 down
 [root@centos6 network-scripts]#rm –f ifcfg-bond0

  刪除eth2裏面的master,及slave

3、centos7的bonding配置(centos7中的補齊命令比centos6更強)

1.加2個網卡,在同一個vmnet中。

2.使用nmcli管理工具

1)建立邏輯網卡bond0

[root@centos7 network-scripts]#nmcli con add type bond con-name bond0 ifname bond0 mode active-backup
 Connection 'bond0' (c505387c-6f85-4af5-bf50-7958d8cf39ef) successfully added.

#add 至關與自動生成配置文件

[root@centos7 network-scripts]#nmcli con modify bond0 ipv4.addresses 20.20.20.20/24 ipv4.dns 8.8.8.8 ipv4.gateway 20.20.20.1 ipv4.method manual connection.autoconnect yes;--設定bond0 ip

2)添加從屬網路接口(增長slave的方案給兩塊新加的網卡)

[root@centos7 network-scripts]# nmcli connection add con-name slave-38 ifname ens38 type ethernet master bond0 
 Connection 'slave-38' (97708606-56ac-48aa-9014-c23a376c2379) successfully added. [root@centos7 network-scripts]# nmcli connection add con-name slave-39 ifname ens39 type ethernet master bond0 
 Connection 'slave-39' (608dc1a0-9407-45be-a720-4c415b4b8488) successfully added.

3.直接激活bond0

[root@centos7  network-scripts]# nmcli connection up bond0

4.更改bond0模式

[root@centos7network-scripts]# nmcli connection modify bond0 mode broadcast

5.刪除同centos6

4、建立網絡組Networking Teaming實現相似功能

網絡組:是將多個網卡聚合在一塊兒方法,從而實現冗錯和提升吞吐量。但網絡組不一樣於舊版中bonding技術,提供更好的性能和擴展性。

1.建立網絡組team0

[root@centos7 network-scripts]# nmcli connection add type team con-name team0 ifname team0 config '{"runner": {"name": "loadbalance"}}'
 Connection 'team0' (9a5ab96b-3cd3-412d-9532-1327c035367c) successfully added.

2.添加從屬網路接口

[root@centos7 network-scripts]# nmcli connection add con-name slave-38 ifname ens38 type team-slave master team0
 Connection 'slave-38' (e5182e70-86a6-480f-bc14-2d2055bfab9f) successfully added. [root@centos7 network-scripts]# nmcli connection add con-name slave-39 ifname ens39 type team-slave master team0
 Connection 'slave-39' (e31b4880-0095-4322-af49-63094bbe873d) successfully added.

3.設置team0的ip

[root@centos7 network-scripts]# nmcli connection modify team0 ipv4.method manual ipv4.addresses 20.20.20.20/24 connection.autoconnect yes 

4.激活team0及slave

[root@centos7 network-scripts]# nmcli connection up team0
 Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/13) [root@centos7 network-scripts]# nmcli connection up slave-38
 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/16) [root@centos7 network-scripts]# nmcli connection up slave-39
 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/18)

5.刪除team0

[root@centos7 network-scripts]# nmcli connection down team0
 Connection 'team0' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/13) [root@centos7 network-scripts]# nmcli connection down slave-38
 Connection 'slave-38' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/16) [root@centos7 network-scripts]# nmcli connection down slave-39
 Connection 'slave-39' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/19) [root@centos7 network-scripts]# rm -f ifcfg-slave-3*
 [root@centos7 network-scripts]# rm -f ifcfg-team0 

實驗:使用nmcli爲網卡配置2套方案,一個Dhcp一個靜態獲取

1.改舊方案的名稱(非必須)

[root@centos7 network-scripts]# nmcli connection modify ens34 connection.id home

2.將home的方案設置的自動獲取ipv4地址

[root@centos7network-scripts]#nmcli connection modify home ipv4.method auto

3.使方案生效

[root@centos7 network-scripts]#nmcli connection up home
 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/9)

查看方案

[root@centos7 network-scripts]# nmcli connection show 
NAME UUID TYPE DEVICE ens33 dadb8960-c959-47f5-addb-13f8e439d72d ethernet ens33 home 482d5ab5-ac7d-4467-ac09-65440b174331 ethernet ens34 virbr0 1eee137a-f1ea-4fe8-b387-5d0561d76aca  bridge    virbr0

4.新增方案名爲office

[root@centos7 network-scripts]# nmcli connection add con-name office type ethernet ifname ens34

5.爲新增的方案進行配置靜態地址

[root@centos7 network-scripts]# nmcli connection modify office ipv4.method manual connection.autoconnect yes ipv4.addresses 8.8.8.8/24 ipv4.gateway 8.8.8.1 ipv4.dns 4.4.4.4

6.切換到新方案,使之生效

[root@centos7 network-scripts]# nmcli connection up office

查看方案

[root@centos7 network-scripts]# nmcli connection show 
NAME UUID TYPE DEVICE ens33 dadb8960-c959-47f5-addb-13f8e439d72d ethernet ens33 office 482d5ab5-ac7d-4467-ac09-65440b174331 ethernet ens34 virbr0 1eee137a-f1ea-4fe8-b387-5d0561d76aca bridge virbr0 home2ae365b6-ab9a-4882-8831-e38a362881e2  ethernet  --

若是手工修改了配置文件,以下

[root@centos7 network-scripts]# vim /etc/sysconfig/network-scripts/ifcfg-office
IPADDR=8.8.8.8 PREFIX=24 GATEWAY=8.8.8.1 DNS1=4.4.4.4

則須要使用nmcli connection reload來重讀後纔可以nmcli connection up

刪除方案

[root@centos7 network-scripts]# nmcli connection delete office
相關文章
相關標籤/搜索