学习编程 2017-12-10
1,默认情况下,发送给minion的命令执行结果将返回给salt-master。Saltstack Returnner的接口允许将结果发送给任意系统。
GitHub:https://github.com/saltstack/salt/tree/develop/salt/returners
官网:https://docs.saltstack.com/en/latest/ref/returners/
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(单边模式)
[root@saltmaster ~]# yum install –y mysql
[root@saltmaster tmp]# service mysql start Starting MySQL........ SUCCESS!
[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;
[root@dns02 ~]# vi /etc/salt/minion mysql.host: '10.80.0.162' mysql.user: 'salt' mysql.pass: 'salt' mysql.db: 'salt' mysql.port: 3306
[root@saltmaster ~]# salt '*' service.restart salt-minion dns01: True dns02: True
[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!
[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
使用Log4j的SystemLogAppender可以实现远程的日志输出,为集中式的日志管理提供便利。/etc/init.d/syslog start3. 在写日志的客户机上,修改log4j配置文件: