设为首页 收藏本站
查看: 1566|回复: 0

[经验分享] 运维自动化 SaltStack 安装

[复制链接]
累计签到:5 天
连续签到:1 天
发表于 2018-8-1 07:18:21 | 显示全部楼层 |阅读模式
运维自动化 SaltStack
SaltStack介绍:(略)
设置epel源
  rpm -ivh 'http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm'
yum安装master、minion
Master主机安装:
  [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、
Minion主机安装:
  [root@wdds_2 yum.repos.d]# yum install salt-minion
启动salt
  [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
master、minion配置文件说明:
saltstack 简单使用
  [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
根据被控主机的grains信息进行匹配过滤
  [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

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-544393-1-1.html 上篇帖子: saltstack的深入-配置zabbix所需的mysql-server 下篇帖子: saltstack的深入-配置zabbix所需的server,web,agent
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表