自动化运维之四Saltstack之Job管理

1.Saltstack之Job管理

1.1简介

当我们每执行一个状态salt '*' state.highstate就会产生一个任务,在我们日常的工作当中这样的任务是需要管理起来的

如:1.网络中断,无返回结果,不知任务是否执行完成 2.刚执行一个Job后,yum安装一个数据包导致卡死想把其kill掉 3.把最近的操作记录列出来

1.2Job的缓存路径

[root@linux-node1 ~]# cd /var/cache/salt/master/
[root@linux-node1 master]# ll
total 4
drwxr-xr-x 3 root root 18 Oct 15 10:29 file_lists
drwxr-xr-x 152 root root 4096 Oct 18 02:40 jobs
drwxr-xr-x 4 root root 66 Oct 15 06:20 minions
drwxr-xr-x 2 root root 6 Oct 14 18:20 proc
drwxr-xr-x 2 root root 6 Oct 14 18:20 queues
drwxr-xr-x 3 root root 33 Oct 15 10:29 roots
drwxr-xr-x 2 root root 6 Oct 14 18:20 syndics
drwxr-xr-x 2 root root 51 Oct 18 06:28 thin
drwxr-xr-x 2 root root 6 Oct 14 18:20 tokens
[root@linux-node1 master]# cd jobs/
[root@linux-node1 jobs]# ls
01 11 1e 2d 3c 48 56 5f 6b 77 8a 9b a6 b5 c4 d6 e0 f1 fa
02 12 21 2e 3d 4a 57 60 6c 7c 8c 9c a7 b6 c5 d7 e3 f2 fb
03 13 25 31 3e 4b 58 61 70 7e 8d 9d a8 b8 c6 d8 e8 f3 fc
05 15 27 32 3f 4c 59 63 72 81 91 9e ab bc ca da ea f5 fd
06 19 28 35 42 4d 5a 64 73 82 92 9f ad bd cc db eb f6 fe
07 1a 29 36 43 50 5b 66 74 83 93 a0 ae c0 cd dc ed f7 ff
08 1b 2b 37 44 51 5c 68 75 86 95 a2 b1 c1 d0 de ee f8
0f 1d 2c 38 47 55 5d 6a 76 87 96 a4 b4 c2 d1 df ef f9
[root@linux-node1 jobs]# cd 0
01/ 02/ 03/ 05/ 06/ 07/ 08/ 0f/ 
[root@linux-node1 jobs]# cd 02/
[root@linux-node1 02]# ls
242982fdafa1814796c260d072c80c 7d72c31bc028bd3e9a71b97c46a0cb
#缓存时间默认24小时
[root@linux-node1 linux-node1.example.com]# vim /etc/salt/master
#keep_jobs: 24

1.3Job的管理模块执行模块

官网链接地址:https://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.saltutil.html

salt '*' saltutil.find_cached_job <job id>
salt '*' saltutil.find_job <job id>  #查询正在运行的Job
salt '*' saltutil.is_running state.highstate  #查看当前正在运行的jid
[root@linux-node1 linux-node1.example.com]# salt '*' saltutil.running
linux-node2.example.com:
 |_
 ----------
 arg:
 - sleep 60
 fun:
 cmd.run
 jid:
 20181019074951971598
 pid:
 9764
 ret:
 tgt:
 *
 tgt_type:
 glob
 user:
 root
linux-node1.example.com:
 |_
 ----------
 arg:
 - sleep 60
 fun:
 cmd.run
 jid:
 20181019074951971598
 pid:
 66498
 ret:
 tgt:
 *
 tgt_type:
 glob
 user:
 root
salt '*' saltutil.kill_job <job id>  ##kill正在工作的job

 

0
如无特殊说明,文章均为本站原创,转载请注明出处

该文章由 发布

这货来去如风,什么鬼都没留下!!!
发表我的评论

Hi,请填写昵称和邮箱!

取消评论
代码 贴图 加粗 链接 删除线 签到