借助于网卡绑定技术,不仅可以提高网络传输速度,更重要的是,还可以确保在其中一块网卡出现故障时,依然可以正常提供网络服务。

双网卡绑定技术在centos7中使用了teaming技术,而在rhel6/centos7中使用的是bonding技术,在centos7中双网卡绑定既能使用teaming也可以使用bonding,这里推荐使用teaming技术,方便与查看和监控。

两种最常见的双网卡绑定模式:

  (1) roundrobin - 轮询模式

    所有链路处于负载均衡状态,这种模式的特点增加了带宽,同时支持容错能力。

  (2) activebackup - 主备模式

    一个网卡处于活动状态,另一个处于备份状态,所有流量都在主链路上处理,当活动网卡down掉时,启用备份网卡。

在虚拟机系统中再添加一块网卡设备,请确保两块网卡都处在同一个网络连接中(即网卡模式相同)。处于相同模式的网卡设备才可以进行网卡绑定,否则这两块网卡无法互相传送数据。

1.生成网络连接和配置文件:在centos7中,关闭虚拟机添加网卡,再开启虚拟机,系统是不会自动生成网卡的配置文件:

  1)nmcli dev:查看物理网卡信息  

[root@localhost network-scripts]# nmcli dev
DEVICE      TYPE      STATE      CONNECTION         
virbr0      bridge    connected  virbr0             
ens33       ethernet  connected  ens33              
ens37       ethernet  connected  Wired connection 1 
lo          loopback  unmanaged  --                 
virbr0-nic  tun       unmanaged  --                 

  nmcli connection show:查看网卡连接信息  

[root@localhost network-scripts]# nmcli connection show
NAME                UUID                                  TYPE            DEVICE 
Wired connection 1  8a06d1d5-18c2-3cb0-b2a4-d318aedde9aa  802-3-ethernet  ens37  
ens33               5daa0579-8f5c-408f-b0a7-24a64ea73a60  802-3-ethernet  ens33  
virbr0              bfb37186-ac0f-437f-9713-f6f307485e8e  bridge          virbr0 
Wired connection 1 表示没有设置过的有线网卡连接。接下来要修改这个有线连接的命名方法,并生成网卡配置文件:
2)nmcli connection delete UUID:删除网卡连接
[root@localhost network-scripts]# nmcli connection delete 8a06d1d5-18c2-3cb0-b2a4-d318aedde9aa 
Connection 'Wired connection 1' (8a06d1d5-18c2-3cb0-b2a4-d318aedde9aa) successfully deleted.

  3)再次创建新的连接并生成配置文件  

nmcli connection add type ethernet con-name ens37 ifname ens37:
[root@localhost network-scripts]# nmcli connection add type ethernet con-name ens37 ifname ens37
Connection 'ens37' (ab73ab8c-8f3f-4823-960d-b7c1d93c92b7) successfully added.  
[root@localhost network-scripts]# nmcli connection show 
NAME    UUID                                  TYPE            DEVICE 
ens33   5daa0579-8f5c-408f-b0a7-24a64ea73a60  802-3-ethernet  ens33  
ens37   ab73ab8c-8f3f-4823-960d-b7c1d93c92b7  802-3-ethernet  ens37  
virbr0  bfb37186-ac0f-437f-9713-f6f307485e8e  bridge          virbr0 

  两个网络连接和配置文件都生成了,接下来使用teaming模式进行双网卡绑定

2.roundrobin模式:也称为轮询模式,它 基于每一个包 ,当某一台服务器的两张网卡设置为roundrobin模式teaming,此时服务器发出的数据包,就会在两个物理网卡上进行轮询,即第一个数据包走一张网卡,第二个数据包走第二张网卡,依次轮询。

  注意:

        (1)roundrobin具有容错性,当一张网卡down掉,数据包依然发送成功。

        (2)在使用roundrobin模式必须要在交换机上做以太通道,不然会出现网络无法连通。

   1)使用nmcli命令操作,创建team接口team0,同时设置teaming模式为roundrobin  

[root@localhost network-scripts]# nmcli connection add type team con-name team0 ifname  team0 config '{"runner":{"name": "roundrobin"}}'
Connection 'team0' (8f7276a7-8963-49a3-b918-adf281cc2f1d) successfully added.   
[root@localhost network-scripts]# vim ifcfg-team0 
DEVICE=team0
TEAM_CONFIG="{\"runner\":{\"name\": \"roundrobin\"}}"
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=team0
UUID=8f7276a7-8963-49a3-b918-adf281cc2f1d
ONBOOT=yes
DEVICETYPE=Team

2)给接口team0设置ip地址

  dhcp:  

[root@localhost network-scripts]# nmcli connection modify team0 ipv4.method auto  
[root@localhost network-scripts]# vim ifcfg-team0
DEVICE=team0
TEAM_CONFIG="{\"runner\":{\"name\": \"roundrobin\"}}"
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=team0
UUID=98fd527f-c8d6-4e93-8304-24c8d6a6e52f
ONBOOT=yes
DEVICETYPE=Team

  手动:  

[root@localhost network-scripts]# nmcli connection modify team0 ipv4.addresses '10.10.64.9/24' ipv4.gateway '10.10.64.1'
[root@localhost network-scripts]# nmcli connection modify team0 ipv4.method manual
[root@localhost network-scripts]# vim ifcfg-team0
DEVICE=team0
TEAM_CONFIG="{\"runner\":{\"name\": \"roundrobin\"}}"
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=team0
UUID=98fd527f-c8d6-4e93-8304-24c8d6a6e52f
ONBOOT=yes
DEVICETYPE=Team
IPADDR=10.10.64.9
PREFIX=24
GATEWAY=10.10.64.1

  3)将两张物理网卡加入到team中  

[root@localhost network-scripts]#  nmcli con add type team-slave con-name team0-port1 ifname ens33 master team0
Connection 'team0-port1' (45741585-4f7a-40a9-9339-3a6292c6cebf) successfully added.
[root@localhost network-scripts]# 
[root@localhost network-scripts]#  nmcli con add type team-slave con-name team0-port2 ifname ens37 master team0
Connection 'team0-port2' (e3ea758c-9064-449a-bb8a-4e080e74c163) successfully added. 
[root@localhost network-scripts]# nmcli connection show 
NAME         UUID                                  TYPE            DEVICE 
ens33        5daa0579-8f5c-408f-b0a7-24a64ea73a60  802-3-ethernet  ens33  
ens37        a7918f7e-dd10-4ce2-83b7-47e0f30f4386  802-3-ethernet  ens37  
team0        8f6fa8f1-7832-4d9c-8cb6-935bdfc0ec3f  team            team0  
virbr0       2fb7c674-1630-4d66-85a6-db0c241cbafa  bridge          virbr0 
team0-port1  ebd04d0c-e434-4a5c-b147-79a8f200bb62  802-3-ethernet  --     
team0-port2  b9e7201c-7a2a-458c-bcb5-f2e8e6c2551f  802-3-ethernet  --    

 查看team0的状态:  

[root@localhost network-scripts]# teamdctl team0 state
setup:
  runner: roundrobin

  4)roundrobin问题排查

  通过直接查看网卡发现team0并没有启动  

[root@localhost network-scripts]# ip addr | grep team0
6: team0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN qlen 1000

  使用ifup 启动team0和sysetmctl restart network也都不成功

  发现team0-port1 team0-port2没有添加成功物理网卡  

[root@localhost network-scripts]# nmcli connection show 
NAME         UUID                                  TYPE            DEVICE 
ens33        5daa0579-8f5c-408f-b0a7-24a64ea73a60  802-3-ethernet  ens33  
ens37        a7918f7e-dd10-4ce2-83b7-47e0f30f4386  802-3-ethernet  ens37  
team0        8f6fa8f1-7832-4d9c-8cb6-935bdfc0ec3f  team            team0  
virbr0       2fb7c674-1630-4d66-85a6-db0c241cbafa  bridge          virbr0 
team0-port1  ebd04d0c-e434-4a5c-b147-79a8f200bb62  802-3-ethernet  --     
team0-port2  b9e7201c-7a2a-458c-bcb5-f2e8e6c2551f  802-3-ethernet  --    

  删除team0-port1 team0-port2以及两张物理网卡的连接  

[root@localhost network-scripts]# nmcli connection delete ens33 ens37 team0-port1 team0-port2

(process:49282): libnm-WARNING **: no object known for /org/freedesktop/NetworkManager/ActiveConnection/6

Connection 'ens33' (5daa0579-8f5c-408f-b0a7-24a64ea73a60) successfully deleted.
Connection 'team0-port1' (ebd04d0c-e434-4a5c-b147-79a8f200bb62) successfully deleted.
Connection 'ens37' (a7918f7e-dd10-4ce2-83b7-47e0f30f4386) successfully deleted.
Connection 'team0-port2' (b9e7201c-7a2a-458c-bcb5-f2e8e6c2551f) successfully deleted.
[root@localhost network-scripts]# 
[root@localhost network-scripts]# nmcli connection show 
NAME                UUID                                  TYPE            DEVICE 
Wired connection 1  d554b158-bbf6-3819-a19b-7391061b067f  802-3-ethernet  ens33  
team0               8f6fa8f1-7832-4d9c-8cb6-935bdfc0ec3f  team            team0  
virbr0              2fb7c674-1630-4d66-85a6-db0c241cbafa  bridge          virbr0 
[root@localhost network-scripts]# 
[root@localhost network-scripts]# nmcli connection delete d554b158-bbf6-3819-a19b-7391061b067f 
Connection 'Wired connection 1' (d554b158-bbf6-3819-a19b-7391061b067f) successfully deleted.
[root@localhost network-scripts]# 
[root@localhost network-scripts]# nmcli connection show 
NAME    UUID                                  TYPE    DEVICE 
team0   8f6fa8f1-7832-4d9c-8cb6-935bdfc0ec3f  team    team0  
virbr0  2fb7c674-1630-4d66-85a6-db0c241cbafa  bridge  virbr0 

  再次将两张物理网卡添加到team  

[root@localhost network-scripts]# nmcli connection add type team-slave con-name team0-port1 ifname ens33 master team0
Connection 'team0-port1' (c2d4edbf-5cb1-4e04-8359-3925bce440f1) successfully added.
[root@localhost network-scripts]# nmcli connection add type team-slave con-name team0-port2 ifname ens37 master team0
Connection 'team0-port2' (4818e0f2-420c-481e-b235-83c69be4c5b7) successfully added.  
[root@localhost network-scripts]# nmcli connection show 
NAME         UUID                                  TYPE            DEVICE 
team0        8f6fa8f1-7832-4d9c-8cb6-935bdfc0ec3f  team            team0  
team0-port1  c2d4edbf-5cb1-4e04-8359-3925bce440f1  802-3-ethernet  ens33  
team0-port2  4818e0f2-420c-481e-b235-83c69be4c5b7  802-3-ethernet  ens37  
virbr0       2fb7c674-1630-4d66-85a6-db0c241cbafa  bridge          virbr0 

  此时查看team0的状态  

[root@localhost network-scripts]# teamdctl team0 state
setup:
  runner: roundrobin
ports:
  ens33
    link watches:
      link summary: up
      instance[link_watch_0]:
        name: ethtool
        link: up
        down count: 0
  ens37
    link watches:
      link summary: up
      instance[link_watch_0]:
        name: ethtool
        link: up
        down count: 0  

这样,team模式的roundrobin搭建成功。

总结:

在做链路聚合的时候,所要使用到的物理网卡不能独立存在连接,也就是在nmcli con sh查看时,不能独立存在,否则就无法绑定到team模式中

 

posted on 2020-09-02 17:37  星痕1216  阅读(621)  评论(0编辑  收藏  举报