saltstack之(十一)扩展组件salt-returners
场景:每次执行salt任务后,将返回结果存入到数据库,可以做任务跟踪以及历史查看。
1.在node1上安装mysql数据库并启动设置root密码。
[root@node1 ~]# yum -y install mysql-server MySQL-python
[root@node1 ~]# service mysqld start
[root@node1 ~]# mysqladmin -uroot password 123456
2.数据库建库建表语句。
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;
3.在node2上编辑/etc/salt/minion文件,并重新启动salt-minion服务,文件修改如下:
[root@node2 salt]# tail -n 5 /etc/salt/minion
mysql.host: '192.168.3.1'
mysql.user: 'root'
mysql.pass: '123456'
mysql.db: 'salt'
mysql.port: 3306
[root@node1 ~]# service salt-minion restart
4.在node1上远程执行命令并指定返回数据写入MySQL,登陆并查看数据库内容。
[root@node1 ~]# salt 'node2.xkops.com' test.ping --return mysql
mysql>select * from salt.salt_events;