您的位置:首页 > 移动开发 > IOS开发

Nagios+NRPE安装备忘录(一)

2016-02-29 09:29 441 查看
环境

1. 数台Linux RH6 x86_64服务器需要进行load/disk space/process数量等监控

2. 其中client1/2/3 (下文c1/c2/c3)属于开发组A,client4/5(下文c4/c5)属于开发组B

准备

1. NIS环境下创建一个nagios账户和特定的组,如nagios,属组为nagios

2. 确保需要监控的服务器全部加入NIS

3. 选取一台服务器做nagios监控服务器,假设叫Monitor

4.下载安装包:https://www.nagios.org/downloads/ 选择免费的安装包(如果是需要商用版本,需要到www.nagios.com下载)

nagios core的免费版本叫Core DIY,当前最新版本为nagios-4.1.1。下图为https://www.nagios.org/downloads/nagios-core/ 页面展示的CORE的不同免费/收费版本的对比



nagios plugin版本为2.1.1,nrpe版本为2.15.

之所以选择nrpe,而不是使用ssh方式监控客户端,是考虑到所有服务器都在内网,并且各个服务器都有很多用途,cpu占用率比较高,如果使用Nagios的check_by_ssh插件,会增加monitor和client的cpu负担(https://assets.nagios.com/downloads/nagioscore/docs/nrpe/NRPE.pdf 原话是:: It is possible to execute Nagios
plugins on remote Linux/Unix machines through SSH. There is acheck_by_ssh plugin that allows you to do this. Using SSH is more secure than the NRPE addon, but it alsoimposes a larger (CPU) overhead on both the monitoring and remote machines. This can become
an issue whenyou start monitoring hundreds or thousands of machines. Many Nagios admins opt for using using the NRPEaddon because of the lower load it imposes.)

Monitor服务器上的安装Nagios

1. root登录Monitor

2. 确保Monitor上已经安装了Apache/PHP/GCC Compiler/GD development libraries

3. 把下载到的安装包, nagios-4.1.1.tar / nagios-plugins-2.1.1.tar.gz / nrpe-2.15.tar.gz放到某个目录,如/root/nagios,并解压(如 tar xzf nagios-plugins-2.1.1.tar.gz)

4. 先安装nagios (https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/quickstart.html 列出了安装的参考,但是没有针对RH的,所以实际参考了Fedora的安装手册 https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/quickstart-fedora.html

4.1 cd /root/nagios/nagios-4.4.1

4.2 预指定nagios安装的用户和属组:./configure--with-command-group=nagios --with-nagios-user=nagios--with-nagios-group=nagios

4.3 make all #编译Nagios源码

4.4 make install #安装二进制文件

4.5 make install-init #安装init 脚本

4.6 make install-config #安装样本配置文件

4.7 make install-commandmode #对外部命令目录设置权限

4.8 make install-webconf #在Apache conf.d目录下安装Nagios的web 配置文件

4.9 htpasswd-c /usr/local/nagios/etc/htpasswd.users nagiosadmin #创建一个可以访问Nagios web页面的账号并记录密码。密码一定要保存好,后面访问web页面会需要

4.10 vi /usr/local/nagios/etc/objects/contacts.cfg #将这个文件中nagiosadmin的contact信息修改为相应真实联系人的信息,如你将负责监控整个nagios的状态,那么就把你自己的信息,特别是email信息替换进去,以便后续可以收到相应的邮件通知。

4.11 service httpd restart #重启Apache,使上面的改动生效

5. 安装Nagios Plugins

5.1 cd /root/nagios/nagios-plugins-2.1.1

5.2 ./configure--with-nagios-user=nagios --with-nagios-group=nagios #指定用户和属组为前面创建的nagios专用用户和属组

5.3 make #编译源代码

5.4 make install #安装

6. 启动Nagios

6.1 chkconfig --add nagios; chkconfig nagios on #把Nagios加入到系统服务名单并在系统启动时自动启动

6.2 /usr/local/nagios/bin/nagios-v /usr/local/nagios/etc/nagios.cfg #检查nagios配置文件

6.3 service nagios start #如果上面一步没有错误,就可以启动Nagios

7. 访问Nagios Web

7.1 检查SELinux设置,以避免"Internal Server Error"

getenforce #检查SELinux是否在Enforcing状态

setenforce 0 #临时设置SELinux为Permissive状态

如果要永久修改SELinux状态,需要设置/etc/selinux/config中的状态,如SELINUX=disabled

如果不想修改SELinux状态,可以用以下命令运行CGI

chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin/

chcon -R -t httpd_sys_content_t /usr/local/nagios/share/

7.2 访问Nagios页面 http://[Mointor_ip]/nagios ,在这个过程中会需要输入之前htpasswd命令设置的用户名和密码

8. 其他

如果不能正常访问网页,在确保避开了SELinux问题后,检查Monitor上的防火墙设置

以上步骤只能保证在Monitor服务器上可以正常运行Nagios,并且在Web界面可以看到名称为LocalHost的服务器的性能指标。如果想用Monitor服务器的真实hostname替换LocalHost,具体步骤将在后面具体提供。

安装NRPE

1. 在Monitor服务器上

1.1 cd /root/nagios/nrpr-2.15

1.2 ./configure --with-nrpe-user=nagios --with-nrpe-group=nagios --with-nagios-user=nagios --with-nagios-group=nagios

1.3 make all #编译源代码

1.4 make install-plugin #安装NRPE插件

2. 在被监控的client服务器上,以c1为例讲解安装步骤

2.1. 以root登录c1

2.2. 先安装nagios-plugins

2.2.1 cd /root/nagios/nagios-plugins-2.1.1

2.2.2 ./configure--with-nagios-user=nagios --with-nagios-group=nagios #指定用户和属组为前面创建的nagios专用用户和属组

2.2.3 make #编译源代码

2.2.4 make install #安装

2.2.5 chown nagios.nagios /usr/local/nagios; chown -R nagios.nagios /usr/local/nagios/libexec #修改plugin的权限

2.3 检查是否需要安装xinet,没有的话,需要安装

2.4 安装NRPE

2.4.1 cd /root/nagios/nrpr-2.15

2.4.2 ./configure --with-nrpe-user=nagios --with-nrpe-group=nagios --with-nagios-user=nagios --with-nagios-group=nagios

2.4.3 make all #编译源代码

2.4.4 make install-plugin #安装NRPE插件

2.4.5 make install-daemon

2.4.6 make install-daemon-config

2.4.7 make install-xinetd

2.4.8 在/etc/xinetd.d/nrpe文件的only_from行,添加Monitor服务器的ip地址,以空格分开

2.4.9 在/etc/services文件末添加一行:nrpe5666/tcp# NRPE 并保存

2.4.10 根据具体情况,相应修改/usr/local/nagios/etc/nrpe.cfg文件末尾附近的command行。具体的修改将在另外一篇博文记录。

2.5 重启xinetd服务 service xinetd restart

2.6 检查nrpe是否正常工作

输入 netstat -at | grep nrpe ,期待的结果是

tcp 0 0 *:nrpe *:* LISTEN

如果有问题需要重复检查以上步骤,特别是/etc/xinted.d/nrpe中only_from是不是包含127.0.0.1

2.7 在Monitor服务器上验证是否可以获取c1的NRPE版本

/usr/local/nagios/libexec/check_nrpe -H [c1_ip]

期待的结果是输出NRPE v2.15

2.8 在enable了IPV6的c1机器上可能出现的问题:

当运行/usr/local/nagios/libexec/check_nrpe -H localhost 的时候,报以下错误:

CHECK_NRPE: Error - Could not complete SSLhandshake.

解决办法参考 http://blog.csdn.net/njchina/article/details/50699212
2.9 如果不想使用xinetd服务来运行NRPE,还有一种办法:

2.9.1 先用service xinetd stop来停掉xinetd,并用chkconfig xinetd off来彻底禁止xinet以后在level2-5自动启动。

2.9.2 修改/usr/local/nagios/etc/nrpe.cfg, 在allowed_hosts=127.0.0.1后用逗号分隔,添加Monitor的ip地址

2.9.3 用命令/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d 启动nrpe

2.9.4 把上面的命令写成脚本放到initd.d中,方便以后重启nrpe

还有一个悬而未决的问题:c1上/etc/xinetd.d/nrpe文件有可能会被插入disable=yes一行,会导致在Monitor的Nagios web界面c1的信息出现Return code of 255 is out of bounds 是什么原因导致这个变动没有找到,也没有在网上搜索到

NRPE的安装文档 https://assets.nagios.com/downloads/nagioscore/docs/nrpe/NRPE.pdf
以上只是基本的安装部分。要正确配置Nagios,还需要花很多的功夫。我在这上面走了很多弯路。最后总结的经验记录在安装备忘录(二)里。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: