与在redhat安装nagios相比,在ubuntu安装nagios监控非常简单,直接通过
apt-get即可从ubuntu的服务器上下载组件自动安装。
sudo apt-get install nagios3 nagios-nrpe-plugin
给nagiosadmin添加一个密码:
sudo htpasswd /etc/nagios3/htpasswd.users nagiosadmin
添加一个用户:
sudo htpasswd /etc/nagios3/htpasswd.users dragon
在被监控主机上安装nrpe,
sudo apt-get install nagios-nrpe-server
sudo vi /etc/nagios/nrpe.cfg
找到allowed_host添加监控主机的ip地址:
allowed_hosts=127.0.0.1,192.168.1.112
Service nrpe restart
在server端测试
/usr/lib/nagios/plugins/check_nrpe -H 192.168.1.124,测试成功的话会输出客户机的NRPE版本号。
NRPE_2.1.4
在server新建监控主机定义文件server02.cfg
sudo cp /etc/nagios3/conf.d/localhost_nagios2.cfg \/etc/nagios3/conf.d/server02.cfg
编辑 /etc/nagios3/conf.d/server02.cfg:注意修改address为被监控主机的地址,并添加DNS,http,ssh的服务监控。
define host{
use generic-host
host_name server02
alias server-02
address 192.168.1.124
}
define service{
use generic-service
host_name server02
service_description Disk Space
check_command check_all_disks!20%!10%
}
define service{
use generic-service
host_name server02
service_description Current Users
check_command check_users!20!50
}
define service{
use generic-service
host_name server02
service_description Total Processes
check_command check_procs!250!400
}
define service{
use generic-service
host_name server02
service_description Current Load
check_command check_load!5.0!4.0!3.0!10.0!6.0!4.0
}
define service{
use generic-service
host_name server02
service_description DNS
check_command check_dns!192.168.1.124
}
define service {
host_name server02
service_description HTTP
check_command check_http
use generic-service
notification_interval 0
}
# check that ssh services are running
define service {
host_name server02
service_description SSH
check_command check_ssh
use generic-service
notification_interval 0
}
测试nagios配置是否成功
nagios3 -v /etc/nagios3/nagios.cfg
Error in configuration file '/etc/nagios3/nagios.cfg' - Line 470 (Check result path is not a valid directory)
这个文件是nagios用于存储监测主机的结果和未能监测到的服务信息
check_result_path=/var/lib/nagios3/spool/checkresults
我发现本机上并没有这个文件目录的存在,所以我新建了这个文件,可能会出现启动nagios没有报错,但无法看到监控信息的情况,查看日志提示“Jul 16 20:00:59 fileserver nagios: Error: Could not open check result queue directory '/var/nagios/spool/checkresults' for reading. ”.
Sudo mkdir /var/lib/nagios3/spool/checkresults
Sudo chmod nagios:nagios /var/lib/nagios3/spool/checkresults
启动nagios
Service nagios3 start
打开在浏览器地址栏输入:“ip\nagios3”
利用NSClient++监控远程Windows上的“本地信息”
在Nagios的libexec下有check_nt这个插件,它就是用来检查windows机器的服务的。其功能类似于check_nrpe。不过还需要搭配另外一个软件NSClient++,它则类似于NRPE。
NSClient++的原理如下图
可以看到NSClient与nrpe最大的区别就是:
被监控机上安装有nrpe,并且还有插件,最终的监控是由这些插件来进行的。当监控主机将监控请求发给nrpe后,nrpe调用插件来完成监控。
NSClient++则不同,被监控机上只安装NSClient,没有任何的插件。当监控主机将监控请求发给NSClient++后,NSClient直接完成监控,所有的监控是由NSClient完成的。
这也说明了NSClient++的一个很大的问题:不灵活、没有可扩展性。它只能完成自己本身包含的监控操作,不能由一些插件来扩展。好在NSClient++已经做的不错了,基本上可以完全满足我们的监控需求。
安装NSClient++
使用check_nt可以看到winserver上nsclient++的监控情况(注意需要指定端口为:12489)
要注意两台主机之间网络是否联通,使用ping测试网络联通,winserver的防火墙有可能阻断两台主机之间的网络通信,可以选择关掉。
编辑nagios server端的nt.cfg里面的命令check_nt增加一些参数。
sudo vi /etc/nagios-plugins/config/nt.cfg
Sudo vi /etc/nagios3/objects/windows.cfg
define host{
use generic-host ; Inherit default values from a template
host_name Nagios-Windows ; The name we're giving to this host
alias My Windows Server ; A longer name associated with the host
address 192.168.1.139 ; IP address of the host
}
define hostgroup{
hostgroup_name windows-servers ; The name of the hostgroup
alias Windows Servers ; Long name of the group
}
define service{
use generic-service
host_name Nagios-Windows
service_description NSClient++ Version
check_command check_nt!CLIENTVERSION
}
define service{
use generic-service
host_name Nagios-Windows
service_description Uptime
check_command check_nt!UPTIME
}
define service{
use generic-service
host_name Nagios-Windows
service_description CPU Load
check_command check_nt!CPULOAD!-l 5,80,90
}
define service{
use generic-service
host_name Nagios-Windows
service_description Memory Usage
check_command check_nt!MEMUSE!-w 80 -c 90
}
define service{
use generic-service
host_name Nagios-Windows
service_description C:\ Drive Space
check_command check_nt!USEDDISKSPACE!-l c -w 80 -c 90
}
define service{
use generic-service
host_name Nagios-Windows
service_description W3SVC
check_command check_nt!SERVICESTATE!-d SHOWALL -l W3SVC
}
define service{
use generic-service
host_name Nagios-Windows
service_description Explorer
check_command check_nt!PROCSTATE!-d SHOWALL -l Explorer.exe
}
测试nagios配置是否成功
nagios3 -v /etc/nagios3/nagios.cfg
service nagios3 restart
Sudo vi /etc/nagios3/nagios.cfg把#cfg_file=/etc/nagios3/objects/windows.cfg前面的#给去掉。使用“nagios3 -v /etc/nagios3/nagios.cfg”测试是否有错。没有报错的话,开启nagios3.
用浏览器打开nagios的控制台等待一段时间之后就可以看到实验效果了。
本文允许转载但务必保留出处:(http://dragon123.blog.51cto.com/9152073/1543915)