SaltStack实战之远程执行-Returners
来源:互联网 发布:mac aecc2017切换中文 编辑:程序博客网 时间:2024/05/23 12:17
SaltStack实战之远程执行-Returners
@(学习)[SaltStack]
- SaltStack实战之远程执行-Returners
- Returners列表
- 介绍mysql returner的用法
- 1 安装pip和MySQLdb
- 2 配置mysql数据库
- 2 配置salt-master
- 3 测试
1. Returners列表
https://docs.saltstack.com/en/latest/ref/returners/all/index.html
2. 介绍mysql returner的用法
因mysql returner使用需要python MySQLdb模块,所以需要先安装MySQLdb模块。
2.1 安装pip和MySQLdb
在下列地址下载安装包。
https://pypi.python.org/pypi/setuptools
https://pypi.python.org/pypi/pip/
[root@salt-master111 tmp]# yum -y install python-devel mysql-devel[root@salt-master111 tmp]# unzip setuptools-36.0.1.zip[root@salt-master111 tmp]# cd setuptools-36.0.1[root@salt-master111 tmp]# python setup.py install[root@salt-master111 tmp]# cd ../[root@salt-master111 tmp]# tar -zxvf pip-9.0.1.tar.gz [root@salt-master111 tmp]# cd pip-9.0.1[root@salt-master111 tmp]# python setup.py install[root@salt-master111 tmp]# pip install mysql[root@salt-master111 tmp]# pythonPython 2.7.5 (default, Nov 6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import MySQLdb>>>
2.2 配置mysql数据库
使用官方的数据表结构,并给minion服务器相关权限。
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;grant all on salt.* to salt@"10.1.0.%" identified by "saltpass";
2.2 配置salt-master
/etc/salt/master
return: mysqlmysql.host: 'salt-host'mysql.user: 'salt'mysql.pass: 'saltpass'mysql.db: 'salt'
重启master和minion服务
systemctl restart salt-mastersystemctl restart salt-minion
2.3 测试
master端执行命令。
[root@salt-master111 ~]# salt 'salt-master111' test.ping --return mysqlsalt-master111: True[root@salt-master111 ~]#
在数据库中查看,salt_returns是否有数据进来。
mysql> select * from salt_returns;+-----------+----------------------+--------+----------------+---------+--------------------------------------------------------------------------------------------------------------------------------------------+---------------------+| fun | jid | return | id | success | full_ret | alter_time |+-----------+----------------------+--------+----------------+---------+--------------------------------------------------------------------------------------------------------------------------------------------+---------------------+| test.ping | 20170609172835506510 | true | salt-master111 | 1 | {"fun_args": [], "jid": "20170609172835506510", "return": true, "retcode": 0, "success": true, "fun": "test.ping", "id": "salt-master111"} | 2017-06-09 17:28:35 || test.ping | 20170609172841714924 | true | salt-master111 | 1 | {"fun_args": [], "jid": "20170609172841714924", "return": true, "retcode": 0, "success": true, "fun": "test.ping", "id": "salt-master111"} | 2017-06-09 17:28:41 || test.ping | 20170609173636297217 | true | salt-master111 | 1 | {"fun_args": [], "jid": "20170609173636297217", "return": true, "retcode": 0, "success": true, "fun": "test.ping", "id": "salt-master111"} | 2017-06-09 17:36:36 || test.ping | 20170609173653113715 | true | salt-master111 | 1 | {"fun_args": [], "jid": "20170609173653113715", "return": true, "retcode": 0, "success": true, "fun": "test.ping", "id": "salt-master111"} | 2017-06-09 17:36:53 |+-----------+----------------------+--------+----------------+---------+--------------------------------------------------------------------------------------------------------------------------------------------+---------------------+4 rows in set (0.00 sec)
阅读全文
0 0
- SaltStack实战之远程执行-Returners
- SaltStack实战之远程执行-Targeting
- SaltStack实战之远程执行-Modules
- saltstack 远程执行脚本
- SaltStack实战之SaltStack快速入门
- saltstack实战之基础配置
- SaltStack实战之数据系统-Grains
- SaltStack实战之数据系统-Pillar
- SaltStack实战之配置管理-YAML编写技巧
- SaltStack实战之配置管理-LAMP自动化部署
- SaltStack实战之配置管理-状态间关系
- SaltStack实战之配置管理-Jinja2模板
- SaltStack实战之数据系统 Grains VS Pillar
- SaltStack实战之manage、salt-ssh和salt jobs
- saltstack 远程命令
- saltstack实战--优化
- SaltStack实战应用
- struts2之远程执行
- ios开发 label分段设置字体颜色
- Understanding and Diagnosing Visual Tracking System
- android studio3.0 kotlin配置Anko
- 从尾到头打印链表
- 分形三角形
- SaltStack实战之远程执行-Returners
- Leetcode-Merge Two Sorted Lists
- 通过adb与python结合创建的设备驱动脚本deviceDriver.py
- [转]有return的情况下try catch finally的执行顺序(最有说服力的总结)
- 重建二叉树
- 使用多张图片做帧动画的性能优化
- Mac构建Protobuf
- Leetcode 152 Maximum Product Subarray
- 贪心+并查集