saltstack 把数据返回到mysql服务器
环境:http://www.cnblogs.com/zzzhfo/p/5790918.html
master端需要安装MySQL-python和mysql-server
mysql-server用于存储minion数据,MySQL-python用来收集数据
master端
安装mysql-server和MySQL-python
[root@salt-master /]# yum -y install mysql-server MySQL-python
启动数据库
[root@salt-master /]# /etc/init.d/mysqld start
[root@salt-master /]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.1. Source distribution Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
CREATE DATABASE `salt`
DEFAULT CHARACTER SET utf8
DEFAULT COLLATE utf8_general_ci; USE `salt`;
如下:
mysql> CREATE DATABASE `salt`
-> DEFAULT CHARACTER SET utf8
-> DEFAULT COLLATE utf8_general_ci;
Query OK, row affected (0.00 sec) mysql> USE `salt`;
Database changed
表结构表的jid
CREATE TABLE `jids` (
`jid` varchar(255) NOT NULL,
`load` mediumtext NOT NULL,
UNIQUE KEY `jid` (`jid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
mysql> CREATE TABLE `jids` (
-> `jid` varchar() NOT NULL,
-> `load` mediumtext NOT NULL,
-> UNIQUE KEY `jid` (`jid`)
-> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, rows affected (0.02 sec)
表结构表“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;
mysql> CREATE TABLE `salt_returns` (
-> `fun` varchar() NOT NULL,
-> `jid` varchar() NOT NULL,
-> `return` mediumtext NOT NULL,
-> `id` varchar() NOT NULL,
-> `success` varchar() 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;
Query OK, rows affected (0.01 sec)
表结构表“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> CREATE TABLE `salt_events` (
-> `id` BIGINT NOT NULL AUTO_INCREMENT,
-> `tag` varchar() NOT NULL,
-> `data` mediumtext NOT NULL,
-> `alter_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
-> `master_id` varchar() NOT NULL,
-> PRIMARY KEY (`id`),
-> KEY `tag` (`tag`)
-> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, rows affected (0.00 sec)
授权
mysql> grant all on salt.* to salt@'192.168.161.132' identified by 'salt';
Query OK, 0 rows affected (0.00 sec)
测试
[root@salt-master /]# mysql -u salt -p -h 192.168.161.132
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.1. Source distribution Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| salt |
| test |
+--------------------+
rows in set (0.00 sec)
修改/etc/salt/master
[root@salt-master /]# vim /etc/salt/master
mysql.host: '192.168.161.132'
mysql.user: 'salt'
mysql.pass: 'salt'
mysql.db: 'salt'
mysql.port:
重启master
[root@salt-master /]# /etc/init.d/salt-master restart
Stopping salt-master daemon: [ OK ]
Starting salt-master daemon: [ OK ]
minion端
[root@salt-minion /]# yum -y install MySQL-python
修改/etc/salt/minion 添加如下内容
[root@salt-minion /]# vim /etc/salt/minion
mysql.host: '192.168.161.132'
mysql.user: 'salt'
mysql.pass: 'salt'
mysql.db: 'salt'
mysql.port:
重启minion
[root@salt-minion /]# /etc/init.d/salt-minion restart
Stopping salt-minion daemon: [ OK ]
Starting salt-minion daemon: [ OK ]
测试
[root@salt-master /]# salt '*' test.ping --return mysql
salt-minion:
True root@salt-master /]# mysql -u salt -p -h 192.168.161.132
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.1. Source distribution Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> use salt;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed mysql> select * from salt_returns;
+-----------+----------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------+---------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------+
| fun | jid | return | id | success | full_ret | alter_time |
+-----------+----------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------+---------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------+
| test.ping | | true | salt-minion | | {"fun_args": [], "jid": "", "return": true, "retcode": , "success": true, "fun": "test.ping", "id": "salt-minion"} | -- :: |
+-----------+----------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------+---------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------+
rows in set (0.00 sec)
方法2
master端安装MySQL-python和mysql-server
minion端不需要安装MySQL-python包
操作步骤略(与发一相同)
[root@salt-master /]# vim /etc/salt/master 追加如下内容
master_job_cache: mysql #每次执行不加--return mysql由master端将返回的数据写入数据库 不需要minion
重启服务
[root@salt-master /]# /etc/init.d/salt-master restart
Stopping salt-master daemon: [ OK ]
Starting salt-master daemon: [ OK ]
测试
[root@salt-master /]# salt 'salt-minion' test.ping
salt-minion:
True
[root@salt-master /]# salt 'salt-minion' cmd.run 'df -h'
salt-minion:
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 18G 935M 16G % /
tmpfs 495M 12K 495M % /dev/shm
/dev/sda1 194M 27M 158M % /boot
root@salt-master /]# mysql -u salt -p -h 192.168.161.131
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.1.73 Source distribution Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> use salt;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
mysql> select * from salt_returns;
+-----------+----------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------+---------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------+
| fun | jid | return | id | success | full_ret | alter_time |
+-----------+----------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------+---------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------+
| test.ping | 20160826200517605155 | true | salt-minion | 1 | {"fun_args": [], "jid": "20160826200517605155", "return": true, "retcode": 0, "success": true, "fun": "test.ping", "id": "salt-minion"} | 2016-08-26 20:05:17 |
| test.ping | 20160826202029989457 | true | salt-minion | 1 | {"fun_args": [], "jid": "20160826202029989457", "return": true, "retcode": 0, "success": true, "cmd": "_return", "_stamp": "2016-08-26T12:20:30.138166", "fun": "test.ping", "id": "salt-minion"} | 2016-08-26 20:20:30 |
| cmd.run | 20160826202045948708 | "Filesystem Size Used Avail Use% Mounted on\n/dev/sda3 18G 935M 16G 6% /\ntmpfs 495M 12K 495M 1% /dev/shm\n/dev/sda1 194M 27M 158M 15% /boot" | salt-minion | 1 | {"fun_args": ["df -h"], "jid": "20160826202045948708", "return": "Filesystem Size Used Avail Use% Mounted on\n/dev/sda3 18G 935M 16G 6% /\ntmpfs 495M 12K 495M 1% /dev/shm\n/dev/sda1 194M 27M 158M 15% /boot", "retcode": 0, "success": true, "cmd": "_return", "_stamp": "2016-08-26T12:20:45.984974", "fun": "cmd.run", "id": "salt-minion"} | 2016-08-26 20:20:46 |
+-----------+----------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------+---------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------+
3 rows in set (0.00 sec)
saltstack 把数据返回到mysql服务器的更多相关文章
- 【SpringMVC】SpringMVC系列9之Model数据返回到View
9.Model数据返回到View 9.1.概述 Spring MVC 提供了以下几种途径输出模型数据: ModelAndView: 处理方法返回值类型为 ModelAndView 时, 方法体 ...
- 将jsp页面的<s:iterator>的数据返回到action
jsp: <form method="post" id="createTable"> <table width="98%" ...
- MySQL服务器是怎么处理客户端请求的
不论MySQL客户端进程和服务器进程是采用哪种方式进行通信,最后实现的效果都是:客户端进程向服务器进程发送一段文本(MySQL语句),服务器进程处理后再向客户端进程发送一段文本(处理结果).那服务器进 ...
- jsp 配置MySQL服务器 以及数据的插入和读取
不多说,直接上代码.百度上面也是一大堆,大家多问百度就行. 在利用JDBC访问数据库过程中,主要涉及三种资源:对数据库的连接的连接对象Connection,SQL语句对象 Statement,访问结果 ...
- MySQL 服务器变量 数据操作DML-视图
原文:MySQL 服务器变量 数据操作DML-视图 SQL语言的组成部分 常见分类: DDL:数据定义语言 DCL:数据控制语言,如授权 DML:数据操作语言 其它分类: 完整性定义语言: DDL的一 ...
- MySQL(一) -- MySQL学习路线、数据库的基础、关系型数据库、关键字说明、SQL、MySQL数据库、MySQL服务器对象、SQL的基本操作、库操作、表操作、数据操作、中文数据问题、 校对集问题、web乱码问题
1 MySQL学习路线 基础阶段:MySQL数据库的基本操作(增删改查),以及一些高级操作(视图.触发器.函数.存储过程等). 优化阶段:如何提高数据库的效率,如索引,分表等. 部署阶段:如何搭建真实 ...
- jmeter连接配置带跳板机(SSH)的mysql服务器
jmeter连接配置mysql服务器时,如果数据库服务器没有通过ssh连接,则只需要配置相应的jdbc参数就可以了,即请求域名或ip地址:3306,如果数据库服务器是通过SSH连接的,那需要通过中间远 ...
- 闰秒导致MySQL服务器的CPU sys过高
今天,有个哥们碰到一个问题,他有一个从库,只要是启动MySQL,CPU使用率就非常高,其中sys占比也比较高,具体可见下图. 注意:他的生产环境是物理机,单个CPU,4个Core. 于是,他抓取了CP ...
- MYSQL服务器my.cnf配置文档详解
MYSQL服务器my.cnf配置文档详解 硬件:内存16G [client] port = 3306 socket = /data/3306/mysql.sock [mysql] no-auto-re ...
随机推荐
- Maven打包含有Main方法jar并运行
最近使用Kettle做定时数据抽取,因为Job更新或需求变更,修改Bug等种种原因,需要对重跑Job一般是针对每天的数据重跑一次.刚开始的做法是直接在自己的开发机器上重跑,这样速度比较慢,因为这时候你 ...
- [LeetCode] Shortest Distance from All Buildings 建筑物的最短距离
You want to build a house on an empty land which reaches all buildings in the shortest amount of dis ...
- 使用WCF传输DataTable:DataTable和Xml格式的字符串相互转换(C#)
背景:项目中要用到客户端向服务端传数据,使用WCF,绑定webHttpBinding,做了一个小例子. 业务逻辑简介:客户端在a表中添加了几条数据,从SQL Server数据库直接取出新添加的数据(D ...
- Docker命令学习
今天更换腾讯云系统的时候发现了多了个CoreOS,据说是专门运行docker的轻量系统,顺便学习一下docker命令. 1. docker version 显示 Docker 版本信息. 2. doc ...
- iOS推送流程
1. 在apple开发者帐号上创建一个BundleID,创建证书或者Xcode上都是用这个BundleID(例如com.mycompany.pushDemo) 2. 代码层面: 在capability ...
- linux 压缩包覆盖问题
最近提交代码自动化构建发布的时候,出现了之前被删除的代码还是被打包发布了的问题. 流程是这样,jenkins通过定时任务获取git的提交,检测到有新提交时,就把代码拉下来通过maven进行build. ...
- iframe 跨域相互操作
我们在开发后台管理系统时可能会经常要跟 iframe 打交道,因为现在大部分后台管理系统都是页面内嵌iframe,所以有时候两者之间就难免要互相通信,但浏览器为了安全的原因,所以就禁止了不同域的访问, ...
- jQuery实现二级菜单
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- ftp同步代码
一个很naive的代码,用来做ftp的"主->从 下载,从->主 上传".ftp可不像mysql那样还有log可以用,所以完全naive的做法:连到ftp server ...
- Ubuntu学习总结-09 安装 Pycharm
一 下载 PyCharm 从以下网址下载Linux版本的Pycharm,这里使用的版本是pycharm-professional-2016.2.3.tar.gz . http://www.jetbra ...