saltstack执行结果结合Elasticsearch来展现

来源:互联网 发布:联想面部识别软件 编辑:程序博客网 时间:2024/06/01 13:48

默认情况下,发送给salt minion的命令执行结果将返回给salt master.

Saltstack Returner的接口允许将结果发送给任意系统

官方文档:
https://docs.saltstack.com/en/latest/ref/returners/all/salt.returners.elasticsearch_return.html#module-salt.returners.elasticsearch_return

一、在minion里修改配置文件

vim /etc/salt/minion# 编辑配置文件,添加 es服务的IP及端口elasticsearch:  hosts:    - '10.10.10.100:9200'  number_of_shards: 3  number_of_replicas: 1# 重启minion端:/etc/init.d/salt-minion restart

二、master端\minion端都需 安装elasticsearch模块

  • 1、elasticsearch模块安装
# 方式一:pip 安装pip install elasticsearch  # 方式二:源码安装git clone https://github.com/elastic/elasticsearch-py.gitcd elasticsearch-py ; python setup.py install    # 可能会报错:No module named pbr.pbr_json    pip install pbr# 方式三:下载Python包源码安装下载地址: https://pypi.python.org/pypi/pbr/#downloads
  • 2、elasticsearch模块测试
# 创建索引。没有报错信息,且es服务上能看到testindex索引salt 'myminion' elasticsearch.index_create testindex# 判断索引是否存在salt ‘myminion’ elasticsearch.index_exists testindex# 删除索引。正常的话:删除添加的测试索引salt 'myminion' elasticsearch.index_delete testindex# 获取索引数据salt myminion elasticsearch.index_get testindex

三、master端执行命令查看结果

salt 'myminion' test.ping --return elasticsearch 

这时es里会显示索引数据

这里写图片描述

  • 如果每次执行不加–elasticsearch,由master端将返回的数据写入es
1.修改master配置文件# vi /etc/salt/master在配置文件后面追加以下内容ext_job_cache: elasticsearch2.重启master# service salt-master restart3.测试

加上结果返回给其他服务时,salt命令返回会稍微慢一点点

原创粉丝点击