1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 使用nmcli配置主备模式链路聚合(team端口绑定)

使用nmcli配置主备模式链路聚合(team端口绑定)

时间:2023-08-13 03:12:33

相关推荐

使用nmcli配置主备模式链路聚合(team端口绑定)

现在让我们在CentOS 7中配置网卡绑定,运行ip link命令查看可以使用的网卡

[root@localhost ~]# ip link1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:002: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000link/ether 08:00:27:7b:d3:32 brd ff:ff:ff:ff:ff:ff3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000link/ether 08:00:27:81:d3:be brd ff:ff:ff:ff:ff:ff

在这里使用enp0s3和enp0s8两个网卡配置 主备模式的链路聚合。

创建Team接口

[root@localhost ~]# nmcli connection add type team con-name team0 ifname team0 config '{"runner":{"name":"activebackup"}}' Connection 'team0' (4df78635-b9fc-4539-ab02-27db11c656fe) successfully added.

运行nmcli con show查看team0的配置

[root@localhost ~]# nmcli con showNAMEUUID TYPEDEVICE team04df78635-b9fc-4539-ab02-27db11c656fe teamteam0 enp0s3 5005942f-a7fd-4e55-b8e7-77928d8da72d ethernet enp0s3 Wired connection 1 45dee64a-53b3-3e2a-b2d4-e377f3e668a2 ethernet enp0s8

添加Slave接口

在这里使用enp0s3和enp0s8两个网卡作为team0的slave接口:

[root@localhost ~]# nmcli connection add type team-slave con-name team0-port1 ifname enp0s3 master team0 Connection 'team0-port1' (15183c4a-2053-4b53-ad58-de5a07ae3ae9) successfully added.[root@localhost ~]# nmcli connection add type team-slave con-name team0-port2 ifname enp0s8 master team0Connection 'team0-port2' (a34e20b0-3422-46e5-a947-bb2eaa6c0622) successfully added.

查看端口配置信息:

[root@localhost ~]# nmcli connection show NAMEUUID TYPEDEVICE team04df78635-b9fc-4539-ab02-27db11c656fe teamteam0 enp0s3 5005942f-a7fd-4e55-b8e7-77928d8da72d ethernet enp0s3 Wired connection 1 45dee64a-53b3-3e2a-b2d4-e377f3e668a2 ethernet enp0s8 team0-port1 15183c4a-2053-4b53-ad58-de5a07ae3ae9 ethernet --team0-port2 a34e20b0-3422-46e5-a947-bb2eaa6c0622 ethernet --

分配IP地址

给team0分配一个静态的IP地址并启动team0配置:

[root@localhost ~]# nmcli connection modify team0 ipv4.method manual ipv4.addresses 192.168.0.200/24 ipv4.gateway 192.168.0.1 ipv4.dns 202.102.128.68# nmcli connection down team0 关闭接口[root@localhost ~]# nmcli connection up team0 Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4)

查看连接配置信息,发现team0-port1没有绑定在enp0s3这个网卡接口上

这是因为ifcfg-team0-port1配置文件和ifcfg-enp0s3配置文件都设置为开机启动了

所以我们需要关闭enp0s3的开机启动,在这里我们把enp0s3和Wired connection 1这两个配置都关掉开机启动。

[root@localhost ~]# nmcli connection modify enp0s3 autoconnect no[root@localhost ~]# nmcli connection modify Wired\ connection\ 1 autoconnect no

然后重启一下网络服务,查看链接配置:

[root@localhost ~]# systemctl restart network[root@localhost ~]# nmcli connection[root@localhost ~]# ip ad

可以看到team0-port1和team0-port2都绑定在对应的网卡上面了,team0的ip地址显示的是手动设置的192.168.0.200

验证

查看team0的状态:

[root@localhost ~]# teamdctl team0 statesetup:runner: activebackupports:enp0s3link watches:link summary: upinstance[link_watch_0]:name: ethtoollink: updown count: 0enp0s8link watches:link summary: upinstance[link_watch_0]:name: ethtoollink: updown count: 0runner:active port: enp0s8

现在活动的端口是enp0s8,我们断开这个端口,看一下主备模式配置是否工作:

[root@localhost ~]# nmcli device disconnect enp0s8 Device 'enp0s8' successfully disconnected.[root@localhost ~]# teamdctl team0 statesetup:runner: activebackupports:enp0s3link watches:link summary: upinstance[link_watch_0]:name: ethtoollink: updown count: 0runner:active port: enp0s3

看到活动接口切换到enp0s3上面了。

其他team端口聚合模式

##配置为主备模式,类似于bond的mode=1nmcli connection add type team ifname team0 con-name team0 config ‘{“runner”: {“name”: “activebackup”}}’##配置为通过802.3ad模式的lacp,需要交换机做lacp绑定,类似于bond的mode=4nmcli connection add type team ifname team0 con-name team0 config ‘{“runner”: {“name”: “lacp”}}’##广播方式,流量通过所有team接口随机发出,类似于bond的mode=3nmcli connection add type team ifname team0 con-name team0 config ‘{“runner”: {“name”: “broadcast”}}’##轮循方式,数据包按照顺序挨个从team接口发出,类似于bond的mode=0nmcli connection add type team ifname team0 con-name team0 config ‘{“runner”: {“name”: “roundrobin”}}’##负载均衡方式,根据负载均衡算法,选择不通的端口发包nmcli connection add type team ifname team0 con-name team0 config ‘{“runner”: {“name”: “loadbalance”}}’

其他相关知识点

参考了牛人的总结:/duzhaoqi/p/7491761.html

关于网络接口命名

CentOS 6之前,网络接口使用连续号码命名: eth0、 eth1等,当增加或删除网卡时,名称可能会发生变化。CentOS 7使用基于硬件,设备拓扑和设置类型命名。

网卡命名机制

systemd对网络设备的命名方式

(a) 如果Firmware或BIOS为主板上集成的设备提供的索引信息可用,且可预测则根据此索引进行命名,例如eno1(b) 如果Firmware或BIOS为PCI-E扩展槽所提供的索引信息可用,且可预测,则根据此索引进行命名,例如ens1(c) 如果硬件接口的物理位置信息可用,则根据此信息进行命名,例如enp2s0(d) 如果用户显式启动,也可根据MAC地址进行命名,enx2387a1dc56(e) 上述均不可用时,则使用传统命名机制

网卡名称

(1)基于BIOS支持启用biosdevname软件

内置网卡: em1,em2pci卡: pYpX Y:slot ,X:port

(2) 名称组成格式

en: Ethernet 有线局域网wl: wlan 无线局域网ww: wwan无线广域网

名称类型:

o<index>: 集成设备的设备索引号s<slot>: 扩展槽的索引号x<MAC>: 基于MAC地址的命名p<bus>s<slot>: enp2s1

网卡设备的命名过程

第一步:

udev, 辅助工具程序/lib/udev/rename_device根据/usr/lib/udev/rules.d/60-net.rules

第二步:

biosdevname 会根据/usr/lib/udev/rules.d/71-biosdevname.rules

第三步:

通过检测网络接口设备,根据/usr/lib/udev/rules.d/75-net-descriptionID_NET_NAME_ONBOARDID_NET_NAME_SLOTID_NET_NAME_PATH

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。