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

[[email protected] /]# yum -y install mysql-server MySQL-python

启动数据库

[[email protected] /]# /etc/init.d/mysqld start
[[email protected]-master /]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
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> 
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, 1 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(255) NOT NULL,
    ->   `load` mediumtext NOT NULL,
    ->   UNIQUE KEY `jid` (`jid`)
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 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(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;
Query OK, 0 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(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;
Query OK, 0 rows affected (0.00 sec)

授权

mysql> grant all on salt.* to [email protected]‘192.168.161.131‘ identified by ‘salt‘;
Query OK, 0 rows affected (0.00 sec)

测试

[[email protected] /]# 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 5
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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| salt               |
| test               |
+--------------------+
3 rows in set (0.00 sec)

修改/etc/salt/master

[[email protected] /]# vim /etc/salt/master
mysql.host: ‘192.168.161.131‘
mysql.user: ‘salt‘
mysql.pass: ‘salt‘
mysql.db: ‘salt‘
mysql.port: 3306

重启master

[[email protected] /]# /etc/init.d/salt-master restart
Stopping salt-master daemon: [ OK ]
Starting salt-master daemon: [ OK ]

minion端

[[email protected] /]# yum -y install MySQL-python

修改/etc/salt/minion 添加如下内容

[[email protected] /]# vim /etc/salt/minionmysql.host: ‘192.168.161.131‘
mysql.user: ‘salt‘
mysql.pass: ‘salt‘
mysql.db: ‘salt‘
mysql.port: 3306

重启minion

[[email protected] /]# /etc/init.d/salt-minion restart
Stopping salt-minion daemon:                               [  OK  ]
Starting salt-minion daemon:                               [  OK  ]

测试

[[email protected] /]# salt ‘*‘ test.ping --return mysql
salt-minion:
    True

[email protected]-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 |
+-----------+----------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------+---------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------+
1 rows in set (0.00 sec)

方法2

master端安装MySQL-python和mysql-server

minion端不需要安装MySQL-python包

操作步骤略(与发一相同)

[[email protected] /]# vim /etc/salt/master   追加如下内容
master_job_cache: mysql      #每次执行不加--return mysql由master端将返回的数据写入数据库 不需要minion

重启服务

[[email protected] /]# /etc/init.d/salt-master restart
Stopping salt-master daemon: [ OK ]
Starting salt-master daemon: [ OK ]

测试

[[email protected] /]# salt ‘salt-minion‘ test.ping
salt-minion:
    True
[[email protected]-master /]# salt ‘salt-minion‘ cmd.run ‘df -h‘
salt-minion:
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sda3        18G  935M   16G   6% /
    tmpfs           495M   12K  495M   1% /dev/shm
    /dev/sda1       194M   27M  158M  15% /boot
[email protected] /]# 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)
时间: 2024-10-18 01:18:56

saltstack 把数据返回到mysql服务器的相关文章

将jsp页面的<s:iterator>的数据返回到action

jsp: <form method="post" id="createTable"> <table width="98%" border="0" cellspacing="0" cellpadding="0" align="center"> <tr> <td height="10"></td&g

CentOS6.4 配置mysql服务器启动多个端口,同步单表数据

============================================================ ====多端口启动==== ============================================================ 创建数据目录 mkdir /usr/local/mysql/var1/ mkdir /usr/local/mysql/var2/ =================================================

jsp 配置MySQL服务器 以及数据的插入和读取

不多说,直接上代码.百度上面也是一大堆,大家多问百度就行. 在利用JDBC访问数据库过程中,主要涉及三种资源:对数据库的连接的连接对象Connection,SQL语句对象 Statement,访问结果集ResultSet 或 RowSet. package ShopCar; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLExcepti

由于master宕机等导致resource调用出现异常,直接将该resource返回到pool以便其他代码使用会导致得到不可预期的结果,导致返回数据混乱。

实现一:public String get(final String key) {              Jedis resource = null;              try {                           resource = pool.getResource();                            return resource.get(key);           } finally {                      

将SQL Server 2000数据导入到MySQL 5.5的方法

一.安装MySQL 5.5(可以与SQL Server不在同一台服务器上),并新建一个空的数据库(一般用utf-8编码),用于接收导入的数据. 二.在SQL Server的服务器上安装mysql-connector-odbc-5.3.2-win32. 三.在SQL Server的服务器上运行"管理工具"->"数据源(ODBC)",切换到"系统DSN"面板,添加"MySQL ODBC 5.3 Unicode Driver"

jmeter连接配置带跳板机(SSH)的mysql服务器

jmeter连接配置mysql服务器时,如果数据库服务器没有通过ssh连接,则只需要配置相应的jdbc参数就可以了,即请求域名或ip地址:3306,如果数据库服务器是通过SSH连接的,那需要通过中间远程连接工具来登录,此处使用的远程连接工具为Putty,配置的时候需要将数据库的ssh->tunnel中的请求域名先映射到本地3306的端口(一般mysql的请求端口设置为3306,只是符合大众流~~~),然后通过ssh的服务器ip及端口来访问,具体的配置请参考如下: 1.首先,下载并打开Putty喽

mysql服务器(一)

mysql服务器 1.mysql安装 版本:mysql-advanced-5.6.23-linux-glibc2.5-x86_64 具体可以参考目录下的INSTALL-BINARY文件 #安装mysql,将mysql压缩解压到/usr/local tar zxvf mysql-advanced-5.6.23-linux-glibc2.5-x86_64.tar.gz -C /uar/local/mysql cd /usr/local ln -s mysql-advanced-5.6.23-linu

将excel数据导入到mysql

一.            将excel数据另存为txt文件 二.            将txt文件拷贝到mysql服务器中 保证txt文件在mysql系统中打开无乱码 三.            创建库和表 CREATE TABLE `list2` ( `name` varchar(50) DEFAULT NULL, `changjia` varchar(50) DEFAULT NULL, `weight` varchar(100) DEFAULT NULL, `count` varchar

zabbix-3.2.4监控mysql服务器性能

环境:centos7已安装 zabbix-agent-3.2.4-2.el7.x86_64 zabbix-server-mysql-3.2.4-2.el7.x86_64 zabbix-web-3.2.4-2.el7.noarch zabbix-web-mysql-3.2.4-2.el7.noarch zabbix-release-3.2-1.el7.noarch zabbix-get-3.2.4-2.el7.x86_64 查看zabbix_agentd.conf配置文件: PidFile=/va