1. 程式人生 > >salt-api return mysql返回的使用,記錄操作日誌

salt-api return mysql返回的使用,記錄操作日誌

需要 操作日誌 tab pre node var nac incr day

說在前面

  • 折騰這個搞了半天,現做下記錄

安裝依賴(操作只在master端)

yum install mysql-python or pip install mysql-python

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;

更新salt的master配置文件

[root@VM_75_82_centos private]# egrep -v ‘^$|^#‘ /etc/salt/master
default_include: master.d/*.conf
auto_accept: True
interface: 0.0.0.0
mysql.host: ‘10.105.75.81‘    
mysql.user: ‘root‘
mysql.pass: ‘123456#‘
mysql.db: ‘salt‘
mysql.port: 3306
file_roots:
   base:
     - /srv/salt/
pillar_roots:
  base:
    - /srv/pillar
return: mysql
master_job_cache: mysql     #使用此選項後,就不需要minion端配置

測試返回

[root@VM_75_82_centos private]# salt ‘*‘ cmd.run ‘ls‘ 
node82:
    anaconda-ks.cfg
[root@VM_75_82_centos private]# salt ‘*‘ cmd.run ‘uptime‘ 
node82:
     20:15:20 up 1 day,  8:06,  2 users,  load average: 0.07, 0.13, 0.13

查看數據庫已經有數據了

技術分享圖片

salt-api return mysql返回的使用,記錄操作日誌