saltstatck - 远程执行 3. 返回数据写入
官方
https://docs.saltstack.com/en/latest/ref/returners/all/salt.returners.mysql.html#module-salt.returners.mysql
安装依赖
yum install python-devel pip install MySQL-python
两种方式配置 ### 1. 在 matser 配置 mysql -e "grant all privileges on salt.* to salt@'127.0.0.1'identified by'salt';" #数据库添加 salt 账号本地访问 vi /etc/salt/master
master_job_cache: mysql mysql.host: '127.0.0.1' mysql.user: 'salt' mysql.pass: 'salt' mysql.db: 'salt' mysql.port: 3306
返回测试(master 端写数据库)
salt '*' cmd.run 'uptime'
在 minion 方法
mysql -e "grant all privileges on salt.* to salt@'%' identified by 'salt';" #数据库添加salt账号授权远程访问vi /etc/salt/minionmysql.host: '192.168.1.110'
mysql.user: 'salt'
mysql.pass: 'salt'
mysql.db: 'salt'
mysql.port: 3306return: mysql #salt操作不加--return mysql也会强制写入mysql表里面
返回测试(minion 端写数据库)
</pre>
salt '*' test.ping --return mysql返回是minion端返回
创建表结构 -----mysql -uroot -p #进入数据库 CREATE DATABASEsalt
DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci; USEsalt
; -- -- Table structure for tablejids
-- DROP TABLE IF EXISTSjids
; CREATE TABLEjids
(jid
varchar(255) NOT NULL,load
mediumtext NOT NULL, UNIQUE KEYjid
(jid
) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE INDEX jid ON jids(jid) USING BTREE; -- -- Table structure for tablesalt_returns
-- DROP TABLE IF EXISTSsalt_returns
; CREATE TABLEsalt_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, KEYid
(id
), KEYjid
(jid
), KEYfun
(fun
) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -- Table structure for tablesalt_events
-- DROP TABLE IF EXISTSsalt_events
; CREATE TABLEsalt_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
), KEYtag
(tag
) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;数据库查询
mysql> select * from salt_returnsG;
1. row ** fun: test.ping
jid: 20170921222510247262
return: true
id: Test1
success: 1
full_ret: {"fun_args": [], "jid": "20170921222510247262", "return": true, "retcode": 0, "success": true, "fun": "test.ping", "id": "Test1"}
alter_time: 2017-09-21 22:25:10
1 row in set (0.00 sec)
标签: 无
当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »