Saltstack_使用指南13_runner的job和manage与execution的saltutil
程序员文章站
2023-01-28 17:19:52
1. 主机规划 salt 版本 job 管理文档 runner modules文档 Salt runners类似于Salt execution modules,但是前者是在master端执行的,后者是在minion端执行的。 execution modules文档 注意事项 修改了master或者m ......
1. 主机规划
salt 版本
1 [root@salt100 ~]# salt --version 2 salt 2018.3.3 (oxygen) 3 [root@salt100 ~]# salt-minion --version 4 salt-minion 2018.3.3 (oxygen)
job 管理文档
https://docs.saltstack.com/en/latest/topics/jobs/index.html
runner modules文档
salt runners类似于salt execution modules,但是前者是在master端执行的,后者是在minion端执行的。
1 https://docs.saltstack.com/en/latest/ref/cli/salt-run.html 2 https://docs.saltstack.com/en/latest/ref/runners/index.html 3 https://docs.saltstack.com/en/latest/ref/runners/all/index.html
execution modules文档
1 https://docs.saltstack.com/en/latest/ref/modules/all/index.html 2 https://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.saltutil.html
注意事项
修改了master或者minion的配置文件,那么必须重启对应的服务。
2. salt-run jobs常用方法
1 # 返回正在活动中的jobs信息 2 salt-run jobs.active 3 # 列出所有可检测的jobs和相关functions 4 salt-run jobs.list_jobs 5 # 根据 jid 列出指定的job 6 salt-run jobs.list_job 20190111160734604439 7 # 返回以前执行job的打印输出【回看当时job输出的信息】 8 salt-run jobs.lookup_jid 20190111170928354082
示例信息如下
1 [root@salt100 ~]# salt-run jobs.active 2 20190111170928354082: 3 ---------- 4 arguments: 5 - df -h && sleep 30 6 function: 7 cmd.run 8 returned: 9 running: 10 |_ 11 ---------- 12 salt01: 13 2640 14 starttime: 15 2019, jan 11 17:09:28.354082 16 target: 17 salt01 18 target-type: 19 glob 20 user: 21 root 22 20190111170930696130: 23 ---------- 24 arguments: 25 - whoami && sleep 30 26 function: 27 cmd.run 28 returned: 29 running: 30 |_ 31 ---------- 32 salt01: 33 2646 34 starttime: 35 2019, jan 11 17:09:30.696130 36 target: 37 salt01 38 target-type: 39 glob 40 user: 41 root 42 [root@salt100 ~]# salt-run jobs.lookup_jid 20190111170928354082 # 显示信息如下 43 salt01: 44 filesystem size used avail use% mounted on 45 /dev/sda3 18g 2.1g 16g 12% / 46 devtmpfs 901m 0 901m 0% /dev 47 tmpfs 911m 12k 911m 1% /dev/shm 48 tmpfs 911m 9.6m 902m 2% /run 49 tmpfs 911m 0 911m 0% /sys/fs/cgroup 50 /dev/sda1 197m 113m 85m 58% /boot 51 tmpfs 183m 0 183m 0% /run/user/1001
3. salt-run manage常用方法
salt的常规管理功能,比如查看哪些hosts上线或下线
1 salt-run manage.list_state 2 salt-run manage.alived 3 salt-run manage.status 4 salt-run manage.down 5 salt-run manage.up 6 salt-run manage.versions
4. saltutil模块
1 # 返回minion端正在执行salt 进程的数据 2 salt '*' saltutil.running 3 # 杀掉指定 jid【jobid】进程 4 salt '*' saltutil.kill_job 20190111180228662382
示例信息
1 [root@salt100 ~]# salt '*' saltutil.running 2 salt03: 3 salt01: 4 |_ 5 ---------- 6 arg: 7 - whoami && sleep 300 8 fun: 9 cmd.run 10 jid: 11 20190111175718092279 12 pid: 13 2825 14 ret: 15 tgt: 16 salt01 17 tgt_type: 18 glob 19 user: 20 root 21 salt02: 22 salt100: 23 [root@salt100 ~]# salt '*' saltutil.kill_job 20190111180228662382 24 salt03: 25 salt02: 26 salt100: 27 salt01: 28 signal 9 sent to job 20190111180228662382 at pid 2882
5. 实战应用
5.1. master执行
1 [root@salt100 master]# salt 'salt01' cmd.run 'whoami && sleep 300' # 执行后,然后 ctrl+c 终端 2 ^c 3 exiting gracefully on ctrl-c 4 this job's jid is: 20190111223139879350 5 the minions may not have all finished running and any remaining minions will return upon completion. to look up the return data for this job later, run the following command: 6 7 salt-run jobs.lookup_jid 20190111223139879350 8 [root@salt100 master]# 9 [root@salt100 master]# salt '*' cmd.run 'whoami && sleep 300' # 第二次执行
5.2. 查看当前活动的jobs
通过如下方式查看可知,虽然之前 ctrl + c 了,但是minion端还是在执行相应的进行。
5.2.1. 方式一
1 [root@salt100 ~]# salt-run jobs.active 2 20190111223139879350: 3 ---------- 4 arguments: 5 - whoami && sleep 300 6 function: 7 cmd.run 8 returned: 9 running: 10 |_ 11 ---------- 12 salt01: 13 3458 14 starttime: 15 2019, jan 11 22:31:39.879350 16 target: 17 salt01 18 target-type: 19 glob 20 user: 21 root 22 20190111223234549650: 23 ---------- 24 arguments: 25 - whoami && sleep 300 26 function: 27 cmd.run 28 returned: 29 running: 30 |_ 31 ---------- 32 salt02: 33 2840 34 |_ 35 ---------- 36 salt03: 37 2835 38 |_ 39 ---------- 40 salt100: 41 40929 42 |_ 43 ---------- 44 salt01: 45 3500 46 starttime: 47 2019, jan 11 22:32:34.549650 48 target: 49 * 50 target-type: 51 glob 52 user: 53 root
5.2.2. 方式二
1 [root@salt100 ~]# salt '*' saltutil.running 2 salt100: 3 |_ 4 ---------- 5 arg: 6 - whoami && sleep 300 7 fun: 8 cmd.run 9 jid: 10 20190111223234549650 11 pid: 12 40929 13 ret: 14 tgt: 15 * 16 tgt_type: 17 glob 18 user: 19 root 20 salt02: 21 |_ 22 ---------- 23 arg: 24 - whoami && sleep 300 25 fun: 26 cmd.run 27 jid: 28 20190111223234549650 29 pid: 30 2840 31 ret: 32 tgt: 33 * 34 tgt_type: 35 glob 36 user: 37 root 38 salt03: 39 |_ 40 ---------- 41 arg: 42 - whoami && sleep 300 43 fun: 44 cmd.run 45 jid: 46 20190111223234549650 47 pid: 48 2835 49 ret: 50 tgt: 51 * 52 tgt_type: 53 glob 54 user: 55 root 56 salt01: 57 |_ 58 ---------- 59 arg: 60 - whoami && sleep 300 61 fun: 62 cmd.run 63 jid: 64 20190111223139879350 65 pid: 66 3458 67 ret: 68 tgt: 69 salt01 70 tgt_type: 71 glob 72 user: 73 root 74 |_ 75 ---------- 76 arg: 77 - whoami && sleep 300 78 fun: 79 cmd.run 80 jid: 81 20190111223234549650 82 pid: 83 3500 84 ret: 85 tgt: 86 * 87 tgt_type: 88 glob 89 user: 90 root
5.3. kill 对应的salt进程
1 [root@salt100 ~]# salt '*' saltutil.kill_job 20190111223139879350 2 salt02: 3 salt03: 4 salt100: 5 salt01: 6 signal 9 sent to job 20190111223139879350 at pid 3458
——————end——————
上一篇: awk处理实记
下一篇: ajax后台处理返回json值示例代码