CentOS 7.2 team实现网卡聚合链路(双网卡绑定)脚本及验证

使用team实现网卡聚合链路脚本:

#!/bin/bash
#创建一个名为team0的链路接口
IP=192.168.101.1
GATE=192.168.101.254
ETH1=eno1
ETH2=eno2
#ETH3=eno3
#ETH4=eno4
nmcli con add type team con-name team0 ifname team0 config '{"runner": {"name":"activebackup"}}'
#nmcli con add type team con-name team1 ifname team1 config '{"runner": {"name":"activebackup"}}'
cat < /etc/sysconfig/network-scripts/ifcfg-$ETH1
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=$ETH1
DEVICE=$ETH1
ONBOOT=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
PEERDNS=yes
PEERROUTES=yes
EOF
cat < /etc/sysconfig/network-scripts/ifcfg-$ETH2
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=$ETH2
DEVICE=$ETH2
ONBOOT=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
PEERDNS=yes
PEERROUTES=yes
EOF
cat < /etc/sysconfig/network-scripts/ifcfg-team0
DEVICE=team0
TEAM_CONFIG="{\"runner\": {\"name\":\"activebackup\"}}"
DEVICETYPE=Team
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=team0
ONBOOT=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPADDR=$IP
PREFIX=24
GATEWAY=$GATE
EOF
nmcli connection add type team-slave con-name team0-port1 ifname $ETH1 master team0
nmcli connection add type team-slave con-name team0-port2 ifname $ETH2 master team0
nmcli connection up team0-port2
nmcli connection up team0-port1
reboot


验证:

1.查看team0状态:

[root@localhost ~]# teamdctl team0 state view
setup:
  runner: activebackup
ports:
  eno1
    link watches:
      link summary: up
      instance[link_watch_0]:
        name: ethtool
        link: up
        down count: 0
  eno2
    link watches:
      link summary: up
      instance[link_watch_0]:
        name: ethtool
        link: up
        down count: 0
runner:
  active port: eno1    #当前主接口

2.列出team0端口

[root@localhost ~]# teamnl team0 ports
 3: eno2: up 1000Mbit FD 
 2: eno1: up 1000Mbit FD 

3.测试,宕掉当前主接口,看是否切换

[root@localhost ~]# nmcli device disconnect eno1
Device 'eno1' successfully disconnected.
[root@localhost ~]# teamnl team0 ports
 3: eno2: up 1000Mbit FD 
[root@localhost ~]# teamdctl team0 state view
setup:
  runner: activebackup
ports:
  eno2
    link watches:
      link summary: up
      instance[link_watch_0]:
        name: ethtool
        link: up
        down count: 0
runner:
  active port: eno2  #切换成功

详细了解team,可访问红帽官网

你可能感兴趣的:(linux,openstack)