基础环境:
[root@SaltM ~]# uname -a
Linux SaltM.t4x.org 2.6.32-642.el6.x86_64 #1 SMP Tue May 10 17:27:01 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
[root@SaltM ~]# uname -n
SaltM.t4x.org
[root@SaltM ~]# uname -r
2.6.32-642.el6.x86_64
[root@SaltM ~]# cat /etc/redhat-release
CentOS release 6.8 (Final) SourceByrd's Weblog-https://note.t4x.org/basic/saltstack-first-config/
IP地址规划:SourceByrd's Weblog-https://note.t4x.org/basic/saltstack-first-config/
[root@SaltM ~]# ifconfig | grep "inet addr:"
inet addr:1.1.1.114 Bcast:1.1.1.255 Mask:255.255.255.0SourceByrd's Weblog-https://note.t4x.org/basic/saltstack-first-config/[root@Salt1 salt]# ifconfig | grep "inet addr:"
inet addr:1.1.1.115 Bcast:1.1.1.255 Mask:255.255.255.0SourceByrd's Weblog-https://note.t4x.org/basic/saltstack-first-config/[root@Salt2 salt]# ifconfig | grep "inet addr:"
inet addr:1.1.1.116 Bcast:1.1.1.255 Mask:255.255.255.0 SourceByrd's Weblog-https://note.t4x.org/basic/saltstack-first-config/
服务端安装:
0 |
[root@SaltM ~]# yum install salt-master PyYAML libyaml openpgm python-babel python-backports-ssl_match_hostname python-crypto python-msgpack python-six python-zmq yum-utils libxml2 libxml2-python m2crypto pciutils python-backports python-chardet python-jinja2 python-requests python-urllib3 zeromq3 salt |
客户端安装:
0 |
[root@Salt2 ~]# yum install salt-minion PyYAML libyaml openpgm python-babel python-backports-ssl_match_hostname python-crypto python-msgpack python-six python-zmq yum-utils libxml2 libxml2-python m2crypto pciutils python-backports python-chardet python-jinja2 python-requests python-urllib3 zeromq3 salt |
默认配置文件:
0 1 |
[root@SaltM ~]# ll /etc/salt/ -rw-r-----. 1 root root 29543 Mar 23 06:24 master |
启动master:
0 1 2 3 |
[root@SaltM ~]# /etc/init.d/salt-master start [root@SaltM ~]# netstat -tunlp|grep 450 tcp 0 0 0.0.0.0:4505 #提供服务的端口 0.0.0.0:* LISTEN 1660/python2.6 tcp 0 0 0.0.0.0:4506 #返回服务的端口 0.0.0.0:* LISTEN 1680/python2.6 |
启动minion:
0 1 |
[root@Salt1 salt]# sed -i "s#\#master: salt#master: 1.1.1.114#g" /etc/salt/minion [root@Salt1 salt]# /etc/init.d/salt-minion start |
配置管理:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
[root@SaltM salt]# echo "1.1.1.115 Salt1.t4x.org" >> /etc/hosts [root@SaltM salt]# echo "1.1.1.116 Salt2.t4x.org" >> /etc/hosts [root@SaltM salt]# salt-key #查看允许或者不允许管理的客户端 [root@SaltM salt]# salt-key -a Salt1.t4x.org #将Salt1.t4x.org加入管理队列 [root@SaltM salt]# salt 'Salt1.t4x.org' test.ping #测试ping,也可以使用* Salt1.t4x.org: True [root@SaltM salt]# salt '*' cmd.run 'echo a > /tmp/a.txt' #在所有可用控制的机器上的tmp目录下建立a.txt目录 [root@SaltM ~]# mkdir /srv/salt/init [root@SaltM salt]# head -414 master | tail -9 file_roots: #顶格写 base: #两个空格 - /srv/salt/ #四个空格 dev: - /srv/salt/dev/services - /srv/salt/dev/states prod: - /srv/salt/prod/services - /srv/salt/prod/states [root@SaltM srv]# pwd /srv [root@SaltM srv]# tree . └── salt ├── init │ └── pkg.sls └── top.sls 2 directories, 2 files [root@SaltM srv]# cat salt/top.sls #默认top.sls base: #环境,顶格 'Salt1.t4x.org': #指定需要配置的主机,两个空格 - init.pkg #init目录下,pkg状态文件 [root@SaltM srv]# cat salt/init/pkg.sls yum.init: #随便写,定义名称 pkg.installed: #状态模块pkg,方法installed - names: - lrzsz #包名 - vim-enhanced - tree [root@SaltM srv]# salt 'Salt1.t4x.org' state.sls init.pkg #state.sls默认读取base环境,但是它并不会读取top.sls文件。你可以指定state.sls执行哪个sls文件,只要这个sls文件在base环境下存在; |