Company's existing monitoring using Zabbix,saltstack client server installed, the client does not need each machine to install, of course, modify the Zabbix configuration file, directly with salt to complete, today tested salt source installation zabbix_agent, the effect is OK;
The ritual, Top.sls.
[email protected] salt]# cat Top.sls
Base
‘*‘:
-Zabbix
#目录树
[Email protected] salt]# tree zabbix/
zabbix/
├──conf.sls
├──files
│?? ├──conf.sh
│?? ├──zabbix-2.4.7.tar.gz
│?? ├──zabbix_agentd
│?? └──zabbix_agentd.conf
├──init.sls
└──install.sls
After a while of salt learning, writing SLS files to build such ideas:
1, according to the SLS file category divided into: Reference files, installation files, configuration files, preferably separated into these three parts, error easier to troubleshoot:
2, the configuration before you need to consider several functions to use, it is best to have a manual installation of the configuration document to configure, and then start the SLS writing:
The features you need to use are:
Using the Status module: file, cmd, service, user, group, etc.
Use relationship between states: require, unless, template, etc.
Mutual references between SLS files: include
[email protected] zabbix]# cat Init.sls
Include
-Zabbix.conf
-Zabbix.install
[email protected] zabbix]# cat Install.sls
Zabbix_source:
File.managed:
-Name:/usr/local/src/zabbix-2.4.7.tar.gz
-Source:salt://zabbix/files/zabbix-2.4.7.tar.gz
-User:root
-Group:root
-mode:644
Cmd.run:
-CWD:/USR/LOCAL/SRC
-Name:tar XF zabbix-2.4.7.tar.gz && chown-r root.root zabbix-2.4.7
-Require:
-File:zabbix_source
Zabbix_user:
Group.present:
-Name:zabbix
-gid:201
User.present:
-Name:zabbix
-Fullname:zabbix
-uid:201
-gid:201
-Createhome:false
-Shell:/sbin/nologin
-Unless:id Zabbix
Zabbix_pkginstall:
Pkg.installed:
-pkgs:
-GCC
-Gcc-c++
-Autoconf
-Automake
-Mod_ssl
-Net-snmp-devel
-Libcurl-devel
-Zlib
-Zlib-devel
Zabbix_commpile:
Cmd.run:
-name:cd/usr/local/src/zabbix-2.4.7 &&/configure--prefix=/usr/local/zabbix--enable-agent && make && make Install
-Require:
-File:zabbix_source
-User:zabbix_user
[email protected] zabbix]# cat Conf.sls
Include
-Zabbix.install
/usr/local/zabbix/etc/zabbix_agentd.conf:
File.managed:
-Name:/usr/local/zabbix/etc/zabbix_agentd.conf
-User:root
-mode:644
-Source:salt://zabbix/files/zabbix_agentd.conf
-Template:jinja #引用jinja模版
-Require:
-Pkg:zabbix_pkginstall
Salt://zabbix/files/conf.sh:
Cmd.script:
-ENV:
-BATCH: ' Yes '
-Unless:test-d/USR/LOCAL/ETC/ZABBIX_AGENTD.CONF.D
-Require:
-Cmd:zabbix_commpile
ZABBIX_AGENTD:
File.managed:
-Name:/etc/init.d/zabbix_agentd
-User:root
-mode:755
-Source:salt://zabbix/files/zabbix_agentd
Cmd.run:
-Name:
-/sbin/chkconfig--add Zabbix_agentd
-Unless:/sbin/chkconfig--list zabbix_agentd
Service.running:
-Enable:true
# #-Reload:true #此处不需要reload
-Watch:
-File:/usr/local/zabbix/etc/zabbix_agentd.conf
Because the ZABBIX_AGENTD Client Profile/usr/local/zabbix/etc/zabbix_agentd.conf, the configuration options hostname= in each client are different, This allows you to configure the value of the grains variable or pillar custom variable value in the initialization to/usr/local/zabbix/etc/zabbix_agentd.conf, which I will only take as an example of the hostname option in the configuration file:
[Email protected] zabbix]# vim files/zabbix_agentd.conf
hostname={{grains[' host '}} so you can get the Hostname of the system,
More usage can be viewed with salt ' Minions ' grains.items, or salt ' Minions ' Pillar.items
[email protected] zabbix]# cat files/conf.sh
#!/bin/bash
#
Mkdir/usr/local/etc/zabbix_agentd.conf.d
Mkdir/var/log/zabbix && chown-r Zabbix.zabbix/var/log/zabbix
Ln-s/usr/local/zabbix/bin/*/usr/bin/
Ln-s/usr/local/zabbix/sbin/*/usr/sbin/
Zabbix_agentd and zabbix_agentd.conf can be obtained from the source installation package, and Zabbix_agentd SysV script needs to modify the ZABBIX_AGENTD installation directory.
All proper, and finally implement salt ' Minions ' state.highstate
This article from "LawLer" blog, declined reprint!
Saltstack Source Installation Zabbix_agent