一. 网络分组(Team)的配置
网络分组(Team)的运行模式,如下所示:
运行模式 | 描述 |
---|---|
循环(roundrobin) | 依次通过所有端口传输数据。 |
活动备份(activebackup) | 通过一个端口传输数据,而其他端口则作为备份保留。 |
负载均衡(loadbalance) | 使用主动 Tx 负载均衡和基于 Berkeley 数据包过滤器 (BPF) 的 Tx 端口选择器在所有端口上传输数据。 |
随机(random) | 在随机选择的端口上传输数据。 |
LACP(lacp) | 实施 802.3ad 链路聚合控制协议 (LACP)。 |
广播(broadcast) | 通过所有端口传输数据。 |
显示网络设备
[root@rhel7 ~]# nmcli device
DEVICE TYPE STATE CONNECTION
eth0 ethernet connected System eth0
lo loopback unmanaged --
或
[root@rhel7 ~]# nmcli connection show
NAME UUID TYPE DEVICE
System eth0 97ea747c-bdb5-4007-83ee-84913a7c6fad ethernet eth0
删除现有网络连接
[root@rhel7 ~]# nmcli connection delete enp1s0
添加一个新的团队设备(team0,可以修改成其它的名字,看你喜好)
[root@rhel7 ~]# nmcli connection add type team con-name team0 ifname team0 config '{"runner": {"name": "roundrobin"}}'
Connection 'team0' (e0967a5e-fbd2-47c8-b779-1417db1e04ea) successfully added.
添加设备到组队设备
[root@rhel7 ~]# nmcli connection add type team-slave con-name team0-member0 ifname ens256 master team0
Connection 'team0-member0' (e0717622-19a7-4365-a494-d6630027b521) successfully added.
[root@rhel7 ~]# nmcli connection add type team-slave con-name team0-member1 ifname ens224 master team0
Connection 'team0-member1' (f1b3589a-39c3-49e4-b6fb-f7796f6a5669) successfully added.
[root@rhel7 ~]# nmcli device
DEVICE TYPE STATE CONNECTION
eth0 ethernet connected System eth0
ens256 ethernet connected Wired connection 1
ens224 ethernet connected Wired connection 2
team0 team connecting (getting IP configuration) team0
lo loopback unmanaged
设置团队设备的IP地址等参数
# IP地址
root@rhel7 ~]# nmcli connection modify team0 ipv4.addresses 10.255.255.30/24
#网关
[root@rhel7 ~]# nmcli connection modify team0 ipv4.gateway 10.255.255.1
#DNS (需要设置多个DNS服务器,以空格分隔)
[root@rhel7 ~]# nmcli connection modify team0 ipv4.dns "10.255.255.222 10.255.255.223"
#IP获取方式设置成手动
nmcli connection modify team0 ipv4.method manual
#关闭端口并重新启用端口
nmcli connection down team0 && nmcli connection up team0
#查看team组的组队状态
[root@rhel7 ~]# teamdctl team0 state
setup:
runner: roundrobin
#查看端口的IP信息
[root@rhel7 ~]# ip address
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens256: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:50:56:88:3c:57 brd ff:ff:ff:ff:ff:ff
inet6 fe80::f2a0:644c:7dde:84d4/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: ens224: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:50:56:88:6f:31 brd ff:ff:ff:ff:ff:ff
inet6 fe80::8cb5:569b:39c0:8570/64 scope link noprefixroute
valid_lft forever preferred_lft forever
4: team0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 6a:ad:72:94:c1:0d brd ff:ff:ff:ff:ff:ff
inet 10.255.255.30/24 brd 10.255.255.255 scope global noprefixroute team0
valid_lft forever preferred_lft forever
#查看端口的配置文件的路径和配置文件
[root@rhel7 network-scripts]# ls
ifcfg-eth0 ifcfg-team0-member1 ifdown-ib ifdown-post ifdown-Team ifup-aliases ifup-ippp ifup-plusb ifup-sit ifup-wireless
ifcfg-lo ifdown ifdown-ippp ifdown-ppp ifdown-TeamPort ifup-bnep ifup-ipv6 ifup-post ifup-Team init.ipv6-global
ifcfg-team0 ifdown-bnep ifdown-ipv6 ifdown-routes ifdown-tunnel ifup-eth ifup-isdn ifup-ppp ifup-TeamPort network-functions
ifcfg-team0-member0 ifdown-eth ifdown-isdn ifdown-sit ifup ifup-ib ifup-plip ifup-routes ifup-tunnel network-functions-ipv6
[root@rhel7 network-scripts]# cat ifcfg-team0
TEAM_CONFIG="{\"runner\": {\"name\": \"roundrobin\"}}"
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
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=e0967a5e-fbd2-47c8-b779-1417db1e04ea
DEVICE=team0
ONBOOT=yes
DEVICETYPE=Team
IPADDR=10.255.255.30
PREFIX=24
GATEWAY=10.255.255.1
DNS1=10.255.255.222
DNS2=10.255.255.223
[root@rhel7 network-scripts]# cat ifcfg-team0-member0
NAME=team0-member0
UUID=e0717622-19a7-4365-a494-d6630027b521
DEVICE=ens256
ONBOOT=yes
TEAM_MASTER=team0
DEVICETYPE=TeamPort
[root@rhel7 network-scripts]# cat ifcfg-team0-member1
NAME=team0-member1
UUID=f1b3589a-39c3-49e4-b6fb-f7796f6a5669
DEVICE=ens224
ONBOOT=yes
TEAM_MASTER=team0
DEVICETYPE=TeamPort
删除网络组
#关闭端口
[root@rhel7 network-scripts]# nmcli connection down team0
Connection 'team0' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/6)
#查看端口列表
[root@rhel7 network-scripts]# nmcli c s
NAME UUID TYPE DEVICE
System eth0 97ea747c-bdb5-4007-83ee-84913a7c6fad ethernet eth0
Wired connection 1 0911dc61-1ab9-3ac8-abfa-fd72cf032a5e ethernet ens256
Wired connection 2 eda4adb2-d0e3-37d8-8938-219367c32fd8 ethernet ens224
team0 e0967a5e-fbd2-47c8-b779-1417db1e04ea team --
team0-member0 e0717622-19a7-4365-a494-d6630027b521 ethernet --
team0-member1 f1b3589a-39c3-49e4-b6fb-f7796f6a5669 ethernet --
#删除team组的子网口
[root@rhel7 network-scripts]# nmcli connection delete team0-member0
Connection 'team0-member0' (e0717622-19a7-4365-a494-d6630027b521) successfully deleted.
[root@rhel7 network-scripts]# nmcli connection delete team0-member1
Connection 'team0-member1' (f1b3589a-39c3-49e4-b6fb-f7796f6a5669) successfully deleted.
[root@rhel7 network-scripts]# nmcli c s
NAME UUID TYPE DEVICE
System eth0 97ea747c-bdb5-4007-83ee-84913a7c6fad ethernet eth0
Wired connection 1 0911dc61-1ab9-3ac8-abfa-fd72cf032a5e ethernet ens256
Wired connection 2 eda4adb2-d0e3-37d8-8938-219367c32fd8 ethernet ens224
team0 e0967a5e-fbd2-47c8-b779-1417db1e04ea team --
#删除team0
[root@rhel7 network-scripts]# nmcli con delete team0
Connection 'team0' (e0967a5e-fbd2-47c8-b779-1417db1e04ea) successfully deleted.
#查看端口列表
[root@rhel7 network-scripts]# nmcli c s
NAME UUID TYPE DEVICE
System eth0 97ea747c-bdb5-4007-83ee-84913a7c6fad ethernet eth0
Wired connection 1 0911dc61-1ab9-3ac8-abfa-fd72cf032a5e ethernet ens256
Wired connection 2 eda4adb2-d0e3-37d8-8938-219367c32fd8 ethernet ens224
#查看配置文件已经自动删除
[root@rhel7 network-scripts]# ls
ifcfg-eth0 ifdown-eth ifdown-isdn ifdown-sit ifup ifup-ib ifup-plip ifup-routes ifup-tunnel network-functions-ipv6
ifcfg-lo ifdown-ib ifdown-post ifdown-Team ifup-aliases ifup-ippp ifup-plusb ifup-sit ifup-wireless
ifdown ifdown-ippp ifdown-ppp ifdown-TeamPort ifup-bnep ifup-ipv6 ifup-post ifup-Team init.ipv6-global
ifdown-bnep ifdown-ipv6 ifdown-routes ifdown-tunnel ifup-eth ifup-isdn ifup-ppp ifup-TeamPort network-functions
二. 网络绑定(bonding)的配置
网络绑定(bonding)的运行模式一共有7种,详细信息如下所示:
网卡绑定mode共有七种(0~6) bond0、bond1、bond2、bond3、bond4、bond5、bond6;
模式 | 模式名称 | 描述 |
---|---|---|
0 | 平衡负载模式(balance-rr) | 为容错和负载均衡设置轮询策略,从第一个可用的接口开始,在每个绑定成员接口上按顺序接收和发送传输。 |
1 | 主-备份策略(active-backup) | 设置主动备份策略以实现容错,传输通过第一个可用的绑定成员接口接收和发送,仅当活动的绑定成员接口发生故障时,才使用另一个绑定成员接口 |
2 | 平衡策略(balance-xor) | 为容错和负载均衡设置 XOR(排除 or)策略,使用此方法,接口将传入请求的 MAC 地址与其中一个成员 NIC 的 MAC 地址进行匹配,一旦建立了此链路,传输将从第一个可用接口开始按顺序发送出去 |
3 | 广播策略(broadcast) | 设置容错的广播策略,所有传输都在所有成员接口上发送 |
4 | IEEE 802.3ad 动态链路聚合策略(LACP) | 设置 IEEE 802.3ad 动态链路聚合策略,创建共享相同速度和双工设置的聚合组,在活动聚合器中的所有成员上传输和接收。需要符合 802.3ad 标准的交换机支持 |
5 | 适配器传输负载均衡(balance-tlb) | 为容错和负载均衡设置传输负载均衡 (TLB) 策略,传出流量根据每个成员接口上的当前负载进行分配。传入流量由当前成员 NIC 接收,如果接收成员发生故障,则另一个成员将接管发生故障的成员的 MAC 地址 |
6 | 适配器适应性负载均衡(balance-alb) | 为容错和负载均衡设置主动负载均衡 (ALB) 策略,包括 IPV4 流量的传输和接收负载均衡,接收负载均衡是通过ARP协商实现的。 |
查看端口列表
[root@rhel7 ~]# nmcli device
DEVICE TYPE STATE CONNECTION
eth0 ethernet connected System eth0
ens256 ethernet connected Wired connection 1
ens224 ethernet connected Wired connection 2
lo loopback unmanaged --
#添加一个新的绑定设备(bond0,或其它随意名称)
[root@rhel7 ~]# nmcli connection add type bond ifname bond0 con-name bond0 bond.options "mode=balance-rr"
Connection 'bond0' (6250e440-0a84-42ca-8f90-672cc4b44136) successfully added.
#查看网口列表
[root@rhel7 ~]# nmcli device
DEVICE TYPE STATE CONNECTION
eth0 ethernet connected System eth0
ens256 ethernet connected Wired connection 1
ens224 ethernet connected Wired connection 2
bond0 bond connecting (getting IP configuration) bond0
lo loopback unmanaged
#为bond0 添加成员设备
[root@rhel7 ~]# nmcli connection add type ethernet ifname ens256 master bond0
Connection 'bond-slave-ens256' (d7bb482b-09de-4c3a-bba5-a521133695a3) successfully added.
[root@rhel7 ~]# nmcli connection add type ethernet ifname ens224 master bond0
Connection 'bond-slave-ens224' (272d6cff-be66-4b1b-96d0-f2cf9825d8e9) successfully added.
#查看端口列表
[root@rhel7 ~]# nmcli c s
NAME UUID TYPE DEVICE
bond0 6250e440-0a84-42ca-8f90-672cc4b44136 bond bond0
System eth0 97ea747c-bdb5-4007-83ee-84913a7c6fad ethernet eth0
Wired connection 1 0911dc61-1ab9-3ac8-abfa-fd72cf032a5e ethernet ens256
Wired connection 2 eda4adb2-d0e3-37d8-8938-219367c32fd8 ethernet ens224
bond-slave-ens224 272d6cff-be66-4b1b-96d0-f2cf9825d8e9 ethernet --
bond-slave-ens256 d7bb482b-09de-4c3a-bba5-a521133695a3 ethernet --
设置绑定设备的IP地址等
#IP地址
[root@rhel7 ~]# nmcli connection modify bond0 ipv4.addresses 10.255.255.30/24
#网关
[root@rhel7 ~]# nmcli connection modify bond0 ipv4.gateway 10.255.255.1
#DNS (需要设置多个DNS服务器,以空格分隔)
[root@rhel7 ~]# nmcli connection modify bond0 ipv4.dns "10.255.255.222 10.255.255.223"
#IP获取方式设置成手动并重启端口
[root@rhel7 ~]# nmcli connection modify bond0 ipv4.method manual
[root@rhel7 ~]# nmcli connection down bond0 && nmcli connection up bond0
#查看端口
[root@rhel7 ~]# nmcli c s
NAME UUID TYPE DEVICE
System eth0 97ea747c-bdb5-4007-83ee-84913a7c6fad ethernet eth0
Wired connection 1 0911dc61-1ab9-3ac8-abfa-fd72cf032a5e ethernet ens256
bond0 6250e440-0a84-42ca-8f90-672cc4b44136 bond bond0
Wired connection 2 eda4adb2-d0e3-37d8-8938-219367c32fd8 ethernet ens224
bond-slave-ens224 272d6cff-be66-4b1b-96d0-f2cf9825d8e9 ethernet --
bond-slave-ens256 d7bb482b-09de-4c3a-bba5-a521133695a3 ethernet --
查看端口状态
[root@rhel7 ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: load balancing (round-robin)
MII Status: down
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
#查看端口IP、配置文件
[root@rhel7 ~]# ip address
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens256: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:50:56:88:3c:57 brd ff:ff:ff:ff:ff:ff
inet6 fe80::f2a0:644c:7dde:84d4/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: ens224: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:50:56:88:6f:31 brd ff:ff:ff:ff:ff:ff
inet6 fe80::8cb5:569b:39c0:8570/64 scope link noprefixroute
valid_lft forever preferred_lft forever
4: bond0: <NO-CARRIER,BROADCAST,MULTICAST,MASTER,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 82:cc:70:ed:e2:99 brd ff:ff:ff:ff:ff:ff
inet 10.255.255.30/24 brd 10.255.255.255 scope global noprefixroute bond0
valid_lft forever preferred_lft forever
#配置文件
[root@rhel7 network-scripts]# cat ifcfg-bond0
BONDING_OPTS=mode=balance-rr
TYPE=Bond
BONDING_MASTER=yes
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
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=bond0
UUID=6250e440-0a84-42ca-8f90-672cc4b44136
DEVICE=bond0
ONBOOT=yes
IPADDR=10.255.255.30
PREFIX=24
GATEWAY=10.255.255.1
DNS1=10.255.255.222
DNS2=10.255.255.223
[root@rhel7 network-scripts]# cat ifcfg-bond-slave-ens224
TYPE=Ethernet
NAME=bond-slave-ens224
UUID=272d6cff-be66-4b1b-96d0-f2cf9825d8e9
DEVICE=ens224
ONBOOT=yes
MASTER=bond0
SLAVE=yes
[root@rhel7 network-scripts]# cat ifcfg-bond-slave-ens256
TYPE=Ethernet
NAME=bond-slave-ens256
UUID=d7bb482b-09de-4c3a-bba5-a521133695a3
DEVICE=ens256
ONBOOT=yes
MASTER=bond0
SLAVE=yes
**删除端口**
#查看端口
[root@rhel7 network-scripts]# nmcli connection show
NAME UUID TYPE DEVICE
System eth0 97ea747c-bdb5-4007-83ee-84913a7c6fad ethernet eth0
Wired connection 1 0911dc61-1ab9-3ac8-abfa-fd72cf032a5e ethernet ens256
bond0 6250e440-0a84-42ca-8f90-672cc4b44136 bond bond0
Wired connection 2 eda4adb2-d0e3-37d8-8938-219367c32fd8 ethernet ens224
bond-slave-ens224 272d6cff-be66-4b1b-96d0-f2cf9825d8e9 ethernet --
bond-slave-ens256 d7bb482b-09de-4c3a-bba5-a521133695a3 ethernet --
#删除端口
[root@rhel7 network-scripts]# nmcli connection delete bond0
Connection 'bond0' (6250e440-0a84-42ca-8f90-672cc4b44136) successfully deleted.
[root@rhel7 network-scripts]# nmcli connection delete bond-slave-ens224
Connection 'bond-slave-ens224' (272d6cff-be66-4b1b-96d0-f2cf9825d8e9) successfully deleted.
[root@rhel7 network-scripts]# nmcli connection delete bond-slave-ens256
Connection 'bond-slave-ens256' (d7bb482b-09de-4c3a-bba5-a521133695a3) successfully deleted.
#配置文件,自动删除了
[root@rhel7 network-scripts]# ls
ifcfg-eth0 ifdown-eth ifdown-isdn ifdown-sit ifup ifup-ib ifup-plip ifup-routes ifup-tunnel network-functions-ipv6
ifcfg-lo ifdown-ib ifdown-post ifdown-Team ifup-aliases ifup-ippp ifup-plusb ifup-sit ifup-wireless
ifdown ifdown-ippp ifdown-ppp ifdown-TeamPort ifup-bnep ifup-ipv6 ifup-post ifup-Team init.ipv6-global
ifdown-bnep ifdown-ipv6 ifdown-routes ifdown-tunnel ifup-eth ifup-isdn ifup-ppp ifup-TeamPort network-functions
三.网络分组(Team)和网络绑定(bonding)的区别
功能 | bonding | Team |
---|---|---|
广播 Tx 策略 | 是 | 是 |
循环 Tx 策略 | 是 | 是 |
Active-backup Tx 策略 | 是 | 是 |
LACP(802.3ad)支持 | 是(仅活动) | 是 |
基于 hash 的 Tx 策略 | 是 | 是 |
用户可以设置哈希功能 | 否 | 是 |
TX 负载均衡支持(TLB) | 是 | 是 |
LACP 哈希端口选择 | 是 | 是 |
LACP 支持的负载均衡 | 否 | 是 |
ethtool 链接监控 | 是 | 是 |
ARP 链路监控 | 是 | 是 |
NS/NA(IPv6)链路监控 | 否 | 是 |
端口启动/关闭延迟 | 是 | 是 |
“端口优先级和粘性(主要选项增强” ) | 否 | 是 |
单独设置每个端口的链接监控设置 | 否 | 是 |
多个链路监控设置 | 有限 | 是 |
Lockless Tx/Rx 路径 | 否(rwlock) | 是(RCU) |
VLAN 支持 | 是 | 是 |
用户空间运行时控制 | 有限 | full |
用户空间中的逻辑 | 否 | 是 |
可扩展性 | 难 | 易 |
模块化设计 | 否 | 是 |
性能开销 | 低 | 非常低 |
D-Bus 接口 | 否 | 是 |
多设备堆栈 | 是 | 是 |
使用 LLDP 时零配置 | 否 | (在计划中) |
NetworkManager 支持 | 是 | 是 |
关注小张的知识杂货铺,让我们一起学习一起进步