標籤:epel 分享圖片 images height action 寫入 charset idt word
一,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執行命令:
[[email protected] ~]# salt ‘*‘ test.ping --return syslogdns02: Truedns01: True
查看salt-minion端syslog日誌
[[email protected] ~]# tail -f /var/log/messagesDec 9 22:22:31 dns02 python2.6: {"fun_args": [], "jid": "20171209222231433150", "return": true, "retcode": 0, "success": true, "fun": "test.ping", "id": "dns02"}
2,returnner返回給mysql(單邊模式)
- 安裝mysql(可以在master也可以在其它伺服器)
[[email protected] ~]# yum install –y mysql
[[email protected] tmp]# service mysql startStarting MySQL........ SUCCESS!
[[email protected] 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;
[[email protected] ~]# vi /etc/salt/minionmysql.host: ‘10.80.0.162‘ mysql.user: ‘salt‘ mysql.pass: ‘salt‘ mysql.db: ‘salt‘ mysql.port: 3306
[[email protected] ~]# salt ‘*‘ service.restart salt-miniondns01: Truedns02: True
[[email protected] 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!
[[email protected] tmp]# salt ‘*‘ cmd.run ‘hostname‘ --return mysqldns02: dns02dns01: 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
saltstack學習-2 :returnner-將結果發送給syslog和mysql(單邊模式)