saltstack使用mysql存储推送信息

中文官网:http://docs.saltstack.cn/

将saltstack执行命令返回的信息存储到mysql

方法一:
minion端控制:
python和mysql交互需要一个模块–mysql-python

[root@server2 ~]# yum install -y MySQL-python.x86_64
[root@server2 ~]# vim /etc/salt/minion
874 mysql.host: '172.25.76.1'
875 mysql.user: 'salt'
876 mysql.pass: 'westos'
877 mysql.db: 'salt'
878 mysql.port: 3306
[root@server2 ~]# systemctl restart salt-minion.service 

master:

[root@server1 ~]# yum install -y mariadb-server MySQL-python.x86_64 
[root@server1 ~]# systemctl start mariadb
[root@server1 ~]# mysql
MariaDB [(none)]> grant all on salt.* to salt@'%' identified by 'westos';
创建数据库
[root@server1 ~]# vim add.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;

导入数据库

[root@server1 ~]# mysql < add.sql 

测试:

[root@server1 ~]# salt '*' test.ping --return mysql
server2:
    True
server3:
    True

MariaDB [salt]> select * from salt_returns;

saltstack使用mysql存储推送信息_第1张图片

方法二:

master端有缓存24小时,通过缓存将命令执行结果放在数据库中

[root@server1 ~]# vim /etc/salt/master
master_job_cache: mysql
mysql.host: 'localhost'
mysql.user: 'salt'
mysql.pass: 'westos'
mysql.db: 'salt'
mysql.port: 3306

[root@server1 ~]# systemctl restart salt-master
MariaDB [(none)]> grant all on salt.* to salt@'localhost' identified by 'westos';
[root@server1 ~]# salt '*' cmd.run 'hostname'
server3:
    server3
server2:
    server2

[root@server1 ~]# mysql -u salt -p salt

saltstack使用mysql存储推送信息_第2张图片

你可能感兴趣的:(linux)