三、Nagios的运行和维护
1) 验证nagios主配置文件的语法正确性
[root@localhost etc]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Total Warnings: 0
Total Errors: 0
Things look okay - No serious problems were detected during the pre-flight check
2) 启动与停止nagios
[root@localhost etc]# service nagios start
Starting nagios:This account is currently not available.
done.
[root@localhost etc]# service nagios status
nagios (pid 5106) is running...
[root@localhost etc]# service nagios stop
[root@localhost etc]# service nagios restart
Running configuration check...done.
Stopping nagios: No lock file found in /usr/local/nagios//var/nagios.lock
Starting nagios:This account is currently not available.
done.
四、Nagios性能分析图表的实现
1) 安装PNP支持包rrdtool工具
首先安装支持包
yum install libxml2-devel libpng-devel pkg-config glib pixman pango pango-devel freetype freetype-devel fontconfig cairo cairo-devel libart_lgpl libart_lgpl-devel
[root@localhost aaa]# tar zxf rrdtool-1.4.5.tar.gz
[root@localhost aaa]# cd rrdtool-1.4.5
[root@localhost rrdtool-1.4.5]# ./configure --prefix=/usr/local/rrdtool ; make ; make install
2)安装PNP
[root@localhost rrdtool-1.4.5]# cd /aaa/
[root@localhost aaa]# tar zxf pnp-0.4.13.tar.gz
[root@localhost aaa]# cd pnp-0.4.13
[root@localhost pnp-0.4.13]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-rrdtool=/usr/local/rrdtool/bin/rrdtool --with-perfdata-di
r=/usr/local/nagios/share/perfdata ; make all ; make install ; make install-config ; make install-init
3) 配置PNP
A,创建默认配置文件
[root@localhost pnp-0.4.13]# cd /usr/local/nagios/etc/pnp/
[root@localhost pnp]# cp process_perfdata.cfg-sample process_perfdata.cfg
[root@localhost pnp]# cp npcd.cfg-sample npcd.cfg
[root@localhost pnp]# cp rra.cfg-sample rra.cfg
[root@localhost pnp]# chown -R nagios:nagios /usr/local/nagios/etc/pnp/
B,修改process_perfdata.cfg
[root@localhost pnp]# vi /usr/local/nagios/etc/pnp/process_perfdata.cfg
4) 修改Nagios主配置文件
A,增加小太阳图标
[root@localhost pnp]# cd /usr/local/nagios/etc/
[root@localhost etc]# vi templates.cfg
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
}
B、修改nagios.cfg
找到如下几行去掉注释
[root@localhost etc]# vi nagios.cfg
833 process_performance_data=1
845 host_perfdata_command=process-host-perfdata
846 service_perfdata_command=process-service-perfdata
C、修改commands.cfg(注释掉原来的command_line原有的配置,更改成下面的配置)
227 # 'process-host-perfdata' command definition
228 define command{
229 command_name process-host-perfdata
230 command_line /usr/local/nagios/libexec/process_perfdata.pl
231 }
232
233
234 # 'process-service-perfdata' command definition
235 define command{
236 command_name process-service-perfdata
237 command_line /usr/local/nagios/libexec/process_perfdata.pl
238 }
D、修改hosts.cfg文件和services.cfg文件
[root@localhost ~]# vi /usr/local/nagios/etc/hosts.cfg(在use这行后面增加hosts-pnp)
define host{
use linux-server,hosts-pnp
host_name web
alias benet-web
address 192.168.6.199
}
define host{
use linux-server,hosts-pnp
host_name mysql
alias benet-mysql
address 192.168.6.200
}
define hostgroup{
hostgroup_name sa-servers
alias sa servers
members web,mysql
}
[root@localhost ~]# vi /usr/local/nagios/etc/services.cfg(在use这行后面增加service-pnp)
################- benet web -##########################
define service{
use local-service,services-pnp
host_name web
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
define service{
use local-service,services-pnp
host_name web
service_description SSH
check_command check_ssh
}
注意项:别心急看小太阳数据,等会儿就有了。
点击小太阳,出现对主机或服务的监控页面
点击小太阳后如果出现下面的错误:
Initalising
Using /usr/local/nagios/share/perfdata/
RRDTool /usr/local/rrdtool/bin/rrdtool found.
RRDTool /usr/local/rrdtool/bin/rrdtool is executable
PHP Function proc_open is enabled
PHP Function fpassthru is enabled
PHP Function xml_parser_create is enabled
PHP zlib Support found.
PHP GD Support not found.
|
这说明你没有安装php-gd这个包,请利用yum –y install php-gd来安装此包,然后重新启动一下httpd服务和nagios服务,此问题就可以解决。