Nagios是一个监视系统运行状态和网络信息的监视系统。Nagios能监视所指定的本地或远程主机以及服务,同时提供异常通知功能等。
安装环境:ubuntu14.04,全是最新的nagios和nagios插件
useradd nagios
编译安装nagios
tar zxf nagios-4.0.7.tar.gz cd nagios-4.0.7 ./configure --prefix=/usr/local/nagios make all make install make install-init make install-commandmode make install-config make install-webconf mv cgi/ /usr/local/nagios/cgi-bin htpasswd ‐c /usr/local/nagios/etc/htpasswd.users nagiosadmin
编译安装nagios插件
tar zxf nagios-plugins-2.0.3.tar.gz cd nagios-plugins-2.0.3 ./configure --prefix=/usr/local/nagios make make install
编译安装nrpe(都得装)
NRPE是nagios的一个扩展,它被用于被监控的服务器上,向nagios监控平台提供该服务器的一些本地的情况。例如,cpu负载、内存使用、硬盘使用等等。NRPE可以称为nagios的for linux 客户端。
apt-get install openssl libssl-dev tar zxf nrpe-2.15 cd nrpe-2.15 ./configure --with-ssl=/usr/bin/openssl --with-ssl-lib=/usr/lib/x86_64-linux-gnu make all make install-plugin make install-daemon make install-daemon-config /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d /usr/local/nagios/libexec/check_nrpe ‐H localhost NRPE v2.15
这就说明check_nrpe连接nrpe daemon是正常的,其他被监控的主机都得这样check_nrpe
监控网络流量check_iftraffic
添加Nrpe.cfg
command[check_iftraffic]=/usr/local/nagios/libexec/check_iftraffic -i eth0 -w 5 -c 10 -b 10 -u m
服务定义
define service{ use generic-service host_name localhost service_description iftraffic check_command check_nrpe!check_iftraffic }
提示unable to read output的, 被控机的/tmp下有个traffic_ifeth*,把他的属主改成nagios就可以了
Pnp4nagios安装
pnp4nagios是基于RRD轮循(环状)数据库中所提供的综合信息,以可视化图形的方式呈现给用户的一款nagios插件
apt-get install rrdtool librrds-perl tar zxf pnp4nagios-0.6.22.tar.gz cd pnp4nagios-0.6.22 ./configure --prefix=/usr/local/pnp4nagios make all make install make install-webconf make install-config make install-init
配置pnp4nagios
cd /usr/local/pnp4nagios/etc/ mv misccommands.cfg-sample misccommands.cfg mv nagios.cfg-sample nagios.cfg mv rra.cfg-sample rra.cfg cd pages/ mv web_traffic.cfg-sample web_traffic.cfg
可以开启process_perfdata debug模式修改/usr/local/pnp4nagios/etc/process_perfdata.cfg
LOG_LEVEL = 2
会在/usr/local/pnp4nagios/var/perfdata.log显示错误日志,方便查找原因
貌似Synchronous Mode在nagios4.x有bug,日志显示一直找不到nagios环境,但是看官方文档更改enable_environment_macros=1应该影响开启nagios环境。
Bulk配置
修改nagios.cfg
process_performance_data=1 # # service performance data # service_perfdata_file=/usr/local/pnp4nagios/var/service-perfdata service_perfdata_file_template=DATATYPE::SERVICEPERFDATA TIMET::$TIMET$ HOSTNAME::$HOSTNAME$ SERVICEDESC::$SERVICEDESC$ SERVICEPERFDATA::$SERVICEPERFDATA$ SERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$ HOSTSTATE::$HOSTSTATE$ HOSTSTATETYPE::$HOSTSTATETYPE$ SERVICESTATE::$SERVICESTATE$ SERVICESTATETYPE::$SERVICESTATETYPE$ service_perfdata_file_mode=a service_perfdata_file_processing_interval=15 service_perfdata_file_processing_command=process-service-perfdata-file # # host performance data # # host_perfdata_file=/usr/local/pnp4nagios/var/host-perfdata host_perfdata_file_template=DATATYPE::HOSTPERFDATA TIMET::$TIMET$ HOSTNAME::$HOSTNAME$ HOSTPERFDATA::$HOSTPERFDATA$ HOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$ HOSTSTATE::$HOSTSTATE$ HOSTSTATETYPE::$HOSTSTATETYPE$ host_perfdata_file_mode=a host_perfdata_file_processing_interval=15 host_perfdata_file_processing_command=process-host-perfdata-file
修改commands.cfg
define command{ command_name process-service-perfdata-file command_line /usr/local/pnp4nagios/libexec/process_perfdata.pl --bulk=/usr/local/pnp4nagios/var/service-perfdata } define command{ command_name process-host-perfdata-file command_line /usr/local/pnp4nagios/libexec/process_perfdata.pl --bulk=/usr/local/pnp4nagios/var/host-perfdata }
重启nagios,然后就出图了。
一般使用的是默认模板,可以根据不同需求自定义模板temple
Nagios网页界面之Visual Shell
Nagios 提供的网页界面是自带的CGI程序,目前只提供英文语言,如果动手修改其排版,或者汉化核心CGI程序(C语言),则每一次版本更新都需要进行更改,这将是非常繁锁的工作。为了解决这个问题,我们可以通过读取Nagios监控系统的状态信息,即var/status.dat文件,根据其中的字段值来重新设计显示界面。
Nagios Visual shell (Vshell)是一个使用PHP编写的轻量级开源Nagios网页前端,输出的XHTML+CSS代码可以通过W3C标准验证。个人认为,Vshell的界面配色很一般,看一会儿就是会觉得很辛苦,以后的版本还需要加强美工。
apt-get install php-apc
V-Shell takes advantage of the Alternative PHP Cache system (APC), which is of particular importance if you are managing a large installation.
You may need to increase your PHP 'memory_limit' setting in your system's php.ini file if you're using APC. For large systems try a setting as high as 256-512MB.
wget http://assets.nagios.com/downloads/exchange/nagiosvshell/vshell.tar.gz tar zxf vshell.tar.gz cd vshell
修改install.php
define('TARGETDIR',"/usr/local/vshell"); define('APACHECONF',"/etc/httpd/conf.d"); (centos) define('APACHECONF',"/etc/apache2/conf.d"); (ubuntu) chmod +x install.php ./install.php