saltstack 返回mysql_saltstack(返回值存储到Mysql)

saltstack将数据返回到mysql服务器:

1、在master上安装mysql-server[[email protected] ~]# yum -y install mysql-server

[[email protected] ~]# service mysqld start && chkconfig mysqld on

2、创建相关的表结构[[email protected] ~]# mysql

mysql>

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;

说明:Required python modules: MySQLdb

3、mysql授权mysql>  grant all on salt.* to [email protected]%‘ identified by ‘salt‘;

4、客户端安装MySQL-python[[email protected] ~]# salt ‘*‘ cmd.run ‘yum -y install MySQL-python‘

[[email protected] ~]# mysql -u satl -p -h 10.10.10.140

Enter password:

ERROR 1045 (28000): Access denied for user [email protected] (using password: YES)

5、客户端进行连接测试[[email protected] ~]# mysql -usalt -psalt -h 10.10.10.140

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.01 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)

6、配置master及minion端相关配置[[email protected] ~]# vim /etc/salt/master

mysql.host: ‘10.10.10.140‘

mysql.user: ‘salt‘

mysql.pass: ‘salt‘

mysql.db: ‘salt‘

mysql.port: 3306

[[email protected] ~]# /etc/init.d/salt-master restart

Stopping salt-master daemon:                               [确定]

Starting salt-master daemon:                               [确定]

[[email protected] ~]# vim /etc/salt/minion

mysql.host: ‘10.10.10.140‘

mysql.user: ‘salt‘

mysql.pass: ‘salt‘

mysql.db: ‘salt‘

mysql.port: 3306

[[email protected] ~]# /etc/init.d/salt-minion restart

Stopping salt-minion daemon:                               [确定]

Starting salt-minion daemon:                               [确定]

7、测试返回值到mysql的情况[[email protected] ~]# salt ‘*‘ cmd.run ‘df‘ --return mysql

node02.saltstack.com:

Filesystem     1K-blocks    Used Available Use% Mounted on

/dev/sda5       14114736 8728708   4662368  66% /

tmpfs             953964      12    953952   1% /dev/shm

/dev/sda1         194241   42160    141841  23% /boot

/dev/sda3        1998672   18204   1875612   1% /tmp

node01.saltstack.com:

Filesystem     1K-blocks    Used Available Use% Mounted on

/dev/sda5       14114736 8729432   4661644  66% /

tmpfs             953964      84    953880   1% /dev/shm

/dev/sda1         194241   42160    141841  23% /boot

/dev/sda3        1998672   18224   1875592   1% /tmp

测试结果:mysql> select * from salt_returns\G;

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

fun: cmd.run

jid: 20170220120522696829

return: "Filesystem     1K-blocks    Used Available Use% Mounted on\n/dev/sda5       14114736 8729432   4661644  66% /\ntmpfs             953964      84    953880   1% /dev/shm\n/dev/sda1         194241   42160    141841  23% /boot\n/dev/sda3        1998672   18224   1875592   1% /tmp"

id: node01.saltstack.com

success: 1

full_ret: {"fun_args": ["df"], "jid": "20170220120522696829", "return": "Filesystem     1K-blocks    Used Available Use% Mounted on\n/dev/sda5       14114736 8729432   4661644  66% /\ntmpfs             953964      84    953880   1% /dev/shm\n/dev/sda1         194241   42160    141841  23% /boot\n/dev/sda3        1998672   18224   1875592   1% /tmp", "retcode": 0, "success": true, "fun": "cmd.run", "id": "node01.saltstack.com"}

alter_time: 2017-02-20 12:05:24

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

fun: cmd.run

jid: 20170220120528485243

return: "Filesystem     1K-blocks    Used Available Use% Mounted on\n/dev/sda5       14114736 8729432   4661644  66% /\ntmpfs             953964      84    953880   1% /dev/shm\n/dev/sda1         194241   42160    141841  23% /boot\n/dev/sda3        1998672   18224   1875592   1% /tmp"

id: node01.saltstack.com

success: 1

full_ret: {"fun_args": ["df"], "jid": "20170220120528485243", "return": "Filesystem     1K-blocks    Used Available Use% Mounted on\n/dev/sda5       14114736 8729432   4661644  66% /\ntmpfs             953964      84    953880   1% /dev/shm\n/dev/sda1         194241   42160    141841  23% /boot\n/dev/sda3        1998672   18224   1875592   1% /tmp", "retcode": 0, "success": true, "fun": "cmd.run", "id": "node01.saltstack.com"}

alter_time: 2017-02-20 12:05:28

2 rows in set (0.00 sec)

ERROR:

No query specified

8、如果每次执行不加--return=mysql,由master端将返回的数据写入数据库master_job_cache: mysql

注意:如果配置了/etc/salt/roster的话,

要注释掉master_job_cache: mysql,否则会有冲突

#master_job_cache: mysql

如果之前已经配置过salt-ssh的话,在设置master_job_cache: mysql的话,就会出现报错信息:[[email protected] salt]# salt ‘node01.saltstack.com‘ cmd.run ‘ls -ld /‘

Failed to allocate a jid. The requested returner ‘mysql‘ could not be loaded.

我暂时没找到解决办法

其它报错信息:[[email protected] salt]# salt ‘node01.saltstack.com‘ cmd.run ‘ls -ld /‘

Salt request timed out. The master is not responding. If this error persists after verifying the master is up, worker_threads may need to be increased.

可以尝试在/etc/salt/master中修改worker_threads的值

#worker_threads: 5

worker_threads: 20

如果仍旧报错,可能是网络的问题,重新执行几次,可能就恢复了

参考资料:http://docs.saltstack.cn/ref/returners/all/salt.returners.mysql.html#module-salt.returners.mysql

原文:http://molewan.blog.51cto.com/287340/1899474

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值