saltstack(十二):saltstack输出处理—Saltstack job cache(写入数据库)

 

 

saltstack(十二):saltstack输出处理—Saltstack job cache(写入数据库)

https://www.unixhot.com/docs/saltstack/ref/returners/all/salt.returners.mysql.html#module-salt.returners.mysql

1.1         master端安装Python MySQL模块

yum install  MySQL-python –y

1.2         /etc/salt/master添加

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

1.3         MySQL机器建库授权连接

建库

CREATE DATABASE  `salt`

  DEFAULT CHARACTER SET utf8

  DEFAULT COLLATE utf8_general_ci;

 

USE `salt`;

 

--

-- Table structure for table `jids`

--

 

DROP TABLE IF EXISTS `jids`;

CREATE TABLE `jids` (

  `jid` varchar(255) NOT NULL,

  `load` mediumtext NOT NULL,

  UNIQUE KEY `jid` (`jid`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE INDEX jid ON jids(jid) USING BTREE;

 

--

-- Table structure for table `salt_returns`

--

 

DROP TABLE IF EXISTS `salt_returns`;

CREATE TABLE `salt_returns` (

  `fun` varchar(50) NOT NULL,

  `jid` varchar(255) NOT NULL,

  `return` mediumtext NOT NULL,

  `id` varchar(255) NOT NULL,

  `success` varchar(10) NOT NULL,

  `full_ret` mediumtext NOT NULL,

  `alter_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,

  KEY `id` (`id`),

  KEY `jid` (`jid`),

  KEY `fun` (`fun`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

 

--

-- Table structure for table `salt_events`

--

 

DROP TABLE IF EXISTS `salt_events`;

CREATE TABLE `salt_events` (

`id` BIGINT NOT NULL AUTO_INCREMENT,

`tag` varchar(255) NOT NULL,

`data` mediumtext NOT NULL,

`alter_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,

`master_id` varchar(255) NOT NULL,

PRIMARY KEY (`id`),

KEY `tag` (`tag`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;
建库语句

 

授权

grant all on salt.* to salt@10.6.76.27 identified by 'salt';
flush privileges;

master连接测试

[root@pe-jira ~]# mysql -usalt -psalt -h10.6.76.28

Warning: Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 395412

Server version: 5.6.27-log Source distribution

 

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

 

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| salt               |

+--------------------+

2 rows in set (0.00 sec)

 

mysql> 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

 

Database changed

mysql> show tables;

+----------------+

| Tables_in_salt |

+----------------+

| jids           |

| salt_events    |

| salt_returns   |

+----------------+

3 rows in set (0.00 sec)

 

mysql>
View Code

 

1.4         重启salt-master

systemctl restart salt-master

1.5         测试

salt 命令-v 显示 jid

 

1.6        kill salt正在执行的任务

https://www.cnblogs.com/shhnwangjian/p/6048891.html

https://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.saltutil.html#module-salt.modules.saltutil

salt '*' saltutil.running  # 查看正在运行的任务,找到jid
salt '*' saltutil.kill_job jid  # 根据jid杀掉任务
salt '*' saltutil.clear_cache  # 清除minion缓存

 

 

备注:

1)正在执行的salt任务,job id会存在minion端的/var/cache/salt/minion/proc目录下

2)正在执行的salt任务,根据上面master cache的配置,Job的路径/var/cache/salt/master/jobs目录下

 

1.10         saltstack 二次开发建议

1、master job cache 讲所有的job输出保存到MySQL

2、管理平台,可以把用户user_ID和jid做管理


 

posted on 2019-06-05 17:09  光阴8023  阅读(705)  评论(0编辑  收藏  举报