您的位置:首页 > 博客中心 > 网络系统 >

Linux-saltstack-1 saltstack的安装与基本配置

时间:2022-04-03 16:28

@

目录

一、环境介绍

系统版本 IP地址 主机名 角色
centos7.5 192.168.1.104 salt-master master
centos7.5 192.168.1.105 salt-client client

环境说明:
centos7.5默认的python环境是2.7版本。
官方说明:
"python 2.7已弃用
鉴于2020年1月1日Python 2.7即将终止生命,Python 2已被弃用,并且从3001版本开始不再受支持。"

所以从3001版本以后依赖的python环境都是python3环境
我们在安装的时候无需安装python3环境,只要配置好salt官网的yum源,在安装salt的过程中会自动安装python3环境。

在服务端关闭防火墙和selinux

systemctl stop firewalld
setenforce 0

二、安装saltstack

#saltstack yum源网站
https://repo.saltstack.com/

1.配置安装yum源

yum -y install https://repo.saltstack.com/py3/redhat/salt-py3-repo-3002.el7.noarch.rpm 

2.安装salt-master

#在master上执行
[root@salt-master ~]# yum -y install salt-master

#查看版本
[root@salt-master ~]# salt-master  --version
salt-master 3002.2

#在master上在安装一个客户端
[root@salt-master ~]# yum -y install salt-minion

3.安装slat-minion

#在client上执行
[root@salt-cilent ~]# yum -y install salt-minion

[root@salt-cilent ~]# salt-minion --version
salt-minion 3002.2

三、配置salt-master

1.指定master的地址

[root@salt-master ~]# cd /etc/salt/
[root@salt-master salt]# ls
cloud         cloud.deploy.d  cloud.profiles.d   master    minion    pki    proxy.d
cloud.conf.d  cloud.maps.d    cloud.providers.d  master.d  minion.d  proxy  roster

#在salt-master上打开minion配置我文件,指定master的地址
[root@salt-master salt]# vim minion
#复制16行内容,将salt修改为master的IP地址
master: 192.168.1.105

2.在master上启动minion

[root@salt-master ~]# systemctl  restart salt-minion
[root@salt-master ~]# cd /etc/salt/pki/minion/
[root@salt-master minion]# ls
minion.pem  minion.pub

四、配置salt-minion

1.指定master IP

[root@salt-cilent ~]# vim /etc/salt/minion
#复制16行内容,将salt修改为master的IP地址
master: 192.168.1.105

2.在minion上启动minion

[root@salt-cilent ~]# systemctl  restart salt-minion

五、启动master

#启动master
[root@salt-master ~]# systemctl  restart salt-master

master启动后默认会监听两个端口:
4505:提供远程执行命令发送功能
4506:支持认证,结果收集等功能

[root@salt-master ~]# netstat -antp |grep python3
tcp        0      0 0.0.0.0:4505            0.0.0.0:*               LISTEN      2416/python3        
tcp        0      0 0.0.0.0:4506            0.0.0.0:*               LISTEN      2422/python3 

1.查看所有客户端发送给服务器端的公钥

在unaccepted下显示了所有未接受的 "客户端发来的公钥"

[root@salt-master ~]# salt-key -L
Accepted Keys:
Denied Keys:
Unaccepted Keys:
salt-client
salt-master
Rejected Keys:

2.接受客户端口发来的公钥

#使用salt-key 来管理密钥 参数如下:
-L    # 列出所有未被接受的公钥
-a    # 接受(Accept)指定的主机公钥,后面接主机名
-r    # 拒绝(Reject)指定的主机公钥,后面接主机名
-d    # 拒绝(Deny)指定的主机公钥,后面接主机名
-A    # 接受(Accept)所有的主机公钥
-R    # 拒绝(Reject)所有的主机公钥
-D    # 拒绝(Deny)所有的主机公钥
-y    # 我们在接受主机公钥时需要按y确认,加上该参数可以省略交互

接受两台主机发来的公钥

[root@salt-master ~]# salt-key -A -y
The following keys are going to be accepted:
Unaccepted Keys:
salt-client
salt-master
Key for minion salt-client accepted.
Key for minion salt-master accepted.

再次查看密钥状态,两台主机的公钥已经处于接受状态(acepted keys)

[root@salt-master ~]# salt-key -L
Accepted Keys:
salt-client
salt-master
Denied Keys:
Unaccepted Keys:
Rejected Keys:

六、测试通信

[root@salt-master ~]# salt ‘*‘ test.ping
salt-master:
    True
salt-client:
    True

通信成功

本类排行

今日推荐

热门手游