标签:com names 批量 sql dir cmd stack cti group
yum install mariadb mariadb-server -y
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
mysql_secure_installation
在所有master和minion端的配置文件最后加入
mysql.host: 172.16.1.11 mysql.user: root mysql.pass: 123456 mysql.db: salt mysql.port: 3306
create database salt;
创建表
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;
在mater和minion端都安装MySQL-python
salt ‘*‘ cmd.run ‘yum install MySQL-python -y‘
#!/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
启动脚本
python salt_event_to_mysql.py &
查看mysql情况(在mater中执行了test.ping后在salt_returns表里面有数据表示正常)
vim /etc/salt/master nodegroups: test1: ‘E@salt-client*‘ test2: ‘E@salt-web*‘ 正则 test3: ‘N@test1 or N@test2‘ 和 test4 ‘N@test1 and N@test2‘ 或
salt -N test1 test.ping
salt ‘11‘ sys.doc
file_roots: base: - /srv/salt dev: - /srv/salt/dev prod: - /srv/salt/prod
vim test.sh while true do sleep 1 echo 1 > /tmp/log done
salt ‘*‘ cmd.script salt://etc/script/test.sh
salt ‘*‘ saltutil.running
salt ‘*‘ saltutil.term_job jid
vim /srv/salt/hosts.sls /tmp/hosts: file.managed: - source: salt://etc/hosts - user: root - group: root - mode: 600
vim /srv/salt/top.sls base: ‘*‘: - hosts
(此两个配置文件是将master上的hosts文件部署到minion的/tmp/hosts)
salt ‘*‘ state.highstate
salt ‘*‘ state.sls hosts
salt ‘*‘ state.sls hosts.hosts
salt ‘*‘ state.sls hosts
标签:com names 批量 sql dir cmd stack cti group
原文地址:https://www.cnblogs.com/xiongyoutom/p/9597361.html