Nagios Setup

URL:https://support.nagios.com/kb/article/nagios-core-installing-nagios-core-from-source-96.html#RHEL

1.下载nagios-4.4.2.tar.gz
2.yum install gcc glibc glibc-common wget unzip httpd php gd gd-devel perl postfix
No package gd-devel available.
下载gd-devel
https://centos.pkgs.org/6/centos-x86_64/gd-devel-2.0.35-11.el6.x86_64.rpm.html

[[email protected] downloads]# rpm -ivh gd-devel-2.0.35-11.el6.x86_64.rpm
error: Failed dependencies:
fontconfig-devel is needed by gd-devel-2.0.35-11.el6.x86_64

[[email protected] downloads]# yum install fontconfig-devel freetype-devel libX11-devel libXpm-devel libgd.so.2 libjpeg-devel libpng-devel pkgconfig zlib-devel

依赖包都安装完毕后,再次安装gd-devel
[[email protected] downloads]# rpm -ivh gd-devel-2.0.35-11.el6.x86_64.rpm
package gd-devel-2.0.35-11.el6.x86_64 is already installed

此时可以继续安装nagios-core了。

3.解压,安装
[[email protected] downloads]# tar zxvf nagios-4.4.2.tar.gz
[[email protected] downloads]# cd nagios-4.4.2

[[email protected] nagios-4.4.2]# ./configure
[[email protected] nagios-4.4.2]# make all

4.Create User And Group
[[email protected] nagios-4.4.2]# make install-groups-users
groupadd -r nagios
useradd -g nagios nagios

5.Install Binaries
[[email protected] nagios-4.4.2]# make install

6.Install Service / Daemon
[[email protected] nagios-4.4.2]# make install-daemoninit
httpd自启动由于已经设置完毕,这里就不重复设定了。

7.Install Command Mode
[[email protected] nagios-4.4.2]# make install-commandmode

8.Install Configuration Files
[[email protected] nagios-4.4.2]# make install-config

9.Install Apache Config Files
[[email protected] nagios-4.4.2]# make install-webconf

10.Configure Firewall
防火墙80端口已经放行。所以这里就不配置了。
否则配置以下命令(RHEL6)
iptables -I INPUT -p tcp --destination-port 80 -j ACCEPT
service iptables save
ip6tables -I INPUT -p tcp --destination-port 80 -j ACCEPT
service ip6tables save

11.Create nagiosadmin User Account
[[email protected] nagios-4.4.2]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

12.启动服务
[[email protected] nagios-4.4.2]# /etc/init.d/nagios start
Starting nagios: Running configuration check... done.

13.此时遇到一个问题,由于我设定了两个VirtualHost,貌似现在无法使用http://IP/nagios或是http://IP:8080/nagios进行访问。
首先确认/etc/httpd/conf/httpd.conf里,
LoadModule cgi_module modules/mod_cgi.so被开启。

然后发现是没有重启Httpd服务导致的。重启后就能正常访问nagios页面了。
需要注意的是,弹出的需要输入用户名和密码的框,是输入刚才设定的nagiosadmin和他的密码。
不要输入成自己设定的http基础认证了。
而且经过测试,不论是80端口还是8080端口,只要开放了的端口都可以被用作nagios的访问端口

URL:https://blog.51cto.com/jianye/1364716

14.接下来安装Nagios Plugin
下载 nagios-plugins-2.2.1.tar.gz(错误!)这里注意要下载的是nagios-plugins-release-2.2.1。否则后面的./tools/setup不存在。
[[email protected] downloads]# tar zxvf nagios-plugins-release-2.2.1.tar.gz

[[email protected] nagios-plugins-2.2.1]# yum install gcc glibc glibc-common make gettext automake wget openssl-devel net-snmp net-snmp-utils epel-release
全都已经安装。

无网络环境下,千万不要按照官方文档安装epel-release-latest-6.noarch.rpm。否则自建的光盘repo会爆炸。

[[email protected] nagios-plugins-2.2.1]# yum install -y perl-Net-SNMP
No package perl-Net-SNMP available.

URL:https://centos.pkgs.org/6/repoforge-i386/perl-Net-SNMP-5.2.0-1.2.el6.rf.noarch.rpm.html

perl(Net::SNMP) = perl-Net-SNMP

这安装perl-Net-SNMP遇到了问题。在没有网络的情况下,好像没法简单的用perl来安装Net-SNMP。
下载perl-Net-SNMP-5.2.0-1.2.el6.rf.noarch.rpm
[[email protected] downloads]# rpm -ivh perl-Net-SNMP-5.2.0-1.2.el6.rf.noarch.rpm
error: Failed dependencies:
perl(Crypt::DES) is needed by perl-Net-SNMP-5.2.0-1.2.el6.rf.noarch
perl(Digest::HMAC) is needed by perl-Net-SNMP-5.2.0-1.2.el6.rf.noarch
perl(Digest::SHA1) is needed by perl-Net-SNMP-5.2.0-1.2.el6.rf.noarch
perl(Socket6) >= 0.19 is needed by perl-Net-SNMP-5.2.0-1.2.el6.rf.noarch

下载并安装依赖包
[[email protected] downloads]# rpm -ivh perl-Crypt-DES-2.05-3.2.el6.rf.x86_64.rpm
[[email protected] downloads]# rpm -ivh perl-Digest-SHA1-2.12-2.el6.x86_64.rpm
[[email protected] downloads]# rpm -ivh perl-Digest-HMAC-1.01-22.el6.noarch.rpm
[[email protected] downloads]# rpm -ivh perl-Socket6-0.23-4.el6.x86_64.rpm

再安装perl-Net-SNMP
[[email protected] downloads]# rpm -ivh perl-Net-SNMP-5.2.0-1.2.el6.rf.noarch.rpm
warning: perl-Net-SNMP-5.2.0-1.2.el6.rf.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 6b8d79e6: NOKEY
Preparing... ########################################### [100%]
1:perl-Net-SNMP ########################################### [100%]

成功了。

15.继续安装Nagios-Plugin
[[email protected] downloads]# cd nagios-plugins-release-2.2.1

[[email protected] nagios-plugins-release-2.2.1]# ./tools/setup
[[email protected] nagios-plugins-release-2.2.1]# ./configure
[[email protected] nagios-plugins-release-2.2.1]# make
[[email protected] nagios-plugins-release-2.2.1]# make install

经验证,现在nagios里的localhost已经up了。

16.添加开机自启动
[[email protected] nagios-plugins-release-2.2.1]# chkconfig --add nagios
[[email protected] nagios-plugins-release-2.2.1]# chkconfig --level 2345 nagios on
检测监控配置是否有错误。
[[email protected] nagios-plugins-release-2.2.1]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

17.命令行测试nagios插件的可用性
[[email protected] ~]# /usr/local/nagios/libexec/check_ping -H 10.116.6.193 -w 3000.0,80% -c 5000.0,100% -p 5
PING OK - Packet loss = 0%, RTA = 31.18 ms|rta=31.181999ms;3000.000000;5000.000000;0.000000 pl=0%;80;100;0

18.修改contact信息
[[email protected] etc]# vi objects/contacts.cfg
email [email protected] ;

19.复制一个windows模板出来
[[email protected] objects]# cp windows.cfg windows.cfg.bak

[[email protected] objects]# vi windows.cfg
修改定义Host。

define host {

use                     windows-server          ; Inherit default values from a template
host_name               CyberArk               ; The name we‘re giving to this host
alias                   My Windows Server       ; A longer name associated with the host
address                 10.116.6.193             ; IP address of the host(这里修改IP)

}

另外记得把下面默认定义的所有针对Windows的Service模板里的host_name全部注释掉,并且都增加一行"hostgroup_name windows-servers ;"
否则配置文件会出错。

并添加如下Ping的服务,这个在windows里没有,但其实也可以不定义。因为默认在网页的Host里就是对PING的验证了。
##################Added by Chris###################

Define a service to "ping" the local machine

define service {

use                     generic-service           ; Name of service template to use

host_name winserver

hostgroup_name          windows-servers         ; The name of the hostgroup
service_description     PING
check_command           check_ping!100.0,20%!500.0,60%

}
##################Added by Chris###################
但是重启nagios后还是没有,这是因为除了localhost外,默认其他模板不生效.
需要到nagios.cfg里去取掉#注释。
[[email protected] objects]# vi ../nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/windows.cfg

注意在重启服务前,记得用这个命令先验证一下配置文件。
[[email protected] objects]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

[[email protected] objects]# /etc/init.d/nagios restart

20.发现包括C盘空间监控的一系列服务拒绝连接。
connect to address 10.116.6.193 and port 12489: 拒绝连接
原因是,这些命令是采用NRPE,NSClient等第三方agent区实现监控的。
我想用SNMP实现,所以需要在Nagios服务器上新增监控用的插件。

URL:http://nagios.manubulon.com/snmp_windows.html
点开download链接,是一段perl脚本。
直接到本地Libexec文件夹,设定755属性保存。发现执行./check_snmp_windows.pl -h没反应。

URL:https://blog.csdn.net/winsonyuan/article/details/54863667

[[email protected] libexec]# yum install perl*

再次执行pl脚本还是不执行,我发现一个问题,脚本内容由于直接从网上复制下来的,好像格式之间没有换行。也许是这个原因?
于是我右键保存目标target,下载下来是一个htm文件,用word打开,发现里面的格式是正确的,修改后缀名为pl后,最后用rz复制到linux系统上。
我下载的是这个:
URL: http://nagios.manubulon.com/snmp_windows.html
[[email protected] libexec]# chmod 755 check_snmp_win.pl

果然就可以执行了!
[[email protected] libexec]# ./check_snmp_win.pl -H 10.116.6.193 -C public -n HTTP -N 2
1 services active (matching "HTTP") : CRITICAL
[[email protected] libexec]# ./check_snmp_win.pl -H 10.116.6.193 -C public -n dns
1 services active (matching "dns") : OK

Linux系统不行,因为这个pl本身就是针对windows的。
并且需要注意,在页面上已经说明了,这个pl只能用于snmpv1,v3,不支持v2。所以在操作前,先验证v1的可用性。
[[email protected] libexec]# snmpwalk -v2c -c public 10.116.6.193

这个页面可以参考配置define command,service,
URL:http://nagios.manubulon.com/index_commands.html#windows

[[email protected] libexec]# vi ../etc/objects/commands.cfg
加入以下这段。
define command {
command_name check_win
command_line $USER1$/check_snmp_win.pl -H $HOSTADDRESS$ -C $USER7$ -n $ARG1$

comment community service(s) name

}

[[email protected] objects]# vi windows.cfg
加入以下这段。
define service {
use generic-service
hostgroup_name windows-servers ; The name of the hostgroup
service_description HTTP service
check_command check_win!http
}
注意,按照URL中的文档添加会出错,我们还是要参考当前环境进行设置。
[[email protected] objects]# /etc/init.d/nagios restart

然而此时Status Information显示Put snmp login info!
检查commands.cfg 发现里面有个$USER7$,不仅在前面漏了-C, 这个是用来定义Community的。目前还没在resource.cfg里定义。
command_line $USER1$/check_snmp_win.pl -H $HOSTADDRESS$ $USER7$ -n $ARG1$
[[email protected] etc]# vi resource.cfg

Sets $USER7$ to be the SNMP community name

$USER7$=public
}

然后重启服务,一切恢复正常。

21.接下来配置check_snmp_storage.pl,用来监控windows的磁盘空间
同样的方法,复制到libexec目录,赋予755权限.
然后,网页文档里没有描述如何监控windows磁盘.但是在script -h里有。
Browse storage list : <script> -C <community> -H <host> -m <anything> -w 1 -c 2 -v
the -m option allows regexp in perl format :
Test drive C,F,G,H,I on Windows : -m ^[CFGHI]:
看到这段文字。
[[email protected] libexec]# ./check_snmp_storage.pl -C public -H 10.116.6.193 -m ^[CD]: -w 1 -c 2 -v
这条命令可以成功执行。
根据这条语句,可以想象出定义的command为:

[[email protected] objects]# vi commands.cfg
define command {
command_name check_snmp_stor
command_line $USER1$/check_snmp_storage.pl -H $HOSTADDRESS$ -C $ARG1$ -m $ARG2$ -w $ARG3$ -c $ARG4$
}

[[email protected] objects]# vi windows.cfg
define service {
use generic-service
hostgroup_name windows-servers ; The name of the hostgroup
service_description C:\ Disk Space
check_command check_snmp_stor!public!C:!70!90
}

22.接着监控进程
下载check_snmp_process.pl。修改权限755复制到libexec目录下。
check_snmp_process.pl
[[email protected] libexec]# ./check_snmp_process.pl -C SMBC -H 10.116.6.193 -n CAPSM.exe -v
1 process matching CAPSM.exe (> 0)

[[email protected] objects]# vi commands.cfg
define command{
command_name check_snmp_process_v1
command_line $USER1$/check_snmp_process.pl -C $ARG1$ -H $HOSTADDRESS$ -n $ARG2$ -w $ARG3$ -c $ARG4$
}

ARG1 : community
ARG2 : regexp of process name
ARG3 : warning level(s)
ARG4 : critical level(s)

[[email protected] objects]# vi windows.cfg
define service {
use generic-service
hostgroup_name windows-servers ; The name of the hostgroup
service_description AppProvider.exe
check_command check_snmp_process_v1!public!"AppProvider.exe"!0!0
}
重启服务后查看效果。
经过验证,如果warning和critical都设置为0,则会报critical而不是warning.
check_command check_snmp_process_v1!public!"PsExec.exe"!0!0

23.邮件发送设置
[[email protected] objects]# yum install sendmail
[[email protected] objects]# /etc/init.d/sendmail start

[[email protected] objects]# echo "test" | mail [email protected]
停了防火墙和selinux后还是收不到。
查看日志,发现原来是因为那是个外部邮箱。而我的server是局域网的。
这当然收不到了。

=======================================================

原文地址:https://blog.51cto.com/7350550/2391052

时间: 2024-08-02 21:47:33

Nagios Setup的相关文章

Nagios Server通过NRPE监控client memory usage.

How to monitor server memory usage with Nagios Remote Plugin Executor (NRPE) Last updated on September 8, 2014 Authored by Sarmed Rahman 5 Comments In a previous tutorial, we have seen how we can set up Nagios Remote Plugin Executor (NRPE) in an exis

一款德国的Nagios插件---Check_mk 搭建

经过两周的研究与测试,把Check_Mk摸得40%程度,在这里简单的总结一下并分享给大家,可能还存在问题,请大家多多指点.. Check_mk 安装 第 1 章  check_mk的介绍 Check_MK是一款通用的Nagios/Icinga数据采集插件,主要由三个子项目组成.它采用了新的方法从操作系统和网络组件中收集数据和淘汰老式的NRPE.check_by_ssh.NSClient和check_snmp.其优点能够自动检测主机上的监控项目,并且在监控端的CPU使用率也显著减少.其遵循CPL

nagios监控安装esxi的服务器(宿主机)

首先,该博文大部分内容来自网络,少部分是自己监控过程中遇到的问题.如果有侵权,请联系告知!!! 现在互联网公司,有能力的都是自己研发监控系统,要么就是zabbix或者小米的监控,还都二次开发等等,可能使用nagios的不是那么多.哈哈,做个记录,仅供参考!!! <准备部署使用open-Falcon(小米开源)> 以下内容大部分来自网络: 普通的Dell服务器硬件监控我们可以通过nagios+openmanage来实现,但是vsphere环境中的Esxi主机的硬件监控怎么实现呢? 这里有两种方案

nagios使用的问题解决

1.通过web界面修改某个服务时报错 例如对某个服务进行临时安排其执行时间,或者不让它发警告,web页面上都有这样的设置.但是常常会有错误信息如下: Could not open command file '/usr/local/nagios/var/rw/nagios.cmd' for update! The permissions on the external command file and/or directory may be incorrect. Read the FAQs on

python根据nagios配置文件将监控的服务联系人等信息导出到excel表格

前阵子,遇到需要把nagios监控的服务统计到表格的需求,想着如果每一次改动,都要去维护表格的话,难免会有疏漏或者问题,于是观察了nagios的host.cfg,services.cfg等配置文件写了一个脚本,包含对多个主机关联到同一个服务的处理等,脚本也有局限性,就是需要把每个主机,都归类到某个组,比如Linux主机归类到Linux组,实际环境,一般也是有这样做归类的,脚本运行过程中会有文件产生,但都很小,以下是相应模块安装和脚本文件,建议在测试机上面跑完再到实际环境跑. 一,安装xlsxwr

Nagios简介与安装(1)

搭建Nagios实在是一个繁杂的过程,首先需要读者有Linux基础,最为重要的是要花费大量的精力和时间,还有就是耐心和细心.我主要是参考网上这篇文章,觉得写的非常好. 原文: http://www.cnblogs.com/mchina/archive/2013/02/20/2883404.html http://www.ibm.com/developerworks/cn/linux/1309_luojun_nagios/ 一.Nagios简介 Nagios是一款开源的电脑系统和网络监视工具,能有

nagios使用问题的解决方案

通过web界面修改某个服务时报错例如对某个服务进行临时安排其执行时间,或者不让它发警告,web页面上都有这样的设置.但是常常会有错误信息如下: Could not open command file '/usr/local/nagios/var/rw/nagios.cmd' for update!The permissions on the external command file and/or directory may be incorrect. Read the FAQs on how

nagios监控vsphere ESXi主机硬件状态(CPU风扇、电源模块、硬盘、温度)

esxi 的只读账户和密码(本文以chkhardware/chkreadonly为例)插架下载地址,此地址附有相关说明:http://www.claudiokuenzler.com/nagios-plugins/check_esxi_hardware.php ESXI主机:DELL R410ESXI版本:ESXI4.0 配置1)check_esxi_hardware.py 复制到nagios插件目录/usr/local/nagios/libexec2)command.cfg要实现如下的效果: -

nagios配置

接近两个星期的奋战,nagios的安装搭建以及监控服务自动报警功能终于基本得以实现,现在自己整理一份安装技术手册,方便自己以后查阅和回顾. 接近两个星期的奋战,nagios的安装搭建以及监控服务自动报警功能终于基本得以实现,现在自己整理一份安装技术手册,方便自己以后查阅和回顾. 一.Nagios试验环境以基本安装 主机名 操作系统 IP 作用 Nagios-Server Centos5.4 211.162.127.51 监控机 211.162.127.43 Centos5.4 211.162.1