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
b.編寫安裝minions的sls文件--install.sls
# cd /srv/salt/minions/
# 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:
salt-ssh 自動安裝salt-minion