linux 7使用team配置双网卡绑定,CentOS7配置双网卡绑定

  • Post author:
  • Post category:linux


配置team0配置文件:

[root@CentOS7 ~]# cat /etc/sysconfig/network-scripts/ifcfg-team0

DEVICE=team0

DEVICETYPE=Team

ONBOOT=yes

BOOTPROTO=none

IPADDR=192.168.1.71

PREFIX=24

GATEWAY=192.168.1.1

TEAM_CONFIG='{“runner”: {“name”: “activebackup”}, “link_watch”: {“name”: “ethtool”}}’

配置eno33554984 :

[root@CentOS7 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eno33554984

EEVICE=eno33554984

DEVICETYPE=TeamPort

ONBOOT=yes

TEAM_MASTER=team0

TEAM_PORT_CONFIG='{“prio”: 100}’

配置eno50332208 :

[root@CentOS7 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eno50332208

DEVICE=eno50332208

DEVICETYPE=TeamPort

ONBOOT=yes

TEAM_MASTER=team0

TEAM_PORT_CONFIG='{“prio”: 99}’

重启网络:

[root@CentOS7 network-scripts]# systemctl restart network

查看端口状态:

[root@CentOS7 network-scripts]# teamnl team0 ports

4: eno50332208: up 1000Mbit FD

3: eno33554984: up 1000Mbit FD

查看team状态:

[root@CentOS7 network-scripts]# teamdctl team0 state

setup:

runner: activebackup

ports:

eno50332208

link watches:

link summary: up

instance[link_watch_0]:

name: ethtool

link: up

down count: 0

eno33554984

link watches:

link summary: up

instance[link_watch_0]:

name: ethtool

link: up

down count: 0

runner:

active port: eno33554984

模拟网卡故障:

[root@CentOS7 ~]# ip link set eno33554984 down

查看team状态:

[root@CentOS7 ~]# teamdctl team0 state

setup:

runner: activebackup

ports:

eno33554984

link watches:

link summary: down

instance[link_watch_0]:

name: ethtool

link: down

down count: 1

eno50332208

link watches:

link summary: up

instance[link_watch_0]:

name: ethtool

link: up

down count: 0

runner:

active port: eno50332208

一键配置脚本:

#!/bin/bash

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