云网牛站
所在位置:首页 > Linux教程 > 在CentOS/RHEL 8上配置Network Teaming网络组

在CentOS/RHEL 8上配置Network Teaming网络组

2019-03-27 09:56:35作者:连一续稿源:云网牛站

本文介绍在CentOS/RHEL 8操作系统上配置Network Teaming网络组的方法,也可称为NIC组合。

 

在RHEL/CentOS 8上配置network teaming daemon

要安装teamd,请在终端中输入以下命令:

sudo dnf -y install teamd

运行rpm -qi teamd命令查看安装的teamd版本:

在CentOS/RHEL 8上配置Network Teaming网络组

 

使用nmcli配置network teaming

参考:Linux上使用ifconfig、ip、netstat、nmcli命令查找可用的网络接口

首先,确定将用作从属的网络接口:

# ip link  show

 1: lo:  mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000

  link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

 2: enp1s0:  mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000

  link/ether 52:54:00:8f:8c:86 brd ff:ff:ff:ff:ff:ff

 3: enp7s0:  mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000

  link/ether 52:54:00:74:99:a9 brd ff:ff:ff:ff:ff:ff

 4: enp8s0:  mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000

  link/ether 52:54:00:2b:db:9c brd ff:ff:ff:ff:ff:ff

由于我在RHEL/CentOS 8服务器机器上运行NetworkManager(参考:使用NetworkManager随机化MAC地址的方法),我将使用nmcli网络管理工具:

# nmcli connection show

在CentOS/RHEL 8上配置Network Teaming网络组

对于我的设置,我将使用两个网络设备:enp7s0和enp8s0,在开始配置之前,请删除与nmcli的连接:

在CentOS/RHEL 8上配置Network Teaming网络组

这两个设备现在应处于断开连接状态:

$ nmcli device status

在CentOS/RHEL 8上配置Network Teaming网络组

创建新的team接口,名称为team0:

$ nmcli connection add type team con-name team0 ifname team0 \

 config '{ "runner": {"name": "loadbalance"}, "link_watch": {"name": "ethtool"}}'

你可以使用activebackup、broadcast、lacp、random、roundrobin命令替换loadbalance。

NetworkManager会将配置文件写入/etc/sysconfig/network-scripts/ifcfg-team-team0,要查看分配的其他值,请运行:

$ nmcli con show team0

使用以下命令查看刚配置的Team接口:

$ nmcli con show

在CentOS/RHEL 8上配置Network Teaming网络组

为team接口分配IP地址、DNS和自动连接:

nmcli con mod team0 ipv4.addresses 192.168.121.10/24

nmcli con mod team0 ipv4.gateway 192.168.121.1

nmcli con mod team0 ipv4.dns 8.8.8.8

nmcli con mod team0 ipv4.method manual

nmcli con mod team0 connection.autoconnect yes

将Network Slave添加到team中:

nmcli con add type team-slave con-name team0-slave0 ifname enp7s0 master team0

nmcli con add type team-slave con-name team0-slave1 ifname enp8s0 master team0

样本输出如下:

Connection 'team0-slave0' (daa6fc23-cdef-40b1-9b9d-5157d6ff3910) successfully added.

Connection 'team0-slave1' (a20cf7ee-fb08-4270-a6e7-b6e20cb490dc) successfully added.

确认连接:

在CentOS/RHEL 8上配置Network Teaming网络组

重新启动连接:

nmcli connection down team0 && nmcli connection up team0

应该看到分配的IP信息了:

$ ip addr show  dev  team0

 8: team0:  mtu 1500 qdisc noqueue state UP group default qlen 1000

  link/ether 52:54:00:74:99:a9 brd ff:ff:ff:ff:ff:ff

  inet 192.168.121.10/24 brd 192.168.121.255 scope global noprefixroute team0

  valid_lft forever preferred_lft forever

  inet6 fe80::4c51:96b:c24e:ede9/64 scope link noprefixroute 

  valid_lft forever preferred_lft forever

$ ping -c 1 192.168.121.1

PING 192.168.121.1 (192.168.121.1) 56(84) bytes of data.

64 bytes from 192.168.121.1: icmp_seq=1 ttl=64 time=0.134 ms

--- 192.168.121.1 ping statistics ---

1 packets transmitted, 1 received, 0% packet loss, time 0ms

rtt min/avg/max/mdev = 0.134/0.134/0.134/0.000 ms

也可以使用teamdctl检查team状态:

$ teamdctl team0 state

setup:

runner: loadbalance

ports:

enp7s0

link watches:

link summary: up

instance[link_watch_0]:

name: ethtool

link: up

down count: 0

enp8s0

link watches:

link summary: up

instance[link_watch_0]:

name: ethtool

link: up

down count: 0

 

使用nmcli删除Team

运行nmcli connection show命令显示连接:

在CentOS/RHEL 8上配置Network Teaming网络组

Bring down team连接:

nmcli connection down team0

删除slaves:

$ nmcli connection delete team0-slave0 team0-slave1

Connection 'team0-slave0' (daa6fc23-cdef-40b1-9b9d-5157d6ff3910) successfully deleted.

Connection 'team0-slave1' (a20cf7ee-fb08-4270-a6e7-b6e20cb490dc) successfully deleted.

删除team created:

$ nmcli connection delete team0

Connection 'team0' (f763a709-3956-497f-b92c-5c06f848bee7) successfully deleted.

确认删除:

$ nmcli connection show

在CentOS/RHEL 8上配置Network Teaming网络组

 

使用ifcfg文件创建Network Team

要使用ifcfg文件创建Network Team,请在/etc/sysconfig/network-scripts/目录中创建一个文件,如下所示:

$ cat /etc/sysconfig/network-scripts/ifcfg-team0

DEVICE=team0

NAME=team0

DEVICETYPE=Team

ONBOOT=yes

BOOTPROTO=none

IPADDR=192.168.121.10

PREFIX=24

GATEWAY=192.168.121.1

TEAM_CONFIG='{"runner": {"name": "activebackup"}, "link_watch": {"name": "ethtool"}}'

要创建一个端口作为team0的member,请在/etc/sysconfig/network-scripts/目录中创建一个或多个文件,如下所示:

$ cat /etc/sysconfig/network-scripts/ifcfg-team0-slave0

NAME=team0-slave0

DEVICE=enp7s0

ONBOOT=yes

TEAM_MASTER=team0

DEVICETYPE=TeamPort

$ cat /etc/sysconfig/network-scripts/ifcfg-team0-slave1

NAME=team0-slave1

DEVICE=enp8s0

ONBOOT=yes

TEAM_MASTER=team0

DEVICETYPE=TeamPort

启动team interface:

$ sudo ip link set enp7s0 down

$ sudo ip link set enp8s0 down

$ sudo ifup team0

列出team端口:

$ teamnl team0 ports

4: enp8s0: up 4294967295Mbit FD 

3: enp7s0: up 4294967295Mbit FD

 

附:关于管理managing Team的主要说明

在CentOS/RHEL 8上配置Network Teaming网络组

 

相关主题

使用nmcli连接到Linux系统中的OpenVPN Server

精选文章
热门文章