最近弄saltstack弄上瘾了,今天又弄了saltstack源码安装nrpe,安装nrpe之前需要安装nagios-plugins,首先是top.sls文件:
[root@cacti salt]# cat top.sls
base:
‘*‘:
- nagios
[root@cacti salt]# tree nagios #目录结构
nagios
├── conf.sls
├── files
│?? ├── conf.sh
│?? ├── nagios-plugins-1.5.tar.gz
│?? ├── nrpe-2.12.tar.gz
│?? └── nrpe.cfg
├── init.sls
├── install.sls
└── top.sls
[root@cacti nagios]# cat init.sls #sls文件引用
include:
- nagios.conf
- nagios.install
[root@cacti nagios]# cat install.sls #安装nagios-plugins
nagios_users: #创建用户
user.present:
- name: nagios
- uid: 5556
- gid_from_name: True
- createhome: False
- shell: /sbin/nologin
nagios_source:
file.managed:
- name: /usr/local/src/nagios-plugins-1.5.tar.gz
- source: salt://nagios/files/nagios-plugins-1.5.tar.gz
- user: root
- group: root
- mode: 644
- unless: test -f /usr/local/src/nagios-plugins-1.5.tar.gz
extract_nagios-plugins:
cmd.run:
- cwd: /usr/local/src
- name: tar xf nagios-plugins-1.5.tar.gz
- require:
- file: nagios_source
nagios_pkginstall:
pkg.installed:
- pkgs:
- gcc
- gcc-c++
- autoconf
- automake
- openssl
- openssl-devel
- zlib
- zlib-devel
- glibc
- glibc-common
nagios_commpile:
cmd.run:
- name: cd /usr/local/src/nagios-plugins-1.5 && ./configure --enable-redhat-pthread-workaround && make && make install
- require:
- cmd: extract_nagios-plugins
- pkg: nagios_pkginstall
[root@cacti nagios]# cat conf.sls #nrpe安装配置
include:
- nagios.install
nrpe_source:
file.managed:
- name: /usr/local/src/nrpe-2.12.tar.gz
- source: salt://nagios/files/nrpe-2.12.tar.gz
- user: root
- group: root
- mode: 755
- unless: test -f /usr/local/src/nrpe-2.12.tar.gz
cmd.run:
- name: cd /usr/local/src && tar xf nrpe-2.12.tar.gz && cd nrpe-2.12 && ./configure --enable-command-args && make all && make install-plugin && make install-daemon && make install-daemon-config
- require:
- file: nrpe_source
/usr/local/nagios/etc/nrpe.cfg:
file.managed:
- name: /usr/local/nagios/etc/nrpe.cfg
- source: salt://nagios/files/nrpe.cfg
- user: nagios
- group: nagios
- mode: 644
salt://nagios/files/conf.sh:
cmd.script:
- env:
- BATCH: ‘yes‘
- require:
- cmd: nrpe_source
- pkg: nagios_pkginstall
[root@cacti files]# cat conf.sh #执行nrpe启动脚本
#!/bin/bash
#
/bin/chown -R nagios.nagios /usr/local/nagios && /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
最后在Master端执行:
salt ‘minions‘ state.highstate即可
值得说明的是:这个是源码安装nrpe,nagios/libexec下可能没有我们自定义使用的脚本及其他二进制程序,如果把已经源码配置好的nrpe,打包成rpm包,可能会更方便管理;可惜不会制作rpm包啊!
本文出自 “LawLer” 博客,谢绝转载!
原文地址:http://10728233.blog.51cto.com/10718233/1791243