Saltstack execution results are saved to MySQL for command security audits
Must be an environment above python2.7
Install related modules
Ubuntu System Installation
Apt-get install-y Python-mysqldb
CentOS System Installation
Yum Install-y Mysql-python
database, related table creation, and account creation authorization
Official website: https://docs.saltstack.com/en/latest/ref/returners/all/salt.returners.mysql.html#module-salt.returners.mysql
create DATABASE ' salt ' DEFAULT CHARACTER SET utf8default 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 INDEX Jid on Jids (Jid) USING BTREE; CREATE TABLE ' salt_returns ' (' fun ' varchar (#) NOT null, ' jid ' varchar (255) is not NULL, ' return ' mediumtext not NULL, ' ID ' varchar (255) NOT NULL, ' success ' varchar (TEN) NOT null, ' Full_ret ' mediumtext not null, ' Alter_time ' TIMESTAMP Defau LT 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, ' AL Ter_time ' TIMESTAMP DEFAULT current_timestamp, ' master_id ' varchar (255) Not null,primary key (' ID '), key ' tag ' (' tag ')) ENG Ine=innodb DEFAULT Charset=utf8;
Create a database account and authorize
Grant all privileges the salt.* to [email protected] ' localhost ' identified by ' xxxxxxxx ';
Salt-master Salt-minion Terminal Related configuration
Method One
Add database-related information on all Minion-side configurations
Locate the #return:mysql in the Minion file after you add the database related information
#return: MySQL
Mysql.host: ' 192.168.217.20 '
Mysql.user: ' Salt '
Mysql.pass: ' xxxxx '
Mysql.db: ' Salt '
mysql.port:3306
Reboot so the client
Method Two
Turn on the master side of the Master_job_cache, the method does not need to Minion end configuration database related information, if also configured Minion-side database related information, then the execution results will be stored in the database two copies
The configuration is as follows:
#return: mysqlmaster_job_cache:mysqlmysql.host: ' 192.168.217.20 ' mysql.user: ' Salt ' mysql.pass: ' wclwcw1101! ' Mysql.db: ' Salt ' mysql.port:3306
Restart Salt-master
Saltstack execution results stored to MySQL