Returner
salt
支持的returners
列表
查看当前salt-minion上面支持多少returner,有的环境可以没有装太多的returner
salt '*' sys.list_returners
Returner原理
master下发指令后,minion将结果返回给master,同时写一份数据至其他扩展的系统,可以是mysql、mongo、syslog、stmp等;
github上面写的有现成的第三方组件 salt-returners
MySQL Returner
官网link: salt.returners.mysql
Master端配置
查看已经当前salt
版本已经支持的returners
salt '*' sys.list_returners
若不支持mysql
,进行如下操作,若已经支持,则忽略
下载 mysql.py 至/srv/salt/_returners
目录下,使用以下任何命令进行同步
Minion端配置
安装MySQL-python
yum install -y MySQL-python
修改配置文件/etc/salt/minion
return: mysql
mysql.host: 'xxxxx'
mysql.user: 'root'
mysql.pass: 'xxxxx'
mysql.db: 'salt'
mysql.port: 3306
以下的数据库当中需要创建如下SQL
:
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;
执行命令
salt '*' test.ping --return mysql
查询数据
SELECT * FROM salt_returns;
Mongo Return
Master同样的操作
Minion
安装pymongo依赖
yum install pymongo -y
修改配置文件/etc/salt/minion
return: mongo
mongo.db: salt
mongo.host: xxxx
mongo.user: root
mongo.password: xxxx
mongo.port: 27017
Redis Return
Master同样操作
Minion
安装python redis
yum install python2-redis -y
修改配置文件/etc/salt/minion
return: redis
redis.db: '0'
redis.host: 'salt'
redis.port: 6379
执行命令
salt '*' test.ping --return redis
查看redis结果
127.0.0.1:6379> keys *
1) "ret:20191230212420062280"
2) "F6572042-D38D-464D-0A2E-80ACAD430903:state.highstate"
3) "ret:req"
4) "F6572042-D38D-464D-0A2E-80ACAD430903:cmd.run"
5) "ret:20191230212656663741"
6) "ret:20191230212954734477"
7) "F6572042-D38D-464D-0A2E-80ACAD430903:test.ping"
8) "ret:20191230212927159795"
9) "minions"
10) "F6572042-D38D-464D-0A2E-80ACAD430903:saltutil.sync_returners"