深刻学习saltstack远程执行(四)

结构:mysql

命令:salt(固定的)web

目标:‘*’    正则表达式

模块:cmd.run   一共有150多种模块sql

返回:执行后返回的结构数据库

 

 

详解目标ssh

                    1 minion ID(ID名字)spa

                    2 通配符  (*,daxian00[1|2|3],daxian00[1-3]等)rest

                    3  列表     (salt -L 'daxian001,daxian002' test.ping)code

                    4 正则表达式(slat -E 'daxian(001|002)*' test.ping)blog

                    全部匹配目标的方式,均可以用到TOPfile里面指定

  

详解模块(经常使用的)

显示arp表  

 salt '*' network.arp   

 

显示主机名          

salt '*' network.get_hostname
web01:
web02
web02:
web03

 

查看服务是否存活

salt '*' service.available sshd
web01:
True
web02:
True

 

 查看全部正在运行的服务

salt '*' service.get_all

 

重载

salt '*' service.reload <service name>

 

重启

salt '*' service.restart <service name>

 

启动

salt '*' service.start <service name>

状态

salt '*' service.status <service name>

中止

salt '*' service.stop <service name>

 

拷贝文件

salt-cp '*' /etc/hosts /tmp/

 

查看top都干什么事情

salt '*' state.show_top

 

 

返回程序:

   将返回的程序返回到mysql 数据库里

   

 

编写状态模块:

  放在:/srv/salt/_modules

  命名: 文件名就是模块名 my_disk.py

  

def list():
  cmd = 'df -h'
  ret = __salt__['cmd.run'](cmd)
return ret

刷新

salt '*' saltutil.sync_modules

会把文件刷新到minion端

 /var/cache/salt/minion/extmods/

执行

salt '*' my_disk.list

相关文章
相关标签/搜索