Salt-ssh 自动安装salt-minion
Salt-ssh 自动安装salt-minion
作用:为了不手动去安装一台一台去salt-minion,并进重复的配置
一、环境
系统环境:
#cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
#python -V
Python 2.7.5
各节点环境说明:
二、hosts文件解析
#vim /etc/hosts
192.168.1.101 salt.node1.com
192.168.1.200 salt.node2.com
192.168.1.201 salt.node3.com
三、安装salt-ssh
a.添加yum源:
*参考salt-stack官网:https://docs.saltstack.com/en/latest/topics/installation/rhel.html
# vim /etc/yum.repos.d/salt-stack.repo
[saltstack-repo]
name=SaltStack repo for Red Hat Enterprise Linux $releasever
baseurl=https://repo.saltstack.com/yum/redhat/$releasever/$basearch/latest
enabled=1
gpgcheck=1
gpgkey=https://repo.saltstack.com/yum/redhat/$releasever/$basearch/latest/SALTSTACK-GPG-KEY.pub
https://repo.saltstack.com/yum/redhat/$releasever/$basearch/latest/base/RPM-GPG-KEY-CentOS-7
b.安装salt-ssh
#yum install salt-ssh -y
c.配置roster文件
*可以在user下面配置passwd,如不配置的话,就要使用salt-ssh ‘*’ test.ping -i命令时配置输入密码进行认证
# vim /etc/salt/roster
node1:
host: 192.168.1.200
user: root
port: 22
node2:
host: 192.168.1.201
user: root
port: 22
四、配置state.sls文件及给复制相关文件到部署目录
a.创建文件目录
# mkdir -p /srv/salt/minions
# mkdir -p /srv/salt/minions/conf
# mkdir -p /srv/salt/minions/yum.repos.d
# vim install.sls
#salt_minion_install minion_yum: #把本地minions/yum.repos.d下和文件复制到要安装minion的/etc/yum.repos.d下 file.recurse: - name: /etc/yum.repos.d - source: salt://minions/yum.repos.d - user: root - group: root - file_mode: 644 - dir_mode: 755 - include_empty: True minion_install: #安装salt-minion pkg.installed: - pkgs: - salt-minion - require: - file: minion_yum - unless: rpm -qa | grep salt-minion minion_conf: #复制准备好的minion配置文件复制到要安装minion下的/etc/salt/minion下 file.managed: - name: /etc/salt/minion - source: salt://minions/conf/minion - user: root - group: root - mode: 640 - template: jinja - defaults: minion_id: {{ grains['fqdn_ip4'][0] }} - require: - pkg: minion_install minion_service: #开机自动启动 service.running: - name: salt-minion - enable: True - require: - file: minion_conf
c.编写minion配置文件
#vim minion
# resolved, then the minion will fail to start.
master: 192.168.1.101 #只用修改master地址
d.把salt源和epel源复制到指定目录下
#cp /etc/yum.repos.d/salt-stack.repo /srv/salt/minions/yum.repos.d/
# cp /etc/yum.repos.d/epel.repo /srv/salt/minions/yum.repos.d/
e.最后查看一下目录详情:
# pwd
/srv/salt/minions
# tree
├── conf
│ └── minion
├── install.sls
└── yum.repos.d
├── epel.repo
└── salt-stack.repo
五、执行salt-ssh安装salt-minion
#salt-ssh -i ‘*’ state.sls minions.install
六、验证安装结果
*注:在最后我在salt-ssh这台主机上安装了salt-mater(yum install -y salt-master ),不然下面的命令执行无效
# salt-key
Accepted Keys:
Denied Keys:
Unaccepted Keys:
centos7
node1
node2
Rejected Keys: