官方网站:https://www.saltstack.com/
官方文档 https://docs.saltstack.cn/contents.html
GitHub: https://github.com/saltstack
中国saltstack用户组:https://www.saltstack.cn/
CentOS-6.5安装saltstack
192.168.161.132 salt-master |
salt-master 可装(salt-minion)这里只装salt-master |
192.168.161.133 salt-test-minion |
salt-minion |
[[email protected] /]# cat /etc/hosts127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6192.168.161.132 salt-master192.168.161.133 salt-test-minion
安装epel源
[[email protected] /]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
关闭防火墙
[[email protected] /]# /etc/init.d/iptables stop iptables: Setting chains to policy ACCEPT: filter [ OK ] iptables: Flushing firewall rules: [ OK ] iptables: Unloading modules: [ OK ] [[email protected] /]# /etc/init.d/iptables stop iptables: Setting chains to policy ACCEPT: filter [ OK ] iptables: Flushing firewall rules: [ OK ] iptables: Unloading modules: [ OK ]
master端
[[email protected] /]# yum -y install salt-master Installed: salt-master.noarch 0:2015.5.10-2.el6 Dependency Installed: PyYAML.x86_64 0:3.10-3.1.el6 libyaml.x86_64 0:0.1.3-4.el6_6 m2crypto.x86_64 0:0.20.2-9.el6 openpgm.x86_64 0:5.1.118-3.el6 python-babel.noarch 0:0.9.4-5.1.el6 python-backports.x86_64 0:1.0-5.el6 python-backports-ssl_match_hostname.noarch 0:3.4.0.2-4.el6.centos python-chardet.noarch 0:2.2.1-1.el6 python-jinja2.x86_64 0:2.2.1-2.el6_5 python-msgpack.x86_64 0:0.4.6-1.el6 python-requests.noarch 0:2.6.0-3.el6 python-six.noarch 0:1.9.0-2.el6 python-urllib3.noarch 0:1.10.2-1.el6 python-zmq.x86_64 0:14.3.1-1.el6 salt.noarch 0:2015.5.10-2.el6 zeromq3.x86_64 0:3.2.5-1.el6 Dependency Updated: python.x86_64 0:2.6.6-66.el6_8 python-libs.x86_64 0:2.6.6-66.el6_8 Complete![[email protected] /]# chkconfig salt-master on [[email protected] /]# chkconfig --list salt-master salt-master 0:off 1:off 2:on 3:on 4:on 5:on 6:off
salt-test-minion端
[[email protected] /]# yum -y install salt-minion Installed: salt-minion.noarch 0:2015.5.10-2.el6 Dependency Installed: PyYAML.x86_64 0:3.10-3.1.el6 libyaml.x86_64 0:0.1.3-4.el6_6 m2crypto.x86_64 0:0.20.2-9.el6 openpgm.x86_64 0:5.1.118-3.el6 python-babel.noarch 0:0.9.4-5.1.el6 python-backports.x86_64 0:1.0-5.el6 python-backports-ssl_match_hostname.noarch 0:3.4.0.2-4.el6.centos python-chardet.noarch 0:2.2.1-1.el6 python-jinja2.x86_64 0:2.2.1-2.el6_5 python-msgpack.x86_64 0:0.4.6-1.el6 python-requests.noarch 0:2.6.0-3.el6 python-six.noarch 0:1.9.0-2.el6 python-urllib3.noarch 0:1.10.2-1.el6 python-zmq.x86_64 0:14.3.1-1.el6 salt.noarch 0:2015.5.10-2.el6 zeromq3.x86_64 0:3.2.5-1.el6 Dependency Updated: python.x86_64 0:2.6.6-66.el6_8 python-libs.x86_64 0:2.6.6-66.el6_8 Complete![[email protected] /]# chkconfig salt-minion on #加入开机启动 [[email protected] /]# chkconfig --list salt-minion salt-minion 0:off 1:off 2:on 3:on 4:on 5:on 6:off
master端
[[email protected] /]# cp /etc/salt/master /etc/salt/master.bk #做备份 [r[email protected] /]# vim /etc/salt/master
416 file_roots: #:把#(注释)去掉
417 base:
418 - /srv/salt
529 pillar_roots: #:把#(注释)去掉
530 base:
531 - /srv/pillar
[[email protected] /]# /etc/init.d/salt-master start
Starting salt-master daemon: [ OK ]
salt-test-minion端
[[email protected] /]# cp /etc/salt/minion /etc/salt/minion.bk [[email protected] /]# vim /etc/salt/minion
16 master: 192.168.161.132 #改为master的Ip或主机名
78 id: minion #定义个名字(建议起个有意义的名字如:nfs、nginx等)
[[email protected] /]# /etc/init.d/salt-minion start
Starting salt-minion daemon: [ OK ]
[[email protected] /]# chkconfig salt-minion on
master端
[[email protected] /]# salt-key -L#显示所有minion认证信息
[[email protected] /]# salt-key -a salt-test-minion #接受salt-test-minion的认证信息;可跟参数 -y
[[email protected] /]# salt-key
或
[[email protected] /]# salt-key -A #接受所有Unaccepted状态的minion认证信息
The following keys are going to be accepted:
Unaccepted Keys:
minion
Proceed? [n/Y] y
Key for minion minion accepted.
[[email protected] /]# salt-key
Accepted Keys:
minion
Denied Keys:
Unaccepted Keys:
Rejected Keys:
安装完成
一些简单命令介绍
[[email protected] salt]# salt-key -d salt-test-minion #拒绝认证salt-test-minion [[email protected] salt]# salt-key -D 拒绝所有 [[email protected] /]# salt ‘*‘ test.ping #检查当前所有主机状态
或
[[email protected] /]# salt ‘salt-test-minion‘ test.ping
[[email protected] /]# salt ‘*‘ cmd.run ‘df -h‘
文件分发
[[email protected] /]# mkdir /srv/-master /]# cd /srv/salt/-/srv/-/etc/- source: salt:--- mode:
[[email protected] salt]# mkdir files [[email protected] salt]# cd files [[email protected] files]# ls [[email protected] files]# vim /etc/hosts [[email protected] files]# cat /etc/hosts #在最后追加一些内容 目的和salt-test-minion的/etc/hosts/的内容不同,后面验证是否分发成功127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6192.168.161.132 salt-master192.168.161.133 salt-test-minion ######################### #[[email protected] /]# cat /etc/hosts #salt-test-minion 的hosts文件 #127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 #::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 #192.168.161.132 salt-master #192.168.161.133 salt-test-minion [[email protected] files]# cp /etc/hosts . #拷贝到当前目录 [[email protected] files]# cd - /srv/salt [[email protected] salt]# salt ‘*‘ state.sls host_file
到salt-test-minion上验证是否真的分发成功
或
[[email protected] salt]# salt-cp ‘*‘ /etc/hosts /etc #不用创建上面的host_file.sls即可实现(不建议此方法)