Install mysql on 11
yum install mariadb mariadb-server -y
Add in mysql configuration file my.cnf
init_connect='SET collation_connection = utf8_unicode_ci' init_connect='SET NAMES utf8' character-set-server=utf8 collation-server=utf8_unicode_ci skip-character-set-client-handshake
Start mysql after configuration
Set the password before logging in mysql for the first time:
mysql_secure_installation
Add the configuration files at the end of all master and minion
mysql.host: 172.16.1.11 mysql.user: root mysql.pass: 123456 mysql.db: salt mysql.port: 3306
Create mysql Library
create database salt;
Create table
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;
Install MySQL Python on both mater and minion
salt '*' cmd.run 'yum install MySQL-python -y'
Configure the PY script VIM salt? Event? To? Mysql.py on the master side
#!/bin/env python #coding=utf8 import json import salt.config import salt.utils.event import MySQLdb __opts__ = salt.config.client_config('/etc/salt/master') conn = MySQLdb.connect(host=__opts__['mysql.host'], user=__opts__['mysql.user'], passwd=__opts__['mysql.pass'], db=__opts__['mysql.db'],port=__opts__['mysql.port'],charset='utf8') corsor = conn.cursor() event = salt.utils.event.MasterEvent(__opts__['sock_dir']) for eachevent in event.iter_events(full=True): ret = eachevent['data'] if "salt/job/" in eachevent['tag']: if ret.has_key('id') and ret.has_key('return'): if ret['fun'] == "saltutil.find_job": continue sql = '''INSERT INTO `salt_returns` (`fun`,`jid`,`return`,`id`,`success`,`full_ret`) VALUES (%s,%s,%s,%s,%s,%s)''' cursor.execute(sql, (ret['fun'],ret['jid'],json.dumps(ret['return']),ret['id'],ret['success'],json.dumps(ret))) cursor.execute("COMMIT") else: pass(Pay attention to the script mysql Where to connect, conn = MySQLdb.connect(host="172.16.1.11",user="root",passwd="930829",db="salt"))
Startup script
python salt_event_to_mysql.py &
Check the mysql situation (after executing test.ping in the mater, data in the salt'returns table indicates normal)