vzdsa 发表于 2015-8-13 08:49:38

运维自动化 SaltStack 安装

SaltStack介绍:(略)设置epel源rpm -ivh 'http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm'
yum安装master、minionMaster主机安装:# 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、
Minion主机安装:# yum install salt-minion启动salt# service salt-master start
Starting salt-master daemon:                               [确定]
# 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# ps aux |grep salt
root       28060.02.6 368028 21072 ?      S    23:39   0:00 /usr/bin/python2.6 /usr/bin/salt-master -d
root       28073.13.5 475152 28936 ?      Sl   23:39   0:00 /usr/bin/python2.6 /usr/bin/salt-master -d
root       28080.02.6 454052 21440 ?      Sl   23:39   0:00 /usr/bin/python2.6 /usr/bin/salt-master -d
root       28090.52.8 454052 22828 ?      Sl   23:39   0:00 /usr/bin/python2.6 /usr/bin/salt-master -d
root       28100.02.5 368028 20744 ?      S    23:39   0:00 /usr/bin/python2.6 /usr/bin/salt-master -d
root       28159.84.0 1150132 32560 ?       Sl   23:39   0:02 /usr/bin/python2.6 /usr/bin/salt-master -d
root       2816 10.64.0 1150136 32560 ?       Sl   23:39   0:02 /usr/bin/python2.6 /usr/bin/salt-master -d
root       2817 10.84.0 1150136 32568 ?       Sl   23:39   0:02 /usr/bin/python2.6 /usr/bin/salt-master -d
root       2818 10.94.0 1150140 32564 ?       Sl   23:39   0:02 /usr/bin/python2.6 /usr/bin/salt-master -d
root       2821 11.74.0 1150144 32572 ?       Sl   23:39   0:03 /usr/bin/python2.6 /usr/bin/salt-master -d
root       28220.12.6 757172 21628 ?      Sl   23:39   0:00 /usr/bin/python2.6 /usr/bin/salt-master -d
root       32710.00.1 103256   840 pts/0    R+   23:39   0:00 grep saltmaster: 10.0.0.61
master、minion配置文件说明:
saltstack 简单使用# salt-key -L      查看当前的key信息
Accepted Keys:
Denied Keys:
Unaccepted Keys:
wdds_2
wdds_3
Rejected Keys:
# salt-key -a wdds_2   接受单个主机(-d删除)
The following keys are going to be accepted:
Unaccepted Keys:
wdds_2
Proceed? Y
Key for minion wdds_2 accepted.
# salt-key -A      接收所有主机(-D删除所有)
The following keys are going to be accepted:
Unaccepted Keys:
wdds_3
Proceed? y
Key for minion wdds_3 accepted.# salt-key
Accepted Keys:
wdds_2
wdds_3
Denied Keys:
Unaccepted Keys:
Rejected Keys:测试# salt '*' cmd.run 'echo helloworld'
wdds_3:
    helloworld
wdds_2:
    helloworld
远程执行命令测试# salt '*' cmd.run 'uptime'         
wdds_2:
    20:00:26 up1:05,1 user, load average: 0.17, 0.06, 0.01
根据被控主机的grains信息进行匹配过滤# salt -G 'os:Centos'test.ping
wdds_2:
True显示被控主机的操作系统类型#salt '*' grains.item os
wdds_2:
   ----------
   os:
       CentOS

#salt '*' grains.item查看minion主机grains信息
远程代码执行测试# salt '*' cmd.exec_codepython 'import sys; print sys.version'
wdds_2:
   2.6.6 (r266:84292, Jul 23 2015, 15:22:56)
   
常用模块介绍
(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等,还有如下高级命令的使用,以及模板配置的渲染、扩展模块的二次开发等,可以自己去深入学习哈。


页: [1]
查看完整版本: 运维自动化 SaltStack 安装