NIC Teaming on CentOS 7 with nmcli
1、Teaming Daemon安装
为了使用teaming功能,首先必须安装teamd包,系统通常不会安装。使用如下命令进行安装。
#yum install teamd -y
2、nmcli配置teaming
首先查看系统当前connection及device配置
[root@MiWiFi-R3-srv Desktop]# nmcli connection show
NAME UUID TYPE DEVICE
[root@MiWiFi-R3-srv Desktop]# nmcli device status
DEVICE TYPE STATE CONNECTION
eno16777736 ethernet disconnected --
eno33554992 ethernet disconnected --
lo loopback unmanaged --
[root@MiWiFi-R3-srv Desktop]#
创建teaming接口
#nmcli con add type team con-name myteam0 ifname team0 config '{ "runner": {"name": "loadbalance"}}'
配置team静态ip
#nmcli con mod myteam0 ipv4.addresses 192.168.31.108/24
#nmcli con mod myteam0 ipv4.gateway 192.168.31.1
#nmcli con mod myteam0 ipv4.method manual
添加eno16777736、eno33554992至myteam0中。
#nmcli con add type team-slave con-name myteam0-port1 ifname eno16777736 master myteam0
#nmcli con add type team-slave con-name myteam0-port2 ifname eno33554992 master myteam0
激活taaming接口
#nmcli con up myteam0
检查配置
[root@MiWiFi-R3-srv Desktop]# nmcli connection show
NAME UUID TYPE DEVICE
myteam0-port2 1a0f2bfd-cea1-4c7b-b2de-d34199b8561e 802-3-ethernet eno33554992
myteam0-port1 8e0c325c-d069-4014-bb75-1fa1f4674618 802-3-ethernet eno16777736
myteam0 e2976c8e-da7d-4901-88c6-db8a9913947c team team0
[root@MiWiFi-R3-srv Desktop]# nmcli device status
DEVICE TYPE STATE CONNECTION
eno16777736 ethernet connected myteam0-port1
eno33554992 ethernet connected myteam0-port2
team0 team connected myteam0
lo loopback unmanaged --
[root@MiWiFi-R3-srv Desktop]# ip a s
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
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
2: eno16777736: <BROADCAST,MULTICAST,LOWER_UP> mtu 1500 qdisc pfifo_fast master team0 state UP qlen 1000
link/ether 00:0c:29:51:e8:75 brd ff:ff:ff:ff:ff:ff
3: eno33554992: <BROADCAST,SimSun;">4: team0: <BROADCAST,LOWER_UP> mtu 1500 qdisc noqueue state UP
inet 192.168.31.108/24 brd 192.168.31.255 scope global team0
inet6 fe80::20c:29ff:fe51:e875/64 scope link tentative dadFailed
[root@MiWiFi-R3-srv ~]# teamdctl team0 state
setup:
runner: loadbalance
ports:
eno16777736
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up
down count: 0
eno33554992
通过teamnl查看slave网卡状态
[root@MiWiFi-R3-srv ~]# teamnl team0 ports
3: eno33554992: up 1000Mbit FD
2: eno16777736: up 1000Mbit FD
[root@MiWiFi-R3-srv ~]#
3、nmcli修改teaming runner配置
[root@MiWiFi-R3-srv Desktop]#nmcli connection modify myteam0 team.config '{ "runner": {"name": "roundrobin"}}'
需要重启下team0方可生效[root@MiWiFi-R3-srv Desktop]# nmcli connection down myteam0
Connection 'myteam0' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/9)
NAME UUID TYPE DEVICE
myteam0-port1 2b975876-780f-4181-971e-a79cf6a07a40 802-3-ethernet --
myteam0-port2 24e3ef82-fb93-4d11-9a6e-4c27227f7f66 802-3-ethernet --
myteam0 1f4ed5e2-46a1-4dbf-a870-5b088957a434 team --
DEVICE TYPE STATE CONNECTION
eno16777736 ethernet disconnected --
eno33554992 ethernet disconnected --
lo loopback unmanaged --
[root@MiWiFi-R3-srv Desktop]# nmcli connection up myteam0-port1
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/12)
[root@MiWiFi-R3-srv Desktop]# nmcli connection up myteam0-port2
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/14)
[root@MiWiFi-R3-srv Desktop]# nmcli connection up myteam0
Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/15)
bond0 bond unmanaged --
myteam0-port1 2b975876-780f-4181-971e-a79cf6a07a40 802-3-ethernet eno16777736
myteam0-port2 24e3ef82-fb93-4d11-9a6e-4c27227f7f66 802-3-ethernet eno33554992
myteam0 1f4ed5e2-46a1-4dbf-a870-5b088957a434 team team0
[root@MiWiFi-R3-srv Desktop]# teamdctl team0 state
runner: roundrobin
4、nmcli添加网卡到team
查看当前设备及网络连接
[root@MiWiFi-R3-srv ~]# ip link show
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
link/ether 00:0c:29:51:e8:75 brd ff:ff:ff:ff:ff:ff
4: eno50332216: <BROADCAST,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 00:0c:29:51:e8:89 brd ff:ff:ff:ff:ff:ff
5: bond0: <BROADCAST,MASTER> mtu 1500 qdisc noop state DOWN mode DEFAULT
link/ether 8a:3d:66:0a:92:91 brd ff:ff:ff:ff:ff:ff
9: team0: <BROADCAST,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT
DEVICE TYPE STATE CONNECTION
eno16777736 ethernet connected myteam0-port1
eno33554992 ethernet connected myteam0-port2
team0 team connected myteam0
eno50332216 ethernet disconnected --
bond0 bond unmanaged --
lo loopback unmanaged --
[root@MiWiFi-R3-srv Desktop]# nmcli networking off
断开网络之后,设备变为非管理状态
DEVICE TYPE STATE CONNECTION
team0 team connected myteam0
bond0 bond unmanaged --
eno16777736 ethernet unmanaged --
eno33554992 ethernet unmanaged --
eno50332216 ethernet unmanaged --
lo loopback unmanaged --
[root@MiWiFi-R3-srv Desktop]# teamdctl team0 port add eno50332216
[root@MiWiFi-R3-srv Desktop]# nmcli networking on
DEVICE TYPE STATE CONNECTION
eno16777736 ethernet connected myteam0-port1
eno33554992 ethernet connected myteam0-port2
eno50332216 ethernet connected eno50332216
team0 team connected myteam0
bond0 bond unmanaged --
lo loopback unmanaged --
[root@MiWiFi-R3-srv Desktop]#
修改新加网卡的连接名
[root@MiWiFi-R3-srv Desktop]# nmcli connection modify eno50332216 con-name myteam0-port3
NAME UUID TYPE DEVICE
myteam0 385eda15-a3fb-4e7e-a6d4-8fc816843b73 team team0
myteam0-port1 32cd5220-4746-4fc4-afc1-03158d9d0378 802-3-ethernet eno16777736
myteam0-port2 f58e3a15-b239-496e-a971-535857395d59 802-3-ethernet eno33554992
myteam0-port3 cf2576ff-9709-44c8-a0a5-df606a3c5697 802-3-ethernet eno50332216
[root@MiWiFi-R3-srv Desktop]#teamnl team0 ports
4: eno50332216: up 1000Mbit FD
3: eno33554992: up 1000Mbit FD
2: eno16777736: up 1000Mbit FD
备注
添加网卡至team0中,网卡必须处于非活动状态才可以添加成功。否则报错如下:
libteamdctl: cli_usock_process_msg: usock: Error message received: "PortAddFail"
libteamdctl: cli_usock_process_msg: usock: Error message content: "Failed to add port."
command call Failed (Invalid argument)
messages中日志如下
Dec 26 18:12:47 MiWiFi-R3-srv NetworkManager[938]: <info> [1482747167.9905] device (eno33554992): state change: config -> ip-config (reason 'none') [50 70 0]
Dec 26 18:12:48 MiWiFi-R3-srv systemd: Unit iscsi.service cannot be reloaded because it is inactive.
5、nmcli从team中删除网卡
查看当前设备及连接
[root@MiWiFi-R3-srv ~]# nmcli connection show
[root@MiWiFi-R3-srv ~]# teamdctl team0 port remove eno50332216
[root@MiWiFi-R3-srv ~]# nmcli device status
eno50332216 ethernet connected myteam0-port3
lo loopback unmanaged --
删除之后查连接与设备仍然存在,重启网卡服务后再次查看eno50332216网卡已从team0中删除,仅留连接名myteam0-port3,该连接名若不在使用可以删除
[root@MiWiFi-R3-srv ~]# systemctl restart network
myteam0-port3 cf2576ff-9709-44c8-a0a5-df606a3c5697 802-3-ethernet --
[root@MiWiFi-R3-srv ~]# teamnl team0 ports
[root@MiWiFi-R3-srv ~]#
6、ip工具配置team
[root@MiWiFi-R3-srv ~]# ip link
[root@MiWiFi-R3-srv ~]# ip link set dev eno50332216 down
down掉后,设备变为不可用。
DEVICE TYPE STATE CONNECTION
eno16777736 ethernet connected myteam0-port1
eno33554992 ethernet connected myteam0-port2
team0 team connected myteam0
eno50332216 ethernet unavailable --
bond0 bond unmanaged --
lo loopback unmanaged --
[root@MiWiFi-R3-srv ~]# ip link set dev eno50332216 master myteam0
Error: argument "myteam0" is wrong: Device does not exist
[root@MiWiFi-R3-srv ~]# ip link set dev eno50332216 master team0 ##这里指定设备名非连接名
eno50332216 e89195e9-5572-4951-9af5-15e8fbbaae8a 802-3-ethernet eno50332216
[root@MiWiFi-R3-srv ~]# nmcli connection modify eno50332216 connection.id myteam0-port3
myteam0-port3 e89195e9-5572-4951-9af5-15e8fbbaae8a 802-3-ethernet eno50332216
7、team相关命令
teamnl命令
teamnl [options] teamdevname command [command args]
-h --help Show this help
Commands:
ports
options
getoption OPT_NAME
setoption OPT_NAME OPT_VALUE
monitor OPT_STYLE
例如获取端口信息及mode模式。
# teamnl team0 ports
# teamnl team0 getoption mode
loadbalance
#
teamdctl命令
teamdctl [options] teamdevname command [command args]
-h --help Show this help
-v --verbose Increase output verbosity
-o --oneline Force output to one line if possible
-D --force-dbus Force to use D-Bus interface
-Z --force-zmq=ADDRESS Force to use ZeroMQ interface [-Z[Address]]
-U --force-usock Force to use UNIX domain socket interface
config dump
config dump noports
config dump actual
state
state dump
state view
state item get ITEMPATH
state item set ITEMPATH VALUE
port add PORTDEV
port remove PORTDEV
port present PORTDEV
port config update PORTDEV PORTCONFIG
port config dump PORTDEV
例如1:查看team0配置信息
#teamdctl team0 state
setup:
runner: loadbalance
ports:
eno16777736
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up
down count: 0
eno33554992
eno50332216
例如2:查看team0配置不包含端口信息。
# teamdctl team0 config dump noports
{
"device": "team0",
"runner": {
"name": "loadbalance",SimSun;"> "tx_hash": [
"eth",SimSun;"> "ipv4",SimSun;"> "ipv6"
]
}
}
#