salt 執行結果返回mysql
可以存放的數據庫有哪些:https://docs.saltstack.com/en/latest/ref/returners/all/index.html
以mysql為例配置參考:
https://docs.saltstack.com/en/latest/ref/returners/all/salt.returners.mysql.html#module-salt.returners.mysql
安裝mysql MySQL-python
[[email protected] salt]# yum install -y mysql-server mysql安裝mysql
[[email protected]
[[email protected] ~]# /etc/init.d/mysqld start
[[email protected] ~]# yum install -y MySQL-python
創建salt庫及 jids, salt_events ,salt_returns三個表
[[email protected] ~]# mysql
CREATE DATABASE `salt`
DEFAULT CHARACTER SET utf8
DEFAULT COLLATE utf8_general_ci;
USE `salt`;
CREATE TABLE `jids` (
`jid` varchar(255) NOT NULL,
`load` mediumtext NOT NULL,
UNIQUE KEY `jid` (`jid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
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;
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 [email protected]%‘ IDENTIFIED BY ‘salt‘;
flush privileges;
遠程登錄測試
[[email protected] ~]# mysql -h 192.168.10.129 -usalt -psalt
mysql>
法一:該方法是由minion直接將數據寫到mysql
[[email protected] ~]# vim /etc/salt/minion
[[email protected] ~]# tail /etc/salt/minion
#return: mysql
mysql.host: ‘192.168.10.129‘
mysql.user: ‘salt‘
mysql.pass: ‘salt‘
mysql.db: ‘salt‘
mysql.port: 3306
[[email protected] ~]# /etc/init.d/salt-minion restart
[[email protected] ~]# vim /etc/salt/minion
[[email protected] ~]# tail /etc/salt/minion
#return: mysql
mysql.host: ‘192.168.10.129‘
mysql.user: ‘salt‘
mysql.pass: ‘salt‘
mysql.db: ‘salt‘
mysql.port: 3306
[[email protected] ~]# /etc/init.d/salt-minion restart
[[email protected] ~]# salt ‘*‘ test.ping --return mysql
mysql> select * from salt_returns;
法二:該方法直接在master上配置,minion端將信息返回到master的緩存,在從緩存信息中寫入數據庫
[[email protected] ~]# vim /etc/salt/master
[[email protected] ~]# tail /etc/salt/master
master_job_cache: mysql
mysql.host: ‘192.168.10.129‘
mysql.user: ‘salt‘
mysql.pass: ‘salt‘
mysql.db: ‘salt‘
mysql.port: 3306
[[email protected] ~]# /etc/init.d/salt-master restart
[[email protected] ~]# salt ‘*‘ cmd.run ‘df -h’
mysql> select * from salt_returns;
本文出自 “feng” 博客,請務必保留此出處http://fengxiaoli.blog.51cto.com/12104465/1957998
salt 執行結果返回mysql