SaltStack實戰(zhàn)之遠程執(zhí)行-Returners

SaltStack實戰(zhàn)之遠程執(zhí)行-Returners

創(chuàng)新互聯(lián)專注于營口企業(yè)網(wǎng)站建設(shè),自適應(yīng)網(wǎng)站建設(shè),商城系統(tǒng)網(wǎng)站開發(fā)。營口網(wǎng)站建設(shè)公司,為營口等地區(qū)提供建站服務(wù)。全流程按需規(guī)劃網(wǎng)站,專業(yè)設(shè)計,全程項目跟蹤,創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)

學(xué)習(xí) SaltStack

  • SaltStack實戰(zhàn)之遠程執(zhí)行-Returners

    • 1. Returners列表

    • 2. 介紹MySQL returner的用法

    • 2.1 安裝pip和MySQLdb

    • 2.2 配置mysql數(shù)據(jù)庫

    • 2.2 配置salt-master

    • 2.3 測試

1. Returners列表

https://docs.saltstack.com/en/latest/ref/returners/all/index.html

returnersdescription
carbon_returnTake data from salt and “return” it into a carbon receiver
cassandra_cql_returnReturn data to a cassandra server
cassandra_returnReturn data to a Cassandra ColumnFamily
couchbase_returnSimple returner for Couchbase.
couchdb_returnS imple returner for CouchDB.
django_returnA returner that will infor a Django system that returns are available using Django’s signal system.
elasticsearch_returnReturn data to an elasticsearch server for indexing.
etcd_returnReturn data to an etcd server or cluster
hipchat_returnReturn salt data via hipchat.
influxdb_returnReturn data to an influxdb server.
kafka_returnReturn data to a Kafka topic
localThe local returner is used to test the returner interface, it just prints the
local_cacheReturn data to local job cache
memcache_returnReturn data to a memcache server
mongo_future_returnReturn data to a MongoDB server
mongo_returnReturn data to a mongodb server
multi_returnerRead/Write multiple returners
mysqlReturn data to a mysql server
nagios_returnReturn salt data to Nagios
odbcReturn data to an ODBC compliant server.
pgjsonbReturn data to a PostgreSQL server with json data stored in Pg’s jsonb data type
postgresReturn data to a postgresql server
postgres_local_cacheUse a postgresql server for the master job cache.
pushover_returnerReturn salt data via pushover (http://www.pushover.net)
rawfile_jsonTake data from salt and “return” it into a raw file containing the json, with one line per event.
redis_returnReturn data to a redis server
sentry_returnSalt returner that reports execution results back to sentry.
slack_returnerReturn salt data via slack
sms_returnReturn data by SMS.
smtp_returnReturn salt data via email
splunkSend json response data to Splunk via the HTTP Event Collector
sqlite3_returnInsert minion return data into a sqlite3 database
syslog_returnReturn data to the host operating system’s syslog facility
xmpp_returnReturn salt data via xmpp
zabbix_returnReturn salt data to Zabbix

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]# python
Python 2.7.5 (default, Nov  6 2016, 00:28:07)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>>

2.2 配置mysql數(shù)據(jù)庫

使用官方的數(shù)據(jù)表結(jié)構(gòu),并給minion服務(wù)器相關(guān)權(quán)限。

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: mysql
mysql.host: 'salt-host'
mysql.user: 'salt'
mysql.pass: 'saltpass'
mysql.db: 'salt'

重啟master和minion服務(wù)

systemctl restart salt-master
systemctl restart salt-minion

2.3 測試

master端執(zhí)行命令。

[root@salt-master111 ~]# salt 'salt-master111' test.ping --return mysql
salt-master111:
   True
[root@salt-master111 ~]#

在數(shù)據(jù)庫中查看,salt_returns是否有數(shù)據(jù)進來。

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 se

新聞標(biāo)題:SaltStack實戰(zhàn)之遠程執(zhí)行-Returners
網(wǎng)站路徑:http://muchs.cn/article20/ijcico.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站排名網(wǎng)站制作、營銷型網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計公司微信公眾號、響應(yīng)式網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站優(yōu)化排名