STORING JOB RESULTS IN AN EXTERNAL SYSTEM
将salt任务执行结果可以存放到以下两种环境中:
(1)本地磁盘的缓存目录中,master配置的缓存目录
(2)存放到外部系统中
目前有两种配置模式:
1、配置minion端将任务结果发送到数据库或redis等外部接口系统
2、配置master端将任务结果发送到master端,再将数据存入外部接口,譬如mysql数据库这样便于以后查找审计等。
示例图,模式1:
示例图,模式2:
以下只演示收集到master再录到mysql数据库中的模式,MySQL安装到master上
参考链接:http://docs.saltstack.cn/ref/returners/all/salt.returners.mysql.html#module-salt.returners.mysql
master端配置:
1、安装依赖包MYSQL-Python
yum install MySQL-python -y
2、配置数据库环境,用户权限,建库建表,赋权
grant all privileges on *.* to 'salt'@'%' identified by '123';
CREATE USER 'salt'@'%' IDENTIFIED BY '123';
flush privileges;
1 CREATE DATABASE `salt` 2 DEFAULT CHARACTER SET utf8 3 DEFAULT COLLATE utf8_general_ci; 4 5 USE `salt`; 6 7 -- 8 -- Table structure for table `jids` 9 -- 10 11 DROP TABLE IF EXISTS `jids`; 12 CREATE TABLE `jids` ( 13 `jid` varchar(255) NOT NULL, 14 `load` mediumtext NOT NULL, 15 UNIQUE KEY `jid` (`jid`) 16 ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 17 CREATE INDEX jid ON jids(jid) USING BTREE; 18 19 -- 20 -- Table structure for table `salt_returns` 21 -- 22 23 DROP TABLE IF EXISTS `salt_returns`; 24 CREATE TABLE `salt_returns` ( 25 `fun` varchar(50) NOT NULL, 26 `jid` varchar(255) NOT NULL, 27 `return` mediumtext NOT NULL, 28 `id` varchar(255) NOT NULL, 29 `success` varchar(10) NOT NULL, 30 `full_ret` mediumtext NOT NULL, 31 `alter_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, 32 KEY `id` (`id`), 33 KEY `jid` (`jid`), 34 KEY `fun` (`fun`) 35 ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 36 37 -- 38 -- Table structure for table `salt_events` 39 -- 40 41 DROP TABLE IF EXISTS `salt_events`; 42 CREATE TABLE `salt_events` ( 43 `id` BIGINT NOT NULL AUTO_INCREMENT, 44 `tag` varchar(255) NOT NULL, 45 `data` mediumtext NOT NULL, 46 `alter_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, 47 `master_id` varchar(255) NOT NULL, 48 PRIMARY KEY (`id`), 49 KEY `tag` (`tag`) 50 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3、master端主配置文件编辑
master_job_cache: mysql
如果是minion端配置外部存储则配置为:ext_job_cache: mysql
mysql.host: 'localhost'
mysql.user: 'salt'
mysql.pass: '123'
mysql.db: 'salt'
mysql.port: 3306
4、重启服务,手动执行任务,查看日志是否有报警信息,数据库中是否有相应的条目
/etc/init.d/salt-master restart
salt 'XXXX' test.ping --return mysql #手动触发返回数据到mysql