首页 > 代码库 > saltstack 管理命令
saltstack 管理命令
salt相关的管理命令:
salt-run manage.up # 查看存活的minion
salt-run manage.down # 查看死掉的minion
salt-run manage.down removekeys=True # 查看down掉的minion,并将其删除
salt-run manage.status # 查看minion的相关状态
salt-run manage.versions # 查看salt的所有master和minion的版本信息
salt-run jobs.active # 查看哪些系统任务还在处理中
salt-run jobs.list_jobs # 显示所有的已完成或部分完成的任务信息
salt ‘*‘ saltutil.running # 查看运行的jobs ID
salt \* saltutil.kill_job 20151209034239907625 # kill掉进程ID
salt -d # 查看帮助文档
salt -d|grep service # 查看service相关模块命令
salt ‘*‘ sys.doc # 查看帮助文档
salt-key -L # 查询所有接收到的证书
salt-key -a <证书名> # 接收单个证书
salt-key -A # 接受所有证书
salt-key -d <证书名> # 删除单个证书
salt-key -D # 删除所有证书
salt ‘*‘ service.get_all # 获取主机所有服务
salt ‘*‘ service.reload sshd # 重载sshd服务
salt ‘*‘ pkg.list_pkgs # 显示软件包版本列表
salt ‘*‘ pkg.version python # 显示软件包版本信息
salt ‘*‘ pkg.install httpd # 安装软件包
salt ‘node1.com‘ service.status mysql # 查看mysql服务状态
salt ‘node1.com‘ service.start mysql # 启动mysql服务
salt ‘node1.com‘ cmd.run ‘service mysql status‘ # 与上面一样查看服务
salt ‘*‘ sys.list_modules # 模块列表
salt-cp ‘*‘ /etc/hosts /etc/hosts # 把master上的hosts文件分发到所有主机
salt ‘*‘ cp.get_file salt://ceshi/b /tmp/test # 把salt-master端相应的文件,分发文件到minion端
salt ‘*‘ cp.get_dir salt://zabbix /tmp # 把salt-master端相应的目录,分发文件到minion端
salt ‘*‘ file.copy /tmp/zabbix.sls /tmp/sls # 把salt-master端对应文件拷贝到minion端相应目录下
salt ‘*‘ cmd.run ‘uptime‘ # 远程命令执行测试
远程执行脚本:
‘cmd.script:‘ salt ‘*‘ cmd.script salt://scripts/runme.sh salt ‘*‘ cmd.script salt://scripts/runme.sh ‘arg1 arg2 "arg 3"‘ salt ‘*‘ cmd.script salt://scripts/windows_task.ps1 args=‘ -Input c:\tmp\infile.txt‘ shell=‘powershell‘ salt ‘*‘ cmd.script salt://scripts/runme.sh stdin=‘one\ntwo\nthree\nfour\nfive\n‘ ‘cmd.shell:‘ This passes the cmd argument directly to the shell salt ‘*‘ cmd.shell "ls -l | awk ‘/foo/{print \$2}‘" salt ‘*‘ cmd.shell template=jinja "ls -l /tmp/{{grains.id}} | awk ‘/foo/{print \$2}‘" salt ‘*‘ cmd.shell "Get-ChildItem C:\ " shell=‘powershell‘ salt ‘*‘ cmd.shell "grep f" stdin=‘one\ntwo\nthree\nfour\nfive\n‘ salt ‘*‘ cmd.shell cmd=‘sed -e s/=/:/g‘ ‘cmd.shells:‘ salt ‘*‘ cmd.shells ‘cmd.tty:‘ salt ‘*‘ cmd.tty tty0 ‘This is a test‘ salt ‘*‘ cmd.tty pts3 ‘This is a test‘ ‘cmd.which:‘ salt ‘*‘ cmd.which cat
grains选项:
salt ‘*‘ grains.ls # 查看grains分类 salt ‘*‘ grains.items # 查看grains所有信息 salt ‘*‘ grains.item osrelease # 查看grains某个信息
说明:state模块是salt state的管理模块,可以通过state模块简单的对minion操作sls状态
salt ‘node1.com‘ state.highstate # 更新指定minons的所有sls状态 salt ‘node1.com‘ state.running # 查看当前运行的sls状态
相关例子:
[root@master ~]# salt \* saltutil.running node02.saltstack.com: |_ ---------- arg: - egrep -v ^# fun: cmd.run jid: 20170221141733009548 pid: 5922 ret: tgt: * tgt_type: glob user: root |_ ---------- arg: - egrep -v ^# fun: cmd.run jid: 20170221141748160358 pid: 5927 ret: tgt: * tgt_type: glob user: root node01.saltstack.com: |_ ---------- arg: - egrep -v ^# fun: cmd.run jid: 20170221141733009548 pid: 6252 ret: tgt: * tgt_type: glob user: root |_ ---------- arg: - egrep -v ^# fun: cmd.run jid: 20170221141748160358 pid: 6256 ret: tgt: * tgt_type: glob user: root [root@master ~]# salt \* saltutil.kill_job 20170221141748160358 node01.saltstack.com: Signal 9 sent to job 20170221141748160358 at pid 6256 node02.saltstack.com: Signal 9 sent to job 20170221141748160358 at pid 5927 [root@master ~]# salt \* saltutil.kill_job 20170221141733009548 node02.saltstack.com: Signal 9 sent to job 20170221141733009548 at pid 5922 node01.saltstack.com: Signal 9 sent to job 20170221141733009548 at pid 6252 [root@master ~]# salt \* saltutil.running node01.saltstack.com: node02.saltstack.com: [root@master ~]# salt-run manage.versions Master: 2015.5.10 Up to date: ---------- node01.saltstack.com: 2015.5.10 node02.saltstack.com: 2015.5.10 [root@RS1 states]# salt-run manage.status down: up: - minion.saltstack.com - minion2.saltstack.com [root@RS1 ~]# salt-run manage.versions# 查看salt的所有master和minion的版本信息 Master: 2015.5.10 Up to date: ---------- minion.saltstack.com: 2015.5.10 minion2.saltstack.com: 2015.5.10 [root@RS1 ~]# salt ‘*‘ test.ping -v# 使用-v参数,能够查看到job的jid Executing job with jid 20170214142709337088 ------------------------------------------- minion.saltstack.com: True minion2.saltstack.com: True 说明:每执行一个任务,都会有一个对应的jid [root@RS1 ~]# salt ‘*‘ saltutil.running# 查看minion当前正在运的jobs minion2.saltstack.com: |_ ---------- arg: fun: state.highstate jid: 20170214143846076337 pid: 5488 ret: tgt: * tgt_type: glob user: root minion.saltstack.com: |_ ---------- arg: fun: state.highstate jid: 20170214143846076337 pid: 6384 ret: tgt: * tgt_type: glob user: root [root@RS1 ~]# salt ‘*‘ saltutil.kill_job 20170214143846076337 取消正在执行的某个jid,例如:20170214143846076337 [root@master ~]# salt-run jobs.list_jobs 20170221155927733273: ---------- Arguments: Function: state.running StartTime: 2017, Feb 21 15:59:27.733273 Target: node01.saltstack.com Target-type: glob User: root 20170221160325920754: ---------- Arguments: Function: sys.doc StartTime: 2017, Feb 21 16:03:25.920754 Target: * Target-type: glob User: root 20170221161556599324: ---------- Arguments: - cat Function: cmd.which StartTime: 2017, Feb 21 16:15:56.599324 Target: * Target-type: glob User: root 20170221161641114901: ---------- Arguments: Function: grains.ls StartTime: 2017, Feb 21 16:16:41.114901 Target: * Target-type: glob User: root
本文出自 “冰冻vs西瓜” 博客,请务必保留此出处http://molewan.blog.51cto.com/287340/1899890
saltstack 管理命令