存在的记忆

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/minion

mysql.host: '192.168.1.110'
mysql.user: 'salt'
mysql.pass: 'salt'
mysql.db: 'salt'
mysql.port: 3306

return: mysql #salt操作不加--return mysql也会强制写入mysql表里面

返回测试(minion 端写数据库)
</pre>
salt '*' test.ping --return mysql

返回是minion端返回


创建表结构
-----
mysql -uroot -p #进入数据库

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;

数据库查询

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」版。查看和发表评论请点击:完整版 »