Nmcli-地址命令配置工具

特点

  • 高可用
  • 负载均衡

一、配置team高可用
#查看本地网卡情况

[root@localhost ~]# nmcli device

#查看示例文件

[root@localhost ~]# cd /usr/share/doc/teamd-1.17/example_configs/
[root@localhost example_configs]# ll
总用量 64
-rw-r--r--. 1 root root 305 Apr 2 2015 activebackup_arp_ping_1.conf
-rw-r--r--. 1 root root 465 Apr 2 2015 activebackup_arp_ping_2.conf
-rw-r--r--. 1 root root 194 Apr 2 2015 activebackup_ethtool_1.conf
-rw-r--r--. 1 root root 212 Apr 2 2015 activebackup_ethtool_2.conf
-rw-r--r--. 1 root root 241 Apr 2 2015 activebackup_ethtool_3.conf
-rw-r--r--. 1 root root 447 Apr 2 2015 activebackup_multi_lw_1.conf
-rw-r--r--. 1 root root 285 Apr 2 2015 activebackup_nsna_ping_1.conf
-rw-r--r--. 1 root root 318 Apr 2 2015 activebackup_tipc.conf
-rw-r--r--. 1 root root 96 Apr 2 2015 broadcast.conf
-rw-r--r--. 1 root root 209 Apr 2 2015 lacp_1.conf
-rw-r--r--. 1 root root 98 Apr 2 2015 loadbalance_1.conf
-rw-r--r--. 1 root root 140 Apr 2 2015 loadbalance_2.conf
-rw-r--r--. 1 root root 183 Apr 2 2015 loadbalance_3.conf
-rw-r--r--. 1 root root 93 Apr 2 2015 random.conf
-rw-r--r--. 1 root root 244 Apr 2 2015 roundrobin_2.conf
-rw-r--r--. 1 root root 97 Apr 2 2015 roundrobin.conf

#选择链路聚合配置模型
#取用以下内容

"runner":       {"name": "activebackup"}

#创建team0设备和team0会话

[root@localhost ~]# nmcli connection add type team con-name team0 ifname team0 config '{"runner": {"name": "activebackup"} }'

#查看创建好的team0会话

[root@localhost ~]# nmcli connection show

#修改team0会话的IP地址和网关

[root@localhost ~]# nmcli connection modify team0 ipv4.addresses 192.168.171.150/24
[root@localhost ~]# nmcli connection modify team0 ipv4.gateway 192.168.171.1(可不写)

#更改IP地址获取方式为手动

[root@localhost ~]# nmcli connection modify team0 ipv4.method manual(可不写)

#查看修改后的team0会话

[root@localhost ~]# nmcli connection show team0 | grep method

#添加设备到team0

[root@localhost ~]# nmcli connection add type team-slave con-name team0-port1 ifname eno33554984 master team0
[root@localhost ~]# nmcli connection add type team-slave con-name team0-port2 ifname eno50332208 master team0

#激活从设备

[root@localhost ~]# nmcli connection up team0-port1
[root@localhost ~]# nmcli connection up team0-port2

#激活主设备

[root@localhost ~]# nmcli connection up team0

#查看启动后的team0状态

[root@localhost ~]# teamdctl team0 state

#停用一个从设备会话来检验效果

[root@localhost ~]# nmcli connection down team0-port1

#停用一个从设备真实网卡来检验效果

[root@localhost ~]# nmcli device disconnect eno50332208
nmcli connection delete tem0-port1
nmcli connection delete team0-port2
nmcli connectiion delete team0

二、配置软件桥接
#创建一个软件桥接设备和会话

[root@localhost ~]# nmcli connection add type bridge con-name br1 ifname br1

#配置软件桥接网卡的IP地址、网关和地址获取方式

[root@localhost ~]# nmcli connection modify br1 ipv4.addresses 192.168.171.151/24
[root@localhost ~]# nmcli connection modify br1 ipv4.gateway 192.168.171.1(可不写)
[root@localhost ~]# nmcli connection modify br1 ipv4.method manual

#添加从设备和会话到桥接设备

[root@localhost ~]# nmcli connection add type bridge-slave con-name br1-port0 ifname eno33554984 master br1

#启动从设备会话

[root@localhost ~]# nmcli connection up br1-port0

#启动桥接会话

[root@localhost ~]# nmcli connection up br1

三、配置team桥接
1、配置team
#创建team1设备和team1会话

[root@localhost ~]# nmcli connection add type team con-name team1 ifname team1 config '{"runner": {"name": "activebackup"} }'

#添加设备到team0

[root@localhost ~]# nmcli connection add type team-slave con-name team1-port1 ifname eno33554984 master team1
[root@localhost ~]# nmcli connection add type team-slave con-name team1-port2 ifname eno50332208 master team1

#激活从设备

[root@localhost ~]# nmcli connection up team1-port1
[root@localhost ~]# nmcli connection up team1-port2

#激活主设备

[root@localhost ~]# nmcli connection up team1

#查看team状态

[root@localhost ~]# teamdctl team1 state

#断掉team1设备

[root@localhost ~]# nmcli device disconnect team1

#停用NetworkManager服务

[root@localhost ~]# systemctl stop NetworkManager.service

#禁止该服务开机启动

[root@localhost ~]# systemctl disable NetworkManager.service

#切换到网卡配置目录

[root@localhost ~]# cd /etc/sysconfig/network-scripts/

#编辑team1配置文件

[root@localhost network-scripts]# vi ifcfg-team1

#追加如下内容:

BRIDGE=brteam1

#编辑team1从设备配置文件,只保留以下内容,移除和IP相关的信息

NAME=team1-port1
UUID=01de42d1-7304-4ef8-8c62-93c405cd8474
DEVICE=eno33554984
ONBOOT=yes
TEAM_MASTER=team1
DEVICETYPE=TeamPort

#配置brteam1配置文件

[root@localhost network-scripts]# cat ifcfg-brteam1
DEVICE=brteam1
ONBOOT=yes
TYPE=Bridge
IPADDR0=192.168.171.152
PREFIX0=24

#重启网络服务

[root@localhost ~]# systemctl restart NetworkManager
[root@localhost ~]# systemctl restart network

创作者:Eric· Charles