1、验证Nagios配置文件的正确性 nagios在验证配置文件方面做的非常到位,只需通过一个命令即可完成:/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfgNagios提供的这个验证功能非常有用,在错误信息中通常会打印出错误的配置文件以及文件中的哪一行,这使得nagios的配置变得非常容易,报警信息通常是可以忽略的,因为一般那些只是建议性的。
2、 启动与停止nagios (1)启动nagiosü通过初始化脚本启动nagios/etc/init.d/nagios start或者Service nagios startü手工方式启动nagios通过nagios命令的“-d”参数来启动nagios守护进程:/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg (2)关闭nagiosü通过初始化脚本关闭nagios服务/etc/init.d/nagios stop或者Service nagios stopü通过kill方式关闭nagioskill <nagios_pid> (3)重启nagiosü通过初始化脚本来重启nagios/etc/rc.d/init.d/nagios reload/etc/rc.d/init.d/nagios restartü通过web监控页重启nagios
3.nagios性能分析图表 (1)nagios性能分析图表的作用Nagios对服务或主机监控的是一个瞬时状态,有时候系统管理员如果需要了解主机在一段时间内的性能以及服务的响应状态,并且形成图表时,就需要通过查看日志数据来分析,但是这种方式不但繁琐,而且抽象,不过幸运的是,PNP可以帮助我们来完成这个工作。 (2) PNP的概念与安装环境PNP是一个小巧的开源软件包,它基于PHP和PERL,PNP可以利用rrdtool工具将Nagios采集的数据绘制成相关的图表,然后显示主机或者服务在一段时间内的运行状况。PNP官方网站为:http://www.pnp4nagios.org如果要安装PNP,首先需要安装如下环境:1:整合后的apache何PHP环境,需支持GD\zlib\jpeg2:安装rrdtool工具3:安装perl RRDtool是一个图表生成工具,可以从http://www.mrtg.org/rrdtool/获得信息。这里下载的版本是rrdtool-1.4.5.tar.gz, 安装过程如下: [iyunv@nagios rrdtool]# tar zxvf rrdtool-1.4.5.tar.gz [iyunv@nagios rrdtool]# cd rrdtool-1.4.5
[iyunv@nagios rrdtool-1.4.5]# ./configure --perfix=/usr/local/rrdtool
[iyunv@nagios rrdtool-1.4.5]# make
[iyunv@nagios rrdtool-1.4.5]# make install
配置时报错:./configure --prefix=/usr/local/rrdtool configure: WARNING:
----------------------------------------------------------------------------
* I could not find a working copy of glib-2.0. Check config.log for hints on why
this is the case. Maybe you need to set LDFLAGS and CPPFLAGS appropriately
so that compiler and the linker can find libglib-2.0 and its header files. If
you have not installed glib-2.0, you can get it either from its original home on ftp://ftp.gtk.org/pub/glib/2.12/ You can find also find an archive copy on http://oss.oetiker.ch/rrdtool/pub/libs The last tested version of glib-2.0 is 2.12.12. LIBS=-lm -lwrap
LDFLAGS=
CPPFLAGS= ----------------------------------------------------------------------------
checking for pango_cairo_context_set_font_options in -lpangocairo-1.0... no
checking for pkg-config... (cached) pkg-config
configure: WARNING:
----------------------------------------------------------------------------
* I found a copy of pkgconfig, but there is no pangocairo.pc file around.
You may want to set the PKG_CONFIG_PATH variable to point to its
location.
---------------------------------------------------------------------------- configure: WARNING:
----------------------------------------------------------------------------
* I could not find a working copy of pangocairo. Check config.log for hints on why
this is the case. Maybe you need to set LDFLAGS and CPPFLAGS appropriately
so that compiler and the linker can find libpangocairo-1.0 and its header files. If
you have not installed pangocairo, you can get it either from its original home on http://ftp.gnome.org/pub/GNOME/sources/pango/1.17 You can find also find an archive copy on http://oss.oetiker.ch/rrdtool/pub/libs The last tested version of pangocairo is 1.17. LIBS=-lm -lwrap
LDFLAGS=
CPPFLAGS= ----------------------------------------------------------------------------
checking for xmlParseFile in -lxml2... yes
checking libxml/parser.h usability... yes
checking libxml/parser.h presence... yes
checking for libxml/parser.h... yes
configure: error: Please fix the library issues listed above and try again. 解决方法是: yum install -y glib libpng pixman pango-devel
接着安装PNP,这里下载的版本是pnp-0.4.13.tar.gz, 安装过程如下:[iyunv@nagios pnp]#tar -xvzf pnp-0.4.13.tar.gz
[iyunv@nagios pnp]#cd pnp-0.4.13 [iyunv@nagios pnp-0.4.13]#./configure --with-nagios-user=nagios --with-nagios-group-nagios --with-rrdtool=/usr/local/rrdtool/bin/rrdtool --with-perfdata-dir=/usr/local/nagios/share/perfdata
[iyunv@nagios pnp-0.4.13]#make all [iyunv@nagios pnp-0.4.13]#make install
[iyunv@nagios pnp-0.4.13]#make install-config
[iyunv@nagios pnp-0.4.13]#make install-init
安装完成,PNP默认文件放置情况如下:General Options:------------------------------------------------ Nagios user/group: nagios nagios
Install directory:/usr/local/nagios
HTML Dir:/usr/local/nagios/share/pnp
Config Dir:/usr/local/nagios/etc/pnp Path to rrdtool:/usr/loca/bin/rrdtool (Version 1.4.5) RRDs Perl Modules:*** NOT FOUND ** RRD Files stored in:/usr/local/nagios/share/perfdata
process_perfdata.pl Logfile:/usr/local/nagios/var/perfdata.log Perfdata files (NPCD) stored in:/usr/local/nagios/var/spool/perfdata/
配置pnp
①创建默认配置文件 cd /usr/local/nagios/etc/pnp/
cp process_perfdata.cfg-sample process_perfdata.cfg cp npcd.cfg-sample npcd.cfg
cp rra.cfg-sample rra.cfg
chown -R nagios:nagios * ②修改process_perfdata.cfg文件 vi /usr/local/nagios/etc/pnp/process_perfdata.cfg
LOG_FILE = /usr/local/nagios/var/perfdata.log # Loglevel 0=silent 1=normal 2=debug LOG_LEVEL = 2 这里将日志级别改为2,即为debug模式。
修改nagios配置文件 ①增加小太阳标示修改templates.cfg,增加一个定义PNP的hosts和services
define host {
name hosts-pnp
register 0
action_url /nagios/pnp/index.php?host=$HOSTNAME$ process_perf_data 1
}
define service {
name services-pnp
register 0
action_url /nagios/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$
process_perf_data 1 }
②修改nagios.cfg找到如下几项,去掉注释,修改后信息如下: process_performance_data=1
host_perfdata_command=process-host-perfdata
service_perfdata_command=process-service-perfdata
③修改commands.cfg
# 'process-host-perfdata' command definition define command{
command_name process-host-perfdata
command_line /usr/local/nagios/libexec/process_perfdata.pl
} # 'process-service-perfdata' command definition
define command{ command_name process-service-perfdata
command_line /usr/local/nagios/libexec/process_perfdata.pl } ④修改hosts.cfg文件和services.cfg文件 define host{ use linux-server,hosts-pnp host_name web alias ixdba-web address 192.168.12.251
}
define host{ use linux-server,hosts-pnp
host_name mysql
alias ixdba-mysql address 192.168.12.237 } define service{ use local-service,services-pnp host_name mysql service_description SSH check_command check_ssh }
define service{ use local-service,services-pnp
host_name web service_description http
check_command check_http
}
测试PNP功能
所有配置完成之后,重新检查nagios配置文件是否正确,然后重启nagios
/etc/init.d/nagios restart如果配置正确,此时就会生成响应主机的pnp文件[iyunv@nagios web]# pwd
/usr/local/nagios/share/perfdata/web [iyunv@gaojf web]# lshttp.rrdhttp.xmlPING.rrdPING.xmlSSHD.rrdSSHD.xml
最后打开网页:打开网页http://IP/nagios,选择主机选项,然后点击小太阳就可以看到图表,或者访问http://ip/nagios/pnp也可以直接访问图表信息。
排错 gd及zlib等都已安装,报错截图如下:
重新编译安装php 加上zlib的支持 [iyunv@test1 php-5.2.9]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-gd --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --enable-sockets
|