时间:2021-07-01 10:21:17 帮助过:6人阅读
以mysql为例配置参考:
https://docs.saltstack.com/en/latest/ref/returners/all/salt.returners.mysql.html#module-salt.returners.mysql
安装mysql MySQL-python
[root@node1 salt]# yum install -y mysql-server mysql安装mysql
[root@node1 ~]# yum install -y MySQL-python#所有minion都要装该包
[root@node1 ~]# /etc/init.d/mysqld start
[root@node2 ~]# yum install -y MySQL-python
创建salt库及 jids, salt_events ,salt_returns三个表
[root@node1 ~]# 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 ‘salt‘@‘%‘ IDENTIFIED BY ‘salt‘;
flush privileges;
远程登录测试
[root@node2 ~]# mysql -h 192.168.10.129 -usalt -psalt
mysql>
法一:该方法是由minion直接将数据写到mysql
[root@node1 ~]# vim /etc/salt/minion
[root@node1 ~]# tail /etc/salt/minion
#return: mysql
mysql.host: ‘192.168.10.129‘
mysql.user: ‘salt‘
mysql.pass: ‘salt‘
mysql.db: ‘salt‘
mysql.port: 3306
[root@node1 ~]# /etc/init.d/salt-minion restart
[root@node2 ~]# vim /etc/salt/minion
[root@node2 ~]# tail /etc/salt/minion
#return: mysql
mysql.host: ‘192.168.10.129‘
mysql.user: ‘salt‘
mysql.pass: ‘salt‘
mysql.db: ‘salt‘
mysql.port: 3306
[root@node2 ~]# /etc/init.d/salt-minion restart
[root@node1 ~]# salt ‘*‘ test.ping --return mysql
mysql> select * from salt_returns;
法二:该方法直接在master上配置,minion端将信息返回到master的缓存,在从缓存信息中写入数据库
[root@node1 ~]# vim /etc/salt/master
[root@node1 ~]# 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
[root@node1 ~]# /etc/init.d/salt-master restart
[root@node1 ~]# salt ‘*‘ cmd.run ‘df -h’
mysql> select * from salt_returns;
本文出自 “feng” 博客,请务必保留此出处http://fengxiaoli.blog.51cto.com/12104465/1957998
salt 执行结果返回mysql
标签:saltstack