saltstack 返回mysql_saltstack返回信息写入数据库

返回

将返回结果写入到mysql中

master端需要安装MySQL-python和mysql-server

mysql-server用来存储minion数据,MySQL-python用来收集数据

master端:

1.安装mysql-server和MySQL-python

yum install MySQL-python mysql-server

2.创建表结构

service mysqld start

CREATE DATABASE `salt`

DEFAULT CHARACTER SET utf8

DEFAULT COLLATE utf8_general_ci;

如下:

创建salt,在salt下添加jids和salt_returns

mysql> CREATE DATABASE `salt`

-> DEFAULT CHARACTER SET utf8

-> DEFAULT COLLATE utf8_general_ci;

Query OK, 1 row affected (0.00 sec)

mysql>

3,在USE salt下创建js表

USE salt;

CREATE TABLE jids (

jid varchar(255) NOT NULL,

load mediumtext NOT NULL,

UNIQUE KEY jid (jid)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

如下:

mysql> use salt;

Database changed

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.03 sec)

mysql>

在USE salt下创建salt_returns表salt_events表

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.02 sec)

创建salt_events

mysql> CREATE TABLE `salt_events` (

-> `id` BIGINT NOT NULL AUTO_INCREMENT,

-> `tag` varchar(255) NOT NULL,

-> `data` varchar(1024) NOT NULL,

-> `alter_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,

-> PRIMARY KEY (`id`),

-> KEY `tag` (`tag`)

-> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Query OK, 0 rows affected (0.03 sec)

mysql> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.00 sec)

授权

mysql> grant all on slat.* to salt@'%' identified by 'salt';

Query OK, 0 rows affected (0.00 sec)

测试,这里没有授权localhost,使用-h主机ip登录测试,查看

[root@master ~]# mysql -u salt -p -h 10.0.0.7

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 7

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)

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> show tables;

+----------------+

| Tables_in_salt |

+----------------+

| jids |

| salt_events |

| salt_returns |

+----------------+

3 rows in set (0.00 sec)

minion端:

yum -y install MySQL-python

修改minion配置文件

[root@master ~]# vim /etc/salt/minion

mysql.host: '10.0.0.7'

mysql.user: 'salt'

mysql.pass: 'salt'

mysql.db: 'salt'

mysql.port: 3306

[root@master ~]# /etc/init.d/salt-minion restart

测试:

在master执行:

salt '*' test.ping --return mysql

查看数据库是否写入值

如下所示:

mysql> select * from salt_returns\G

*************************** 1. row ***************************

fun: test.ping

jid: 20151212003833932291

return: true

id: minion-node11.10.0.0.11.com

success: 1

full_ret: {"fun_args": [], "jid": "20151212003833932291", "return": true, "retcode": 0, "success": true, "fun": "test.ping", "id": "minion-node11.10.0.0.11.com"}

alter_time: 2015-12-12 00:38:34

*************************** 2. row ***************************

fun: test.ping

jid: 20151212004045681725

return: true

id: minion-node20.10.0.0.20.com

success: 1

full_ret: {"fun_args": [], "jid": "20151212004045681725", "return": true, "retcode": 0, "success": true, "fun": "test.ping", "id": "minion-node20.10.0.0.20.com"}

alter_time: 2015-12-12 00:40:45

*************************** 3. row ***************************

fun: test.ping

jid: 20151212004045681725

return: true

id: minios.10.0.0.8.com

5c1967c5325842cec010c6abd3e07965.gif

除非另有说明,否则本站上的内容根据以下许可进行许可: CC署名-非商业性使用-相同方式共享4.0国际许可协议4.0进行许可

本文作者:www.linuxea.com for Mark

文章链接:http://www.linuxea.com/953.html (转载请注明本文出处和本章链接)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值