默认情况下,salt-master发送给minion的命令执行结果将返回给salt-master。而saltstack-returner提供的接口允许将返回结果发送给任意系统
http://docs.saltstack.com/en/latest/ref/returners/index.html将返回结果记录到日志文件中
salt '*' test.ping --return syslog //如此操作将会把返回结果记录到日志中将返回结果记录到mysql中
1.安装mysql
yum -y install mysql mysql-server
2.修改minion端的配置文件(所有minion端都要修改)
vim /etc/salt/minion
mysql.host: '192.168.1.105' //mysql服务器的IP地址
mysql.user: 'salt' //mysql数据库的用户名,需要跟后面授权的用户名一致
mysql.pass: 'salt' //mysql数据库的密码,需要跟后面授权的密码一致
mysql.db: 'salt' //mysql数据库的名称
mysql.port: 3306 //使用端口为3306
3.在salt-master上重启所有minion的服务
salt '*' service.restart minion
4.启动mysql服务
/etc/init.d/mysqld start
5.修改mysql数据库root密码
/usr/bin/mysqladmin -u root password '123456'
6.在mysql中创建数据库salt
mysql -uroot -p //进入mysql
输入两次密码以后进入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;
--
-- 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,
KEY `id` (`id`),
KEY `jid` (`jid`),
KEY `fun` (`fun`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;授权
grant all on salt.* to salt@'192.168.1.%' identified by "salt"; //前面salt是授权的用户名,后面的salt是授权用户salt的密码。
flush privileges;在所有minion上安装MySQL-python模块(在master上进行操作)
salt '*' cmd.run 'yum -y install MySQL-python'测试
在master上执行测试命令:
salt '*' cmd.run 'hostname' --return mysql
然后在mysql数据库上进行查证:
mysql> select * from salt_returns
-> \G //这是执行的查询命令
这是查询得出的结果:
*************************** 1. row ***************************
fun: cmd.run
jid: 20150518232157296491
return: "Admin3-saltstack.littlebee.com"
id: Admin3-saltstack.littlebee.com
success: 1
full_ret: {"fun_args": ["hostname"], "jid": "20150518232157296491", "return": "Admin3-saltstack.littlebee.com", "retcode": 0, "success": true, "fun": "cmd.run", "id": "Admin3-saltstack.littlebee.com"}
*************************** 2. row ***************************
fun: cmd.run
jid: 20150518232157296491
return: "Admin2-saltstack.littlebee.com"
id: Admin2-saltstack.littlebee.com
success: 1
full_ret: {"fun_args": ["hostname"], "jid": "20150518232157296491", "return": "Admin2-saltstack.littlebee.com", "retcode": 0, "success": true, "fun": "cmd.run", "id": "Admin2-saltstack.littlebee.com"}
2 rows in set (0.00 sec)
转载于:https://blog.51cto.com/ryomajia/1652625