SaltStack-job管理
admin
2023-06-04 06:01:48
0

一、salt执行结果默认返回给master端

1、job cache

存放位置

# Directory to store job and cache data:
# This directory may contain sensitive data and should be protected accordingly.
#
#cachedir: /var/cache/salt/master

# Set the number of hours to keep old job information in the job cache:
#keep_jobs: 24

# The number of seconds to wait when the client is requesting information
# about running jobs.
#gather_job_timeout: 10

2、将cache存入数据库

(1)安装数据库连接模块

安装连接mysql的模块MySQL-python
yum install -y MySQL-python

(2)配置数据库连接

在master上配置连接

直接在master的配置文件后面追加内容
vim /etc/salt/master

master_job_cache: mysql
mysql.host: '192.168.56.11'
mysql.user: 'salt'
mysql.pass: '123456'
mysql.db: 'salt'
mysql.port: 3306

(3)重启salt-master

systemctl restart master

(4)验证是否写入数据库

执行如下命令
[root@linux-node1 /srv/salt/prod/bbs]# salt '*' cmd.run 'whoami'
linux-node2.example.com:
    root
linux-node1.example.com:
    root
登录数据库
mysql -h 192.168.56.11 -usalt -p123456
MariaDB [(none)]> use salt;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

*************************** 9. row ***************************
       fun: cmd.run
       jid: 20161109091010973295
    return: "root"
        id: linux-node2.example.com
   success: 1
  full_ret: {"fun_args": ["whoami"], "jid": "20161109091010973295", "return": "root", "retcode": 0, "success": true, "cmd": "_return", "_stamp": "2016-11-09T01:10:11.064745", "fun": "cmd.run", "id": "linux-node2.example.com"}
alter_time: 2016-11-09 09:10:11
*************************** 10. row ***************************
       fun: cmd.run
       jid: 20161109091010973295
    return: "root"
        id: linux-node1.example.com
   success: 1
  full_ret: {"fun_args": ["whoami"], "jid": "20161109091010973295", "return": "root", "retcode": 0, "success": true, "cmd": "_return", "_stamp": "2016-11-09T01:10:11.146238", "fun": "cmd.run", "id": "linux-node1.example.com"}
alter_time: 2016-11-09 09:10:11
10 rows in set (0.00 sec)

3、job查看

先执行一个命令,比如

salt '*' cmd.run 'ping www.baidu.com'

在执行job查看命令

[root@linux-node1 ~]# salt '*' saltutil.running
linux-node2.example.com:
    |_
      ----------
      arg:
          - ping www.baidu.com
      fun:
          cmd.run
      jid:
          20161109091517283293
      pid:
          6049
      ret:
      tgt:
          *
      tgt_type:
          glob
      user:
          root
linux-node1.example.com:
    |_
      ----------
      arg:
          - ping www.baidu.com
      fun:
          cmd.run
      jid:
          20161109091517283293
      pid:
          6269
      ret:
      tgt:
          *
      tgt_type:
          glob
      user:
          root

停止job,可以使用如下方法

[root@linux-node1 ~]# salt '*' saltutil.kill_job 20161109091517283293
linux-node2.example.com:
    Signal 9 sent to job 20161109091517283293 at pid 6049
linux-node1.example.com:
    Signal 9 sent to job 20161109091517283293 at pid 6269
[root@linux-node1 ~]# salt '*' saltutil.running
linux-node2.example.com:
linux-node1.example.com:

4、master端cache

存放位置

[root@linux-node1 /var/cache/salt/master]# ls
file_lists  jobs  minions  proc  queues  roots  syndics  tokens
[root@linux-node1 /var/cache/salt/master]# pwd
/var/cache/salt/master
[root@linux-node1 /var/cache/salt/master]# tree
.
├── file_lists
│   └── roots
│       ├── base.p
│       └── prod.p
├── jobs
│   ├── 6c
│   │   └── 9f646ec75df0bd0ec29760ef0dee7a
│   │       ├── jid
│   │       └── linux-node1.example.com
│   │           └── return.p
│   ├── 90
│   │   └── d3646e58dd82e103973eb889af96d1
│   │       └── jid
│   ├── d4
│   │   └── 74a5b7f1ebf41c84c714d2ad8fda85
│   │       ├── jid
│   │       └── linux-node1.example.com
│   │           └── return.p
│   └── e3
│       └── d2ffbc8e72a923205126c07c9e1e55
│           ├── jid
│           └── linux-node1.example.com
│               └── return.p

二、jobs管理组件

一个方便管理jobs的系统:runners.jobs

列出job cache中的job
[root@linux-node1 /var/cache/salt/master]# salt-run jobs.list_jobs
[WARNING ] /usr/lib/python2.7/site-packages/salt/grains/core.py:1493: DeprecationWarning: The "osmajorrelease" will be a type of an integer.

20161109090923312794:
    ----------
    Arguments:
        - whoami
    Function:
        cmd.run
    StartTime:
        2016, Nov 09 09:09:23.312794
    Target:
        *
    Target-type:
        glob
    User:
        root

查看某个job的返回

[root@linux-node1 ~]# salt-run jobs.lookup_jid 20161109093137760714

linux-node1.example.com:
    PING www.a.shifen.com (119.75.218.70) 56(84) bytes of data.
    64 bytes from 119.75.218.70: icmp_seq=1 ttl=128 time=9.78 ms
    64 bytes from 119.75.218.70: icmp_seq=2 ttl=128 time=4.65 ms
    64 bytes from 119.75.218.70: icmp_seq=3 ttl=128 time=8.26 ms
    
    --- www.a.shifen.com ping statistics ---
    3 packets transmitted, 3 received, 0% packet loss, time 2010ms
    rtt min/avg/max/mdev = 4.657/7.569/9.786/2.150 ms

可以使用salt-run查看当前up和down的minion

[root@linux-node1 ~]# salt-run manage.status
down:
up:
    - linux-node1.example.com
    - linux-node2.example.com


相关内容

热门资讯

“贴耳大吼、扇巴掌”?新生儿入... 近日,四川成都一新生儿入住月子会所仅4天,突发颅内出血被送进ICU一事引发关注。孩子的母亲周女士反映...
特朗普称将就上诉法院涉白宫宴会... △特朗普(资料图)当地时间8月7日,美国总统特朗普在社交平台“真实社交”发文称,将立即就联邦上诉法院...
高景太阳能申请背接触电池前板专... 国家知识产权局信息显示,四川高景太阳能科技有限公司申请一项名为“背接触电池前板、其制备方法及光伏电池...
宿迁市政府领导专题调研江苏省宿... 8月6日,宿迁市副市长陈伟赴江苏省宿迁环境监测中心,专题调研“人工智能+监测”工作开展情况。宿迁市生...
科技改变生活:普通人如何抓住A... 听着, 科技这个词给人的感觉那可是相当的高大上, 就好像它仅仅是属于实验室里头的科学家或者硅谷的那些...
鼓励领导干部带头休假之后又撤回... 近日,河南省委组织部、省人力资源社会保障厅、省商务厅、省文化和旅游厅、省政府国资委、省总工会近日联合...
耗资4亿美元,特朗普的白宫宴会... 据路透社8月7日报道,美国一家联邦上诉法院于本周五下达指令,要求特朗普政府停止在已拆除的白宫东翼旧址...
胡锡进:新西兰外长像只疯狗,竟... 新西兰这几年出了一个对华非常恶毒的外交部长,他叫温斯顿·彼得斯,81岁。他给中新关系带来了与前些年截...
霍尔木兹协议将近达成,美伊正在... 关于霍尔木兹局势有哪些最新消息?凤凰卫视驻伊朗记者李睿从德黑兰发回报道:伊朗与阿曼就霍尔木兹海峡的协...
“新婚前夜输光3000亿”,硅... 文|张雪莹美国加利福尼亚州滨海小镇卡梅尔,终年海雾缭绕的松林海岸间,藏着众多精品艺廊与隐世豪宅,向来...