salt 执行结果返回mysql
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了salt 执行结果返回mysql相关的知识,希望对你有一定的参考价值。
可以存放的数据库有哪些:https://docs.saltstack.com/en/latest/ref/returners/all/index.html
以mysql为例配置参考:
安装mysql MySQL-python
[[email protected] salt]# yum install -y mysql-server mysql安装mysql
[[email protected] ~]# yum install -y MySQL-python#所有minion都要装该包
[[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 ‘salt‘@‘%‘ 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的主要内容,如果未能解决你的问题,请参考以下文章
saltstacksaltstack之job返回数据salt-sshsalt-syndic分布式架构salt-api部署