使用salt-ssh批量管理主机
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用salt-ssh批量管理主机相关的知识,希望对你有一定的参考价值。
安装salt-ssh:yum install -y salt-master salt-ssh master配置文件:cat /etc/salt/master file_roots: base: - /srv/salt/ dev: - /srv/salt/dev/services - /srv/salt/dev/states prod: - /srv/salt/prod/services - /srv/salt/prod/states top.sls文件:cat /srv/salt/top.sls base: ‘roles:nginx‘: - match: grain - init.pkg - init.limit limit文件:cat /srv/salt/init/limit.sls limit-conf-config: file.managed: - name: /tmp/limits.conf - source: salt://init/files/limits.conf - user: root - group: root - mod: 644 - name: /tmp/df.sh - source: salt://init/files/df.sh - user: root - group: root - mod: 644 files目录:ls /srv/salt/init/files df.sh limits.conf df.sh文件:cat /srv/salt/init/files/df.sh #!/bin/bash hostname roster文件:cat /etc/salt/roster test1.discuz.com: host: test1.discuz.com user: root passwd: redhat test2.discuz.com: host: test2.discuz.com user: root passwd: redhat tomcat1.discuz.com: host: tomcat1.discuz.com user: root passwd: centos tomcat2.discuz.com: host: tomcat2.discuz.com user: root passwd: centos 传送文件到各主机:salt-ssh ‘*‘ state.sls init.limit 在各主机执行脚本:salt-ssh ‘*‘ cmd.run ‘bash /tmp/df.sh‘ 生成roster脚本 roster.sh文件:cat /root/roster.sh #!/bin/bash >/etc/salt/roster IFS=‘ ‘ cat /root/hosts | while read line do arr=($line) echo ${arr[0]}":">>/etc/salt/roster echo " host: "${arr[0]}>>/etc/salt/roster echo " user: "${arr[1]}>>/etc/salt/roster echo " passwd: "${arr[2]}>>/etc/salt/roster done hosts文件:cat /root/hosts test1.discuz.com root redhat test2.discuz.com root redhat tomcat1.discuz.com root centos tomcat2.discuz.com root centos
以上是关于使用salt-ssh批量管理主机的主要内容,如果未能解决你的问题,请参考以下文章