设为首页 收藏本站
查看: 1733|回复: 0

[经验分享] SaltStack-job管理

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-11-10 08:49:11 | 显示全部楼层 |阅读模式
一、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)验证是否写入数据库

执行如下命令
[iyunv@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查看命令

[iyunv@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,可以使用如下方法

[iyunv@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
[iyunv@linux-node1 ~]# salt '*' saltutil.running
linux-node2.example.com:
linux-node1.example.com:

4、master端cache

存放位置

[iyunv@linux-node1 /var/cache/salt/master]# ls
file_lists  jobs  minions  proc  queues  roots  syndics  tokens
[iyunv@linux-node1 /var/cache/salt/master]# pwd
/var/cache/salt/master
[iyunv@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
[iyunv@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的返回

[iyunv@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

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




运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-298235-1-1.html 上篇帖子: Saltstack 安装 下篇帖子: SaltStck 搭建Web集群运用示例 (一)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表