官方网站: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

[root@salt-master/]#cat/etc/hosts127.0.0.1localhostlocalhost.localdomainlocalhost4localhost4.localdomain4::1localhostlocalhost.localdomainlocalhost6localhost6.localdomain6192.168.161.132salt-master192.168.161.133salt-test-minion

安装epel源

[root@salt-master/]#wget-O/etc/yum.repos.d/epel.repohttp://mirrors.aliyun.com/repo/epel-6.repo

关闭防火墙

[root@salt-master/]#/etc/init.d/iptablesstopiptables:SettingchainstopolicyACCEPT:filter[OK]iptables:Flushingfirewallrules:[OK]iptables:Unloadingmodules:[OK][root@salt-test-minion/]#/etc/init.d/iptablesstopiptables:SettingchainstopolicyACCEPT:filter[OK]iptables:Flushingfirewallrules:[OK]iptables:Unloadingmodules:[OK]

             master端

[root@salt-master/]#yum-yinstallsalt-masterInstalled:salt-master.noarch0:2015.5.10-2.el6DependencyInstalled:PyYAML.x86_640:3.10-3.1.el6libyaml.x86_640:0.1.3-4.el6_6m2crypto.x86_640:0.20.2-9.el6openpgm.x86_640:5.1.118-3.el6python-babel.noarch0:0.9.4-5.1.el6python-backports.x86_640:1.0-5.el6python-backports-ssl_match_hostname.noarch0:3.4.0.2-4.el6.centospython-chardet.noarch0:2.2.1-1.el6python-jinja2.x86_640:2.2.1-2.el6_5python-msgpack.x86_640:0.4.6-1.el6python-requests.noarch0:2.6.0-3.el6python-six.noarch0:1.9.0-2.el6python-urllib3.noarch0:1.10.2-1.el6python-zmq.x86_640:14.3.1-1.el6salt.noarch0:2015.5.10-2.el6zeromq3.x86_640:3.2.5-1.el6DependencyUpdated:python.x86_640:2.6.6-66.el6_8python-libs.x86_640:2.6.6-66.el6_8Complete![root@salt-master/]#chkconfigsalt-masteron[root@salt-master/]#chkconfig--listsalt-mastersalt-master0:off1:off2:on3:on4:on5:on6:off

             salt-test-minion端

[root@salt-test-minion/]#yum-yinstallsalt-minionInstalled:salt-minion.noarch0:2015.5.10-2.el6DependencyInstalled:PyYAML.x86_640:3.10-3.1.el6libyaml.x86_640:0.1.3-4.el6_6m2crypto.x86_640:0.20.2-9.el6openpgm.x86_640:5.1.118-3.el6python-babel.noarch0:0.9.4-5.1.el6python-backports.x86_640:1.0-5.el6python-backports-ssl_match_hostname.noarch0:3.4.0.2-4.el6.centospython-chardet.noarch0:2.2.1-1.el6python-jinja2.x86_640:2.2.1-2.el6_5python-msgpack.x86_640:0.4.6-1.el6python-requests.noarch0:2.6.0-3.el6python-six.noarch0:1.9.0-2.el6python-urllib3.noarch0:1.10.2-1.el6python-zmq.x86_640:14.3.1-1.el6salt.noarch0:2015.5.10-2.el6zeromq3.x86_640:3.2.5-1.el6DependencyUpdated:python.x86_640:2.6.6-66.el6_8python-libs.x86_640:2.6.6-66.el6_8Complete![root@salt-test-minion/]#chkconfigsalt-minionon    #加入开机启动[root@salt-test-minion/]#chkconfig--listsalt-minionsalt-minion0:off1:off2:on3:on4:on5:on6:off

              master端

[root@salt-master/]#cp/etc/salt/master/etc/salt/master.bk#做备份[root@salt-master/]#vim/etc/salt/master


416file_roots:    #:把#(注释)去掉

417base:

418 - /srv/salt

529pillar_roots:     #:把#(注释)去掉

530base:

531- /srv/pillar

[root@salt-master /]# /etc/init.d/salt-master start
Starting salt-master daemon: [ OK ]

           salt-test-minion端

[root@salt-test-minion/]#cp/etc/salt/minion/etc/salt/minion.bk[root@salt-test-minion/]#vim/etc/salt/minion

16master:192.168.161.132    #改为master的Ip或主机名

78id:minion#定义个名字(建议起个有意义的名字如:nfs、nginx等)

[root@salt-test-minion /]# /etc/init.d/salt-minion start
Starting salt-minion daemon: [ OK ]

[root@salt-test-minion /]#chkconfig salt-minion on

            master端

[root@salt-master/]#salt-key-L#显示所有minion认证信息

[root@salt-master /]# salt-key -a salt-test-minion #接受salt-test-minion的认证信息;可跟参数 -y

[root@salt-master /]# salt-key

[root@localhost /]# 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.

[root@localhost /]# salt-key

Accepted Keys:

minion

Denied Keys:

Unaccepted Keys:

Rejected Keys:

        安装完成

一些简单命令介绍

[root@localhostsalt]#salt-key-dsalt-test-minion#拒绝认证salt-test-minion[root@localhostsalt]#salt-key-D拒绝所有[root@salt-master/]#salt'*'test.ping#检查当前所有主机状态

[root@salt-master /]# salt 'salt-test-minion' test.ping

[root@salt-master /]# salt '*' cmd.run 'df -h'

       文件分发

[root@salt-master/]#mkdir/srv/-master/]#cd/srv/salt/-/srv/-/etc/-source:salt:---mode:

[root@salt-mastersalt]#mkdirfiles[root@salt-mastersalt]#cdfiles[root@salt-masterfiles]#ls[root@salt-masterfiles]#vim/etc/hosts[root@salt-masterfiles]#cat/etc/hosts#在最后追加一些内容目的和salt-test-minion的/etc/hosts/的内容不同,后面验证是否分发成功127.0.0.1localhostlocalhost.localdomainlocalhost4localhost4.localdomain4::1localhostlocalhost.localdomainlocalhost6localhost6.localdomain6192.168.161.132salt-master192.168.161.133salt-test-minion##########################[root@salt-test-minion/]#cat/etc/hosts#salt-test-minion的hosts文件#127.0.0.1localhostlocalhost.localdomainlocalhost4localhost4.localdomain4#::1localhostlocalhost.localdomainlocalhost6localhost6.localdomain6#192.168.161.132salt-master#192.168.161.133salt-test-minion[root@salt-masterfiles]#cp/etc/hosts.#拷贝到当前目录[root@salt-masterfiles]#cd-/srv/salt[root@salt-mastersalt]#salt'*'state.slshost_file


到salt-test-minion上验证是否真的分发成功

[root@salt-mastersalt]#salt-cp'*'/etc/hosts/etc#不用创建上面的host_file.sls即可实现(不建议此方法)