1、前言
nagios是一款常用的监控软件,与此同时,nagios默认却不支持图形化功能,这对于运维管理人员来说有时候真的是非常不便的。幸好,nagios还可以通过安装nagiosgraph插件来实现图形化显示,下面我们就来看看如何安装实现nagios的图形化。
nagios的安装监控可参考:https://www.jianshu.com/p/bc04a9980edc
2、下载nagiosgraph插件
https://sourceforge.net/projects/nagiosgraph/
[root@nagios ~]# cd /usr/local/src/
[root@nagios src]# tar zxf nagiosgraph-1.5.2.tar.gz
[root@nagios src]# cd nagiosgraph-1.5.2
[root@nagios nagiosgraph-1.5.2]# ./install.pl --install
checking required PERL modules
Carp...1.11
CGI... ***FAIL***
Data::Dumper...2.124
Digest::MD5...2.39
File::Basename...2.77
File::Find...1.14
MIME::Base64...3.08
POSIX...1.17
RRDs... ***FAIL***
Time::HiRes... ***FAIL***
checking optional PERL modules
GD... ***FAIL***
Nagios::Config... ***FAIL***
........
3、修复报错
按照步骤2中出现的FAIL提示,修复安装的依赖关系
[root@nagios nagiosgraph-1.5.2]# yum install -y perl-CGI
[root@nagios nagiosgraph-1.5.2]# yum install perl-rrdtool -y
[root@nagios nagiosgraph-1.5.2]# yum install perl-GD -y
[root@nagios nagiosgraph-1.5.2]# yum install perl-Time-HiRes -y
最后一个Nagios::Config 的安装比较复杂,需要安装cpanm来进行安装。网上有很多解决方式,用cpanm安装的好处在于可以自动解决烦人的依赖关系。
[root@nagios nagiosgraph-1.5.2]# wget http://xrl.us/cpanm -O /usr/bin/cpanm; chmod +x /usr/bin/cpanm
[root@nagios nagiosgraph-1.5.2]# yum install perl-ExtUtils-MakeMaker -y
[root@nagios nagiosgraph-1.5.2]# cpanm Module::Build
[root@nagios nagiosgraph-1.5.2]# cpanm Nagios::Config
4、完成安装
按照上述步骤修复完成后,再次执行nagiosgraph的安装:
[root@nagios nagiosgraph-1.5.2]# ./install.pl --install
checking required PERL modules
Carp...1.11
CGI...3.51
Data::Dumper...2.124
Digest::MD5...2.39
File::Basename...2.77
File::Find...1.14
MIME::Base64...3.08
POSIX...1.17
RRDs...1.3008
Time::HiRes...1.9721
checking optional PERL modules
GD...2.44
Nagios::Config...36
checking nagios installation
found nagios exectuable at /usr/local/nagios/bin/nagios
found nagios init script at /etc/init.d/nagios
checking web server installation
found apache executable at /usr/sbin/httpd
found apache init script at /etc/init.d/httpd
...... #后续安装一路按回车键即可
5、编辑nagios.cfg文件
#在该文件中添加下述配置
[root@nagios ~]# cd /usr/local/nagios/etc/
[root@nagios etc]# vim nagios.cfg
# process nagios performance data using nagiosgraph
process_performance_data=1
service_perfdata_file=/tmp/perfdata.log
service_perfdata_file_template=$LASTSERVICECHECK$||$HOSTNAME$||$SERVICEDESC$||$SERVICEOUTPUT$||$SERVICEPERFDATA$
service_perfdata_file_mode=a
service_perfdata_file_processing_interval=30
service_perfdata_file_processing_command=process-service-perfdata-for-nagiosgraph
6、编辑commands.cfg文件
#添加下述配置段
[root@nagios etc]# cd /usr/local/nagios/etc/objects/
[root@nagios objects]# vim commands.cfg
define command {
command_name process-service-perfdata-for-nagiosgraph
command_line /usr/local/nagiosgraph/bin/insert.pl
}
7、编辑apache的httpd.conf文件
#添加下述配置段
[root@nagios objects]# cd /etc/httpd/conf/
[root@nagios conf]# vim httpd.conf
Include /usr/local/nagiosgraph/etc/nagiosgraph-apache.conf
8、验证nagiosgraph的配置信息
在浏览器输入网址:http://IP//nagiosgraph/cgi-bin/showconfig.cgi 进行查看
![](https://img.haomeiwen.com/i5294226/5f26f392698dd449.png)
9、修改模板文件,定义动作URL
[root@nagios conf]# cd /usr/local/nagios/etc/objects/
[root@nagios objects]# vim templates.cfg
define service {
name nagiosgraph
action_url /nagiosgraph/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$
register 0
}
10、修改服务配置文件
[root@nagios objects]# vim newlinux.cfg
define service{
use generic-service,nagiosgraph #在自定义的服务中调用此前定义的动作URL服务
host_name newlinux
service_description Load
check_command check_nrpe!check_load
}
11、重启httpd和nagios服务
[root@nagios conf]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@nagios conf]# service nagios restart
Running configuration check...
Stopping nagios: done.
Starting nagios: done.
每个主机的服务项在/usr/local/nagiosgraph/var/rrd 下都有对应的主机目录及rrd文件。
[root@nagios objects]# ll /usr/local/nagiosgraph/var/rrd/
localhost/ newlinux/
[root@nagios objects]# ll /usr/local/nagiosgraph/var/rrd/newlinux/
total 456
-rw-r--r--. 1 nagios nagios 94768 Sep 20 17:58 CHECK%20USER___users.rrd
-rw-r--r--. 1 nagios nagios 94768 Sep 20 17:53 Load___load15.rrd
-rw-r--r--. 1 nagios nagios 94768 Sep 20 17:53 Load___load1.rrd
-rw-r--r--. 1 nagios nagios 94768 Sep 20 17:53 Load___load5.rrd
-rw-r--r--. 1 nagios nagios 24184 Sep 20 17:52 Total%20procs___procs.rrd
-rw-r--r--. 1 nagios nagios 24184 Sep 20 17:53 Zombie___procs.rrd
-rw-r--r--. 1 nagios nagios 24184 Sep 20 17:53 Zombie___zombies.rrd
![](https://img.haomeiwen.com/i5294226/c3971b091c4b457e.png)
![](https://img.haomeiwen.com/i5294226/7b187fdffb6c5ebe.png)
网友评论