环境

node1  192.168.56.11   角色 salt-master

node2  192.168.56.12   角色  salt-minon

实现内容

使用salt远程安装zabbix-agent

步骤

环境是基于前几篇博客基础上Master和minion已经配置完成

一,创建zabbix项目文件夹,用于存放状态文件
[root@linux-node1 base]# mkdir /srv/salt/base/zabbix -p
[root@linux-node1 base]# mkdir /srv/salt/base/init/files -p #用于存放系统相关初始化的信息
二,配置salt的epel源文件
[root@linux-node1 files]# pwd
/srv/salt/base/init/files
[root@linux-node1 files]# wget http://mirrors.aliyun.com/repo/epel-7.repo
---- ::-- http://mirrors.aliyun.com/repo/epel-7.repo
......
三,拷贝zabbix配置文件作为salt的zabbix源文件
[root@linux-node1 zabbix]# yum list |grep zabbix22-agent
zabbix22-agent.x86_64 2.2.-.el7 epel [root@linux-node1 zabbix]# ll /etc/zabbix/zabbix_agentd.conf
lrwxrwxrwx root root Oct : /etc/zabbix/zabbix_agent.conf -> /etc/zabbix_agent.conf [root@linux-node1 zabbix]# mkdir /srv/salt/base/zabbix/files
[root@linux-node1 zabbix]# cp /etc/zabbix_agentd.conf /srv/salt/base/zabbix/files
四,添加jiaja模板变量到salt的zabbix源文件
[root@linux-node1 files]# grep ^[a-Z] zabbix_agentd.conf
PidFile=/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=
Server={{ ZABBIX_SERVER }}
Hostname={{ AGENT_HOSTNAME }}
Include=/etc/zabbix_agentd.conf.d/
五,配置epel状态文件管理
[root@linux-node1 init]# pwd
/srv/salt/base/init
[root@linux-node1 init]# vim yum-repo.sls
[root@linux-node1 init]# cat yum-repo.sls
/etc/yum.repos.d/epel-.repo:
file.managed:
- source: salt://init/files/epel-7.repo
- user: root
- group: root
- mode:
六,写zabbix-agent的状态文件
[root@linux-node1 zabbix]# pwd
/srv/salt/base/zabbix
[root@linux-node1 zabbix]# cat zabbix-agent.sls
include: #支持include功能
- init.yum-repo zabbix-agent:
pkg.installed:
- name: zabbix22-agent
- require:
- file: /etc/yum.repos.d/epel-.repo
file.managed:
- name: /etc/zabbix_agentd.conf
- source: salt://zabbix/files/zabbix_agentd.conf
- user: root
- group: root
- mode:
- template: jinja
- defaults:
ZABBIX_SERVER: 192.168.56.12
AGENT_HOSTNAME: {{ grains['fqdn'] }}
- require:
- pkg: zabbix-agent
service.running:
- name: zabbix-agent
- enable: True
- watch:
- file: zabbix-agent
- pkg: zabbix-agent zabbix_agentd.conf.d:
file.directory:
- name: /etc/zabbix_agentd.conf.d
- watch_in:
- service: zabbix-agent
- require:
- pkg: zabbix-agent
- file: zabbix-agent
七,测试
[root@linux-node1 files]# salt 'linux-node2*' state.sls zabbix.zabbix-agent test=True
linux-node2.example.com:
----------
ID: /etc/yum.repos.d/epel-.repo
Function: file.managed
Result: None
Comment: The file /etc/yum.repos.d/epel-.repo is set to be changed
Started: ::12.939665
Duration: 10.114 ms
Changes:
----------
newfile:
/etc/yum.repos.d/epel-.repo
----------
ID: zabbix-agent
Function: pkg.installed
Name: zabbix22-agent
Result: None
Comment: The following packages are set to be installed/updated: zabbix22-agent
Started: ::13.254634
Duration: 2867.494 ms
Changes:
----------
ID: zabbix-agent
Function: file.managed
Name: /etc/zabbix_agentd.conf
Result: None
Comment: The file /etc/zabbix_agentd.conf is set to be changed
Started: ::16.122685
Duration: 15.872 ms
Changes:
----------
newfile:
/etc/zabbix_agentd.conf
----------
ID: zabbix_agentd.conf.d
Function: file.directory
Name: /etc/zabbix_agentd.conf.d
Result: None
Comment: The following files will be changed:
/etc/zabbix_agentd.conf.d: directory - new
Started: ::16.139640
Duration: 0.401 ms
Changes:
----------
ID: zabbix-agent
Function: service.running
Result: None
Comment: Service is set to be started
Started: ::16.206765
Duration: 79.412 ms
Changes: Summary
------------
Succeeded: (unchanged=, changed=)
Failed:
------------
Total states run:

salt 'linux-node2*' state.sls zabbix.zabbix-agent test=True

八,执行
[root@linux-node1 init]# salt 'linux-node2*' state.sls zabbix.zabbix-agent 

linux-node2.example.com:
----------
ID: /etc/yum.repos.d/epel-.repo
Function: file.managed
Result: True
Comment: File /etc/yum.repos.d/epel-.repo updated
Started: ::54.907929
Duration: 14.348 ms
Changes:
----------
diff:
New file
mode: ----------
ID: zabbix-agent
Function: pkg.installed
Name: zabbix22-agent
Result: True
Comment: The following packages were installed/updated: zabbix22-agent
Started: ::55.228682
Duration: 20540.866 ms
Changes:
----------
zabbix22:
----------
new:
2.2.-.el7
old:
zabbix22-agent:
----------
new:
2.2.-.el7
old:
----------
ID: zabbix-agent
Function: file.managed
Name: /etc/zabbix_agentd.conf
Result: True
Comment: File /etc/zabbix_agentd.conf updated
Started: ::15.771609
Duration: 34.695 ms
Changes:
----------
diff:
---
+++
@@ -, +, @@
# Default:
# Server= -Server=127.0.0.1
+Server=192.168.56.11 ### Option: ListenPort
# Agent will listen on this port for connections from the server.
@@ -, +, @@
# Default:
# Hostname= -Hostname=Zabbix server
+Hostname=linux-node2.example.com ### Option: HostnameItem
# Item used for generating Hostname if it is undefined. Ignored if Hostname is defined.
@@ -, +, @@
# Include= # Include=/etc/zabbix_agentd.userparams.conf
-# Include=/etc/zabbix_agentd.conf.d/
+Include=/etc/zabbix_agentd.conf.d/ ####### USER-DEFINED MONITORED PARAMETERS ####### ----------
ID: zabbix_agentd.conf.d
Function: file.directory
Name: /etc/zabbix_agentd.conf.d
Result: True
Comment: Directory /etc/zabbix_agentd.conf.d updated
Started: ::15.824436
Duration: 1.088 ms
Changes:
----------
/etc/zabbix_agentd.conf.d:
New Dir
----------
ID: zabbix-agent
Function: service.running
Result: True
Comment: Service zabbix-agent has been enabled, and is running
Started: ::15.825810
Duration: 443.184 ms
Changes:
----------
zabbix-agent:
True Summary
------------
Succeeded: (changed=)
Failed:
------------
Total states run:

salt 'linux-node2*' state.sls zabbix.zabbix-agent

九,登陆到node2上面,zabbix 已正常启动
[root@linux-node2 ~]# ps aux |grep zabbix
zabbix 0.0 0.0 ? S : : /usr/sbin/zabbix_agentd
zabbix 0.0 0.0 ? S : : /usr/sbin/zabbix_agentd: collector [idle sec]
zabbix 0.0 0.0 ? S : : /usr/sbin/zabbix_agentd: listener # [waiting for connection]
zabbix 0.0 0.0 ? S : : /usr/sbin/zabbix_agentd: listener # [waiting for connection]
zabbix 0.0 0.0 ? S : : /usr/sbin/zabbix_agentd: listener # [waiting for connection]
zabbix 0.0 0.0 ? S : : /usr/sbin/zabbix_agentd: active checks # [idle sec]
root 0.0 0.0 pts/ S+ : : grep --color=auto zabbix

总结

1.Jinja模板变量名不支持中横线 -

2.状态文件可以根据项目或服务进行分类管理

3.状态文件支持include功能,支持正则匹配minion id

4.在编写状态文件之前需要先查清楚相关的软件包名称及配置文件名称

5.要习惯先用test=True进行测试,避免不必要的故障

6.基础的东西(jdk,web应用等) 通用的安装全放在一个目录,然后使用include功能

7.做好状态模块之间的依赖关系,避免不必要的状态执行


附 赵班长的 GitHub saltbook-code网址

https://github.com/unixhot/saltbook-code/tree/master

SaltStack安装zabbix-agent-第九篇的更多相关文章

  1. window上安装zabbix agent使用案例

    下载对应的zabbix windows版本 因为zabbix server使用的版本为3.2.0版本 所以下载window 3.2的版本 https://www.zabbix.com/download ...

  2. centos6.4安装 zabbix agent

    1.防火墙设置 允许zabbix-agent的10050端口通过  iptables -A INPUT -p tcp --dport 10050 -j ACCEPT  2.安装zabbix agent ...

  3. CentOS安装Zabbix Agent

    rpm -i http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm安装存储库 yum ...

  4. 用yum rpm 快速安装zabbix agent

    用yum 快速安装zabbix agent. wget http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-agent-3.4.2-1.el7 ...

  5. Zabbix 4.0.2试用(七):在Linux主机中安装zabbix agent并添加该主机(yum源安装)

    Zabbix 4.0.2试用(七):在Linux主机中安装zabbix agent并添加主机(yum源安装) 2018年12月20日, 上午6:42 之前介绍的是下载源安装包,编译安装的方式来安装ag ...

  6. Windows下安装Zabbix agent

    下载Windows版本的Zabbix agent安装包:https://www.zabbix.com/cn/download_agents#tab:40LTS 有两种安装方式: (1)需要手动安装,安 ...

  7. 快速安装zabbix agent并部署监控

    1.准备yum源: epel源:yum install -y zabbix22-agent 2.上传脚本: 上传脚本事先写好的监控脚本到/script/下面 3.修改配置文件:Server=10.10 ...

  8. zabbix agent安装与配置篇

     Zabbix监控windows部署安装 Zabbix agent 在windows上安装部署 (1)手工安装zabbix agent客户端 1.  下载与解压 地址: http://www.zabb ...

  9. zabbix agent安装(三)

    转载于https://mp.weixin.qq.com/s/33ab-JLoRfMkeI4aZDciJQ 前一篇文章介绍了zabbix server安装,这篇文章主要讲解zabbix agent安装以 ...

  10. docker 一键安装zabbix server、zabbix agent

    基本原理.须知:1.zabbix 分为zabbix server和zabbix agent,其中zabbix server需要web环境,并且其数据存储在独立的数据库中:2.docker是一种容器服务 ...

随机推荐

  1. http协议----->http请求方式,post,get

    4.http请求方式有七种(http请求是想web资源请求数据) Post get head options delete trace put 常用:GET POST POST例如form表单提交,G ...

  2. 1.引入jQuery

    http://libs.baidu.com/jquery/2.1.4/jquery.js

  3. Netty in action—Netty中的ByteBuf

    Netty in action—Netty中的ByteBuf - 日积月累 - CSDN博客 https://blog.csdn.net/yjw123456/article/details/77843 ...

  4. 后台curl网络请求

    <?php //前端进行网络请求  ajax //后台进行网络请求用到两种方式  curl   socket //进行网络请求的步骤 //1.初始化一个curl //2.对curl进行配置 // ...

  5. WSGI的理解 perfect

    https://blog.csdn.net/hzrandd/article/details/10099871 https://blog.csdn.net/cloudxli/article/detail ...

  6. 剑指Offer——数值的整数次方

    题目描述: 给定一个double类型的浮点数base和int类型的整数exponent.求base的exponent次方. 分析: 快速幂,简单解释下, 当e的二进制为1001011, b^e=b^( ...

  7. ntpdate同步更新时间

    Linux服务器运行久时,系统时间就会存在一定的误差,一般情况下可以使用date命令进行时间设置,但在做数据库集群分片等操作时对多台机器的时间差是有要求的,此时就需要使用ntpdate进行时间同步 1 ...

  8. Loki之ThreadPool

    Loki中的ThreadPool目的主要是对创建出来的线程进行复用. ThreadPool在Test而非Loki目录下,因此并非是标准Loki的组件之一,不过我们可以对其修改定制, 下面是对其源码的大 ...

  9. zabbix详解(一)

    zabbix简介 zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案. zabbix能监视各种网络参数,保证服务器系统的安全运营:并提供柔软的通知机制以让系统管 ...

  10. 【开发者笔记】冒泡排序过程呈现之java内置GUI表示

    自己玩玩写写,排序的过程多么有趣,特别是把看着电脑吧一堆乱七八糟的数据排成有序组合的时候,看起来贼舒服,特别是强迫症患者.好了,话不多说上代码,也算是自己记录一下吧,没有什么技术含量但个人感觉比较有趣 ...