salt return mysql返回的使用,记录操作日志
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了salt return mysql返回的使用,记录操作日志相关的知识,希望对你有一定的参考价值。
1、安装依赖(操作只在master端)
yum -y install mysql-python
2、master端本地数据库中创建对应的表结构
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、更新salt的master配置文件
[[email protected] salt]# pwd /etc/salt [[email protected] salt]# egrep -v ‘^$|^#‘ master default_include: master.d/*.conf interface: 192.168.24.66 auto_accept: True file_roots: base: - /srv/salt pillar_roots: base: - /srv/salt/pillar return: mysql mysql.host: ‘192.168.24.66‘ mysql.user: ‘salt‘ mysql.pass: ‘salt‘ mysql.db: ‘salt‘ mysql.port: 3306 master_job_cache: mysql //使用此选项后,就不需要minion端配置
4、测试返回
[[email protected] ~]# salt ‘*‘ cmd.run ‘df -h‘ --return mysql 192.168.24.67: Filesystem Size Used Avail Use% Mounted on /dev/sda3 93G 4.4G 84G 5% / tmpfs 1.9G 12K 1.9G 1% /dev/shm /dev/sda1 190M 146M 31M 83% /boot 192.168.24.68: Filesystem Size Used Avail Use% Mounted on /dev/sda3 93G 4.4G 84G 5% / tmpfs 1.9G 12K 1.9G 1% /dev/shm /dev/sda1 190M 146M 31M 83% /boot
已经写入数据库
以上是关于salt return mysql返回的使用,记录操作日志的主要内容,如果未能解决你的问题,请参考以下文章