saltstack学习-2 :returnner-将结果发送给syslog和mysql(单边模式)
一,returnner介绍
1,默认情况下,发送给minion的命令执行结果将返回给salt-master。Saltstack Returnner的接口允许将结果发送给任意系统。
GitHub:https://github.com/saltstack/salt/tree/develop/salt/returners
官网:https://docs.saltstack.com/en/latest/ref/returners/
二,returnner模块列表
三,案例
1,returnner返回到syslog
salt-master执行命令:
[root@saltmaster ~]# salt '*' test.ping --return syslog dns02: True dns01: True
查看salt-minion端syslog日志
[root@dns02 ~]# tail -f /var/log/messages Dec 9 22:22:31 dns02 python2.6: {"fun_args": [], "jid": "", "return": true, "retcode": 0, "success": true, "fun": "test.ping", "id": "dns02"}
2,returnner返回给mysql(单边模式)
- 安装mysql(可以在master也可以在其它服务器)
[root@saltmaster ~]# yum install –y mysql
- 启动mysql服务
[root@saltmaster tmp]# service mysql start Starting MySQL........ SUCCESS!
- 设置root密码
[root@saltmaster tmp]# mysqladmin -u root password '123456'
- 创建数据库,并授权
--创建数据库 CREATE DATABASE `salt`DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci; USE `salt`; 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; 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,KEY `id` (`id`),KEY `jid` (`jid`),KEY `fun` (`fun`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; --授权 GRANT ALL PRIVILEGES ON salt.* to 'salt'@'%' identified by 'salt'; flush privileges;
- 修改所有minion配置文件,在配置文件结尾添加:
[root@dns02 ~]# vi /etc/salt/minion mysql.host: '10.80.0.162' mysql.user: 'salt' mysql.pass: 'salt' mysql.db: 'salt' mysql.port: 3306
- 重启所有minion服务
[root@saltmaster ~]# salt '*' service.restart salt-minion dns01: True dns02: True
- 所有minion安装MySQL-python模块
[root@saltmaster tmp]# salt '*' cmd.run 'yum install -y MySQL-python' dns02: Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Install Process Loading mirror speeds from cached hostfile * epel: mirrors.tongji.edu.cn Resolving Dependencies --> Running transaction check ---> Package MySQL-python.x86_64 0:1.2.3-0.3.c1.1.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: MySQL-python x86_64 1.2.3-0.3.c1.1.el6 base 86 k Transaction Summary ================================================================================ Install 1 Package(s) Total download size: 86 k Installed size: 246 k Downloading Packages: Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : MySQL-python-1.2.3-0.3.c1.1.el6.x86_64 1/1 Verifying : MySQL-python-1.2.3-0.3.c1.1.el6.x86_64 1/1 Installed: MySQL-python.x86_64 0:1.2.3-0.3.c1.1.el6 Complete! dns01: Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Install Process Loading mirror speeds from cached hostfile * epel: mirrors.tongji.edu.cn Resolving Dependencies --> Running transaction check ---> Package MySQL-python.x86_64 0:1.2.3-0.3.c1.1.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: MySQL-python x86_64 1.2.3-0.3.c1.1.el6 base 86 k Transaction Summary ================================================================================ Install 1 Package(s) Total download size: 86 k Installed size: 246 k Downloading Packages: Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : MySQL-python-1.2.3-0.3.c1.1.el6.x86_64 1/1 Verifying : MySQL-python-1.2.3-0.3.c1.1.el6.x86_64 1/1 Installed: MySQL-python.x86_64 0:1.2.3-0.3.c1.1.el6 Complete!
- 测试写入mysql
[root@saltmaster tmp]# salt '*' cmd.run 'hostname' --return mysql dns02: dns02 dns01: dns01
- 结果
mysql> select * from salt_returns; +---------+----------------------+---------+-------+---------+----------------------------------------------------------------------------------------------------------------------------------------------+ | fun | jid | return | id | success | full_ret | +---------+----------------------+---------+-------+---------+----------------------------------------------------------------------------------------------------------------------------------------------+ | cmd.run | 20171210074613759042 | "dns02" | dns02 | 1 | {"fun_args": ["hostname"], "jid": "20171210074613759042", "return": "dns02", "retcode": 0, "success": true, "fun": "cmd.run", "id": "dns02"} | | cmd.run | 20171210074613759042 | "dns01" | dns01 | 1 | {"fun_args": ["hostname"], "jid": "20171210074613759042", "return": "dns01", "retcode": 0, "success": true, "fun": "cmd.run", "id": "dns01"} | +---------+----------------------+---------+-------+---------+----------------------------------------------------------------------------------------------------------------------------------------------+ 2 rows in set (0.00 sec)
snailshadow 标签: returnner,saltstack
相关推荐
highwaymanhw 2020-09-06
CSDNMrWang 2020-04-26
一路到黑 2020-03-26
jakefei 2020-02-15
quguang 2020-01-04
amorfait 2007-06-18
sdfshfh 2009-06-07
Will0 2012-10-11
VictoryKingLIU 2012-09-29
hai0 2011-10-27
MrLiar 2011-10-19
康慧欣 2014-11-27
浪里xiao白龙 2019-06-29
xyc 2012-07-26
使用Log4j的SystemLogAppender可以实现远程的日志输出,为集中式的日志管理提供便利。/etc/init.d/syslog start3. 在写日志的客户机上,修改log4j配置文件:
hfty0 2011-10-17
农码经神 2010-12-17