rpm -ivh 'http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm'
[root@wdds_1 yum.repos.d]# yum install salt-master
正在安装:
salt-master noarch 2015.5.3-3.el6 epel 965 k
为依赖而安装:
m2crypto x86_64 0.20.2-9.el6 base 471 k
openpgm x86_64 5.1.118-3.el6 epel 165 k
python-babel noarch 0.9.4-5.1.el6 base 1.4 M
python-backports x86_64 1.0-3.el6.centos extras 5.3 k
python-backports-ssl_match_hostname noarch 3.4.0.2-4.el6.centos extras 13 k
python-chardet noarch 2.0.1-1.el6.centos extras 225k
python-jinja2 x86_64 2.2.1-2.el6_5 base 466 k
python-msgpack x86_64 0.4.6-1.el6 epel 69 k
python-ordereddict noarch 1.1-2.el6.centos extras 7.7 k
python-requests noarch 1.1.0-4.el6.centos extras 71 k
python-six noarch 1.7.3-1.el6.centos extras 27 k
python-urllib3 noarch 1.5-7.el6.centos extras 41 k
python-zmq x86_64 14.3.1-1.el6 epel 467 k
salt noarch 2015.5.3-3.el6 epel 4.1 M
zeromq3 x86_64 3.2.5-1.el6 epel 338 k、
[root@wdds_2 yum.repos.d]# yum install salt-minion
[root@wdds_1 6]# service salt-master start
Starting salt-master daemon: [确定]
[root@wdds_1 6]# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:53331 0.0.0.0:* LISTEN 1786/rpc.statd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2000/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1852/cupsd
tcp 0 0 0.0.0.0:4505 0.0.0.0:* LISTEN 2808/python2.6
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2338/master
tcp 0 0 0.0.0.0:4506 0.0.0.0:* LISTEN 2822/python2.6
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 2507/sshd
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1738/rpcbind
tcp 0 0 :::39634 :::* LISTEN 1786/rpc.statd
tcp 0 0 :::22 :::* LISTEN 2000/sshd
tcp 0 0 ::1:631 :::* LISTEN 1852/cupsd
tcp 0 0 ::1:25 :::* LISTEN 2338/master
tcp 0 0 ::1:6010 :::* LISTEN 2507/sshd
tcp 0 0 :::873 :::* LISTEN 2021/xinetd
tcp 0 0 :::111 :::* LISTEN 1738/rpcbind
[root@wdds_1 6]# ps aux |grep salt
root 2806 0.0 2.6 368028 21072 ? S 23:39 0:00 /usr/bin/python2.6 /usr/bin/salt-master -d
root 2807 3.1 3.5 475152 28936 ? Sl 23:39 0:00 /usr/bin/python2.6 /usr/bin/salt-master -d
root 2808 0.0 2.6 454052 21440 ? Sl 23:39 0:00 /usr/bin/python2.6 /usr/bin/salt-master -d
root 2809 0.5 2.8 454052 22828 ? Sl 23:39 0:00 /usr/bin/python2.6 /usr/bin/salt-master -d
root 2810 0.0 2.5 368028 20744 ? S 23:39 0:00 /usr/bin/python2.6 /usr/bin/salt-master -d
root 2815 9.8 4.0 1150132 32560 ? Sl 23:39 0:02 /usr/bin/python2.6 /usr/bin/salt-master -d
root 2816 10.6 4.0 1150136 32560 ? Sl 23:39 0:02 /usr/bin/python2.6 /usr/bin/salt-master -d
root 2817 10.8 4.0 1150136 32568 ? Sl 23:39 0:02 /usr/bin/python2.6 /usr/bin/salt-master -d
root 2818 10.9 4.0 1150140 32564 ? Sl 23:39 0:02 /usr/bin/python2.6 /usr/bin/salt-master -d
root 2821 11.7 4.0 1150144 32572 ? Sl 23:39 0:03 /usr/bin/python2.6 /usr/bin/salt-master -d
root 2822 0.1 2.6 757172 21628 ? Sl 23:39 0:00 /usr/bin/python2.6 /usr/bin/salt-master -d
root 3271 0.0 0.1 103256 840 pts/0 R+ 23:39 0:00 grep salt
master: 10.0.0.61
[root@wdds_1 ~]# salt-key -L 查看当前的key信息
Accepted Keys:
Denied Keys:
Unaccepted Keys:
wdds_2
wdds_3
Rejected Keys:
[root@wdds_1 ~]# salt-key -a wdds_2 接受单个主机 (-d 删除)
The following keys are going to be accepted:
Unaccepted Keys:
wdds_2
Proceed? [n/Y] Y
Key for minion wdds_2 accepted.
[root@wdds_1 ~]# salt-key -A 接收所有主机(-D 删除所有)
The following keys are going to be accepted:
Unaccepted Keys:
wdds_3
Proceed? [n/Y] y
Key for minion wdds_3 accepted.
[root@wdds_1 ~]# salt-key
Accepted Keys:
wdds_2
wdds_3
Denied Keys:
Unaccepted Keys:
Rejected Keys:
[root@wdds_1 ~]# salt '*' cmd.run 'echo helloworld'
wdds_3:
helloworld
wdds_2:
helloworld
[root@wdds_1 ~]# salt '*' cmd.run 'uptime'
wdds_2:
20:00:26 up 1:05, 1 user, load average: 0.17, 0.06, 0.01
[root@wdds_1 ~]# salt -G 'os:Centos'test.ping
wdds_2:
True
[root@wdds_1 ~]# salt '*' grains.item os
wdds_2:
----------
os:
CentOS
[root@wdds_1 ~]# salt '*' grains.item 查看minion主机grains信息
[root@wdds_1 ~]# salt '*' cmd.exec_codepython 'import sys; print sys.version'
wdds_2:
2.6.6 (r266:84292, Jul 23 2015, 15:22:56)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)]
常用模块介绍
(1)、cp模块(实现远程文件、目录的复制,以及下载URL文件等操作)
## 将主服务器file_roots指定位置下的目录复制到被控主机
# salt '*' cp.get_dir salt://hellotest /data
##将主服务器file_roots指定位置下的文件复制到被控主机
# salt '*' cp.get_file salt://hellotest/rocketzhang /root/rocketzhang
## 下载指定URL内容到被控主机指定位置
# salt '*' cp.get_url http://xxx.xyz.com/download/0/files.tgz /root/files.tgz
(2)、cmd模块(实现远程的命令行调用执行)
# salt '*' cmd.run 'netstat -ntlp'
(3)、cron模块(实现被控主机的crontab操作)
## 为指定的被控主机、root用户添加crontab信息
# salt '*' cron.set_job root '*/5' '*' '*' '*' '*' 'date >/dev/null2>&1'
# salt '*' cron.raw_cron root
## 删除指定的被控主机、root用户的crontab信息
# salt '*' cron.rm_job root 'date >/dev/null 2>&1'
# salt '*' cron.raw_cron root
(4)、dnsutil模块(实现被控主机通用DNS操作)
## 为被控主机添加指定的hosts主机配置项
# salt '*' dnsutil.hosts_append /etc/hosts 127.0.0.1 rocketzhang.qq.com
(5)、file模块(被控主机文件常见操作,包括文件读写、权限、查找、校验等)
# salt '*' file.get_sum /etc/resolv.conf md5
# salt '*' file.stats /etc/resolv.conf
更多功能可以看文档哈 ^_^
(6)、network模块(返回被控主机网络信息)
# salt '*' network.ip_addrs
# salt '*' network.interfaces
更多功能可以看文档哈 ^_^
(7)、pkg包管理模块(被控主机程序包管理,如yum、apt-get等)
# salt '*' pkg.install nmap
# salt '*' pkg.file_list nmap
(8)、service 服务模块(被控主机程序包服务管理)
# salt '*' service.enable crond
# salt '*' service.disable crond
# salt '*' service.status crond
# salt '*' service.stop crond
# salt '*' service.start crond
# salt '*' service.restart crond
# salt '*' service.reload crond
(9)、更多功能
更多的功能,比如:grains、pillar、states、modules、returner、runners、reactor等,还有如下高级命令的使用,以及模板配置的渲染、扩展模块的二次开发等,可以自己去深入学习哈。
附录
http://docs.saltstack.com/en/latest/ref/modules/all/index.html
http://docs.saltstack.com/en/latest/ref/modules/index.html
http://www.saltstack.cn/projects/cssug-kb/wiki
http://salt-api.readthedocs.org/en/latest/
http://xiaorui.cc/category/saltstack/
http://www.shencan.net/index.php/category/%e8%87%aa%e5%8a%a8%e5%8c%96%e8%bf%90%e7%bb%b4/saltstack/
http://liuping0906.blog.51cto.com/2516248/d-13
http://lixcto.blog.51cto.com/4834175/d-1
http://blog.coocla.org/category/saltstack
http://pengyao.org/
资源站点:
https://github.com/saltstack/
https://github.com/saltstack-formulas
https://github.com/cssug