Icinga Installation
系统环境
OS: debian 5.0.8
Linux debian 2.6.26-2-amd64 #1 SMP Mon Sep 19 06:13:12 UTC 2011 x86_64 GNU/Linux
Icinga工作框架
说明:由于icinga是在nagios基础上延伸而来,是介于Nagios社区版和企业版间的产品,以下图也适用于Icinga 。
Prerequisites:
Apache
GCC compiler
C/C++ development libraries
GD development libraries
libdbi/libdbi-drivers, database like MySQL or PostgreSQL
安装步骤:(注意icinga和mysql数据库位于同一台机器上)
1.安装apache,gd开发库文件和gcc编译环境
debian:~#apt-get install apache2 build-essential libgd2-xpm-dev
2. 安装MySQL数据库
debian:~#apt-get install mysql-server mysql-client libdbi0 libdbi0-dev libdbd-mysql
3. 创建用户和组
debian:~# useradd -m icinga
debian:~# groupadd icinga-cmd
debian:~# usermod -a -G icinga-cmd icinga
修改apache启动用户为icinga ,并重启apache。
debian:/etc/apache2# vim envvars
export APACHE_RUN_USER=icinga
export APACHE_RUN_GROUP=icinga
debian:~# /etc/init.d/apache2 restart
4.从http://sourceforge.jp/projects/sfnet_icinga-cn/releases/下载汉化版icinga软件包进行编译安装。
debian:~#./configure --with-command-group=icinga-cmd --with-web-user=icinga --with-web-group=icinga --enable-idoutils
………………………
………………………
*** Configuration summary for icinga-core 1.5.1 09-09-2011 ***:
General Options:
-------------------------
Icinga executable: icinga
Icinga user/group: icinga,icinga
Command user/group: icinga,icinga-cmd
Apache user/group: icinga,icinga
Embedded Perl: no
Event Broker: yes
Build IDOUtils: libdbi, instance_name=default
Install ${prefix}: /usr/local/icinga
Lock file: ${prefix}/var/icinga.lock
Log directory: ${prefix}/var
cgi log directory: ${prefix}/share/log
phpapi log directory: ${prefix}/share/icinga-api/log
Check result directory: ${prefix}/var/spool/checkresults
Ext Cmd file directory: ${prefix}/var/rw
Init directory: /etc/init.d
Apache conf.d directory: /etc/apache2/conf.d
Mail program: /usr/bin/mail
Host OS: linux-gnu
Web Interface Options:
------------------------
HTML URL: http://localhost/icinga/
CGI URL: http://localhost/icinga/cgi-bin/
Traceroute (used by WAP): /usr/sbin/traceroute
Review the options above for accuracy. If they look okay,
type 'make all' to compile the main program and CGIs.
!!! Please take care about the upgrade documentation !!!
debian:~ #make all
debian:~ #make install
debian:~ #make install-init
debian:~ #make install-config
debian:~ #make install-commandmode
debian:~ #make install-idoutils
启用idomod event broker 模块
debian:/usr/local/icinga/etc/modules#cp idoutils.cfg-sample idoutils.cfg
5. 配置mysql数据库
5.1创建icinga数据库并给予权限
debian:~# mysql -u root -p
mysql> create database icinga;
Query OK, 1 row affected (0.00 sec)
mysql> grant usage on *.* to 'icinga'@'localhost' identified by 'icinga' with MAX_QUERIES_PER_HOUR 0
-> MAX_CONNECTIONS_PER_HOUR 0
-> MAX_UPDATES_PER_HOUR 0;
Query OK, 0 rows affected (0.00 sec)
mysql> grant select,insert,update,delete,drop,create view on icinga.* to 'icinga'@'localhost';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
5.2创建icinga表
mysql -u root -D icinga < icinga-cn-1.5.1/module/idoutils/db/mysql/mysql.sql
debian:~# mysql -u icinga -p icinga
mysql> use icinga;
mysql> show tables;
+----------------------------------------+
| Tables_in_icinga |
+----------------------------------------+
| icinga_acknowledgements |
| icinga_commands |
| ………………………… |
| |
+----------------------------------------+
5.3编辑IDOUtils DB配置文件,确保含有如下内容:
debian:~# vim /usr/local/icinga/etc/ido2db.cfg
db_servertype=mysql
db_port=3306
db_user=icinga
db_pass=icinga
6. 配置icinga传统web界面(注:新的icinga web界面配置将在后面介绍)
debian:~/icinga/icinga-cn-1.5.1# make cgis
debian:~/icinga/icinga-cn-1.5.1# make install-cgis
debian:~/icinga/icinga-cn-1.5.1# make install-html
debian:~/icinga/icinga-cn-1.5.1# make install-webconf
这里创建web访问账号icingaadmin:
debian:~ #htpasswd -c /usr/local/icinga/etc/htpasswd.users icingaadmin
重启apache生效
debian:~ # /etc/init.d/apache2 reload
7. 编译安装nagios插件
从http://sourceforge.net/projects/nagiosplug/files/下载最新的nagios插件包进行安装。
debian:~/icinga/nagios-plugins-1.4.15#./configure --prefix=/usr/local/icinga \
> --with-cgiurl=/icinga/cgi-bin --with-htmurl=/icinga \
> --with-nagios-user=icinga --with-nagios-group=icinga
debian:~/icinga/nagios-plugins-1.4.15# make && make install
注:在编译过程中,可能会提示缺少包,导致某些功能无法使用,如snmp等,根据提示将相应的包安装后,再重新编译安装。
debian:~/icinga/nagios-plugins-1.4.15##apt-get install snmp libsnmp-dev
8.启动IDOUtils和Icinga
注意:IDOUtils必须先启动
debian:~# /etc/init.d/ido2db start
在启动icinga之前,使用如下命令对配置文件进行检查以确保无误;
debian:~#/usr/local/icinga/bin/icinga -v /usr/local/icinga/etc/icinga.cfg
debian:~ # /etc/init.d/icinga start
9. icinga基础安装已经完成,可访问http://yourip/icinga/
10. 安装PNP4Nagios附件组件,支持性能数据绘图功能
安装pnp4nagios之前,环境需要满足以下条件:
· Perl >= 5.x
· RRDtool >= 1.x, better 1.2 but not compulsory
Attention: installing RRDtool without a packet manager might lead to missing dejavu fonts. If you see graphs without text then this may be the cause.
· Nagios >= 2.x or Icinga
· Php
10.1安装rrdtool和php
debian:~/icinga# apt-get install rrdtool php5 php5-gd
从http://sourceforge.net/projects/pnp4nagios/files/下载最新的pnp4nagios软件包进行编译安装。
安装rrd 的perl模块
debian:~/icinga/pnp4nagios-0.6.16# apt-get install librrds-perl
debian:~/pnp4nagios-0.6.16#./configure --with-nagios-user=icinga --with-nagios-group=icinga
debian:~/icinga/pnp4nagios-0.6.16# make all && make fullinstall
10.2 启用icinga数据采集和绘图功能
debian:/usr/local/icinga/etc# vim icinga.cfg
process_performance_data=1
host_perfdata_file=/usr/local/pnp4nagios/var/host-perfdata
service_perfdata_file=/usr/local/pnp4nagios/var/service-perfdata
host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$
service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$
host_perfdata_file_mode=a
service_perfdata_file_mode=a
host_perfdata_file_processing_interval=15
service_perfdata_file_processing_interval=15
host_perfdata_file_processing_command=process-host-perfdata-file
service_perfdata_file_processing_command=process-service-perfdata-file
以上内容均可从/usr/local/pnp4nagios/etc/nagios.cfg-sample文件中Bulk / NPCD mode部分获取。
注释:
process_performance_data设置为1,表示启用性能数据采集;
service_perfdata_file分别表示存放服务性能的临时数据文件;
service_perfdata_file_processing_interval处理性能文件时间间隔;
service_perfdata_file_processing_command处理性能文件调用的命令;
debian:/usr/local/icinga/etc# vim objects/commands.cfg
在该文件中注释掉icinga默认的处理性能文件命令,新增“process-host-perfdata-file” 和“process-service-perfdata-file”指令,如下图所示:
重启icinga,让配置生效,注意重启服务之前,使用命令检查一下是否有错误。
10.3 配置pnp4nagios的数据采集模式
这里选择采用推荐的“Bulk + NPCD mode”模式进行性能数据采集绘图,其工作原理及流程如下图所示:
查看npcd.cfg文件,确认如下内容是否正确
debian:~# less /usr/local/pnp4nagios/etc/npcd.cfg
perfdata_spool_dir = /usr/local/pnp4nagios/var/spool/
perfdata_file_run_cmd = /usr/local/pnp4nagios/libexec/process_perfdata.pl
启动NPCD服务
debian:~#/usr/local/pnp4nagios/bin/npcd -d -f /usr/local/pnp4nagios/etc/npcd.cfg
10.4验证pnp4nagios安装
访问http://yourip/pnp4nagios, 出现500错误,查看apache日志,显示:
[Thu Jan 19 10:13:45 2012] [error] [client 192.168.22.240] (2)No such file or directory: Could not open password file: /usr/local/nagios/etc/htpasswd.users
这里显示为/usr/local/nagios/etc/htpasswd.users未找到,由于安装的是icinga,需要把nagios修改成icinga,重启apache即可。打开页面,显示所有测试项通过即可。
页面提示测试通过后,需要将/usr/local/pnp4nagios/share/install.php文件移走。
# mv /usr/local/pnp4nagios/share/install.php /usr/local/pnp4nagios/share/install.php_bakup
下载verify_pnp_config脚本进行配置验证
#wget http://verify.pnp4nagios.org/verify_pnp_config
执行脚本,如果没有“[CRIT]”,则表示配置正常;
debian:~# ./verify_pnp_config --mode bulk+npcd --config=/usr/local/icinga/etc/icinga.cfg --pnpcfg=/usr/local/pnp4nagios/etc
[INFO] ========== Starting Environment Checks ============
[INFO] My version is: verify_pnp_config-0.6.16-R.31
[INFO] Reading /usr/local/icinga/etc/icinga.cfg
[OK ] Running product is 'icinga'
[OK ] object_cache_file is defined
[OK ] object_cache_file=/usr/local/icinga/var/objects.cache
[INFO] Reading /usr/local/icinga/var/objects.cache
[OK ] resource_file is defined
[OK ] resource_file=/usr/local/icinga/etc/resource.cfg
[INFO] Reading /usr/local/icinga/etc/resource.cfg
[INFO] Reading /usr/local/pnp4nagios/etc/process_perfdata.cfg
[INFO] Reading /usr/local/pnp4nagios/etc/pnp4nagios_release
[OK ] Found PNP4Nagios version "0.6.16"
[OK ] Effective User is 'icinga'
[OK ] User icinga exists with ID '1001'
[OK ] Effective group is 'icinga'
[OK ] Group icinga exists with ID '1001'
[INFO] ========== Checking Bulk Mode + NPCD Config ============
[OK ] process_performance_data is 1 compared with '/1/'
[OK ] service_perfdata_file is defined
[OK ] service_perfdata_file=/usr/local/pnp4nagios/var/service-perfdata
[OK ] service_perfdata_file_template is defined
[OK ] service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$
[OK ] PERFDATA template looks good
[OK ] service_perfdata_file_mode is defined
[OK ] service_perfdata_file_mode=a
[OK ] service_perfdata_file_processing_interval is defined
[OK ] service_perfdata_file_processing_interval=15
[OK ] service_perfdata_file_processing_command is defined
[OK ] service_perfdata_file_processing_command=process-service-perfdata-file
[OK ] host_perfdata_file is defined
[OK ] host_perfdata_file=/usr/local/pnp4nagios/var/host-perfdata
[OK ] host_perfdata_file_template is defined
[OK ] host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$
[OK ] PERFDATA template looks good
[OK ] host_perfdata_file_mode is defined
[OK ] host_perfdata_file_mode=a
[OK ] host_perfdata_file_processing_interval is defined
[OK ] host_perfdata_file_processing_interval=15
[OK ] host_perfdata_file_processing_command is defined
[OK ] host_perfdata_file_processing_command=process-host-perfdata-file
[INFO] Icinga config looks good so far
[INFO] ========== Checking config values ============
[OK ] npcd daemon is running
[OK ] /usr/local/pnp4nagios/etc/npcd.cfg is used by npcd and readable
[INFO] Reading /usr/local/pnp4nagios/etc/npcd.cfg
[OK ] perfdata_spool_dir is defined
[OK ] perfdata_spool_dir=/usr/local/pnp4nagios/var/spool/
[OK ] Command process-service-perfdata-file is defined
[OK ] '/bin/mv /usr/local/pnp4nagios/var/service-perfdata /usr/local/pnp4nagios/var/spool/service-perfdata.$TIMET$'
[OK ] Command looks good
[OK ] Command process-host-perfdata-file is defined
[OK ] '/bin/mv /usr/local/pnp4nagios/var/host-perfdata /usr/local/pnp4nagios/var/spool/host-perfdata.$TIMET$'
[OK ] Command looks good
[OK ] Script /usr/local/pnp4nagios/libexec/process_perfdata.pl is executable
[INFO] ========== Starting global checks ============
[OK ] status_file is defined
[OK ] status_file=/usr/local/icinga/var/status.dat
[INFO] Reading /usr/local/icinga/var/status.dat
[INFO] ==== Starting rrdtool checks ====
[OK ] RRDTOOL is defined
[OK ] RRDTOOL=/usr/bin/rrdtool
[OK ] /usr/bin/rrdtool is executable
[OK ] RRDtool 1.4.3 Copyright 1997-2009 by Tobias Oetiker <[email protected]>
[OK ] USE_RRDs is defined
[OK ] USE_RRDs=1
[OK ] Perl RRDs modules are loadable
[INFO] ==== Starting directory checks ====
[OK ] RRDPATH is defined
[OK ] RRDPATH=/usr/local/pnp4nagios/var/perfdata
[OK ] Perfdata directory '/usr/local/pnp4nagios/var/perfdata' exists
[WARN] 14 hosts/services are not providing performance data
[WARN] 'process_perf_data 1' is set for 15 hosts/services which are not providing performance data!
[OK ] 'process_perf_data 1' is set for 24 of your hosts/services
[INFO] ==== System sizing ====
[OK ] 23 hosts/service objects defined
[INFO] ==== Check statistics ====
[WARN] Warning: 2, Critical: 0
[WARN] Checks finished...
10.5 将pnp4nagios图标显示于icinga web前端
在/usr/local/icinga/etc/objects目录下面新建文件pnp4nagios.cfg,其内容如下:
debian:/usr/local/icinga/etc/objects# cat pnp4nagios.cfg
define host{
name host-pnp ; The name of this host template
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_' class='tips' rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=_HOST_
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
}
define service{
name srv-pnp ; The 'name' of this service template
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$' class='tips' rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=$SERVICEDESC$
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
}
编辑模板文件templates.cfg,分别在主机和服务模板下面新增如下一行(红色标注)。
debian:/usr/local/icinga/etc/objects# vim templates.cfg
define host{
name generic-host ; The name of this host template
use host-pnp
notifications_enabled 1 ; Host notifications are enabled
………………………………
}
define service{
name generic-service ; The 'name' of this service template
use srv-pnp
active_checks_enabled 1 ; Active service checks are enabled
passive_checks_enabled 1 ; Passive service checks are enabled/accepted
……………………………
}
注:增加上述指令后,icinga所有主机和服务都会自动在icinga监视页面出现pnp4nagios的图标。
在icinga主配置文件icinga.cfg,新增如下行即可
cfg_file=/usr/local/icinga/etc/objects/pnp4nagios.cfg
回到解压目录下,复制鼠标悬停图标显示,预览绘图所需的文件 status-header.ssi,并确保该文件无可执行权限。
#cp ./pnp4nagios-0.6.16/contrib/ssi/status-header.ssi /usr/local/icinga/share/ssi/
拷贝pnp4nagios web页面配置文件config.php并修改该文件如下几处
debian:/usr/local/pnp4nagios/etc# vim config_local.php
$conf['nagios_base'] = "/icinga/cgi-bin";
debian:/usr/local/pnp4nagios/etc# cp config_local.php config.php
重启icinga服务,查看web页面(重启之前,确认配置无误),页面已经显示图标,点击查看,相关数据绘图已经展示(如图),且支持鼠标悬停显示。
提示:可以在/usr/local/pnp4nagios/etc/config_local.php文件设置rrd绘画像素以及显示图像大小等。
11. 利用RRDtool Cache Deamon
rrdttool在处理大量的rrd文件时,会造成系统相对较高的I/O负载,利用rrdcaced,可以缓解对大量rrd文件多次随机写入的问题,它会缓存这些写入,批量进行更新,来减少disk I/O。注意检查RRDtool版本是否支持该特性。
安装rrdcached
# apt-get install rrdcached
修改rrdcached启动脚本
debian:/etc/init.d# vim rrdcached
OPTS="-m 777 -s icinga -l unix:/tmp/rrdcached.sock "
OPTS="$OPTS -j /tmp -F"
#OPTS="$OPTS -b /var/lib/rrdcached/db/ -B"
启动rrdcached服务
#debian:~# /etc/init.d/rrdcached restart
# rrdcached -w 1800 -z 1800 -p /tmp/rrdcached.pid -j /tmp -s icinga –F -m 777 -l unix:/tmp/rrdcached.sock
这里使用”-m 777”表示将/tmp/rrdcached.sock的权限设置为777,防止出现” ERROR Unable to connect to rrdcached: Permission denied”。
接下来设置pnp4nagios ,支持rrdcached 。
分别修改文件config_local.php 和 process_perfdata.cfg
debian:/usr/local/pnp4nagios/etc# vim config_local.php
# rrdcached support
# Use only with rrdtool svn revision 1511+
#
$conf['RRD_DAEMON_OPTS'] = 'unix:/tmp/rrdcached.sock';
debian:/usr/local/pnp4nagios/etc# vim process_perfdata.cfg
#
# Use only with rrdtool svn revision 1511+
#
RRD_DAEMON_OPTS = unix:/tmp/rrdcached.sock
注意这里sock路径和启动rrdcached服务的sock保持一致。
验证:
1>打开监控页面,数据绘图正常;
2>查看日志文件/usr/local/pnp4nagios/var/ perfdata.log, 无错误信息;
附:
libdbi:
http://libdbi.sourceforge.net/download.html
GD 库文件:
http://www.boutell.com/gd/
PNP4Nagios
http://docs.pnp4nagios.org
Install NagiosQL
NagiosQL是一个基于Web方式的Nagios配置管理工具,它使用PHP语 言开发,可运行在Apache下,后台使用Mysql数据库。同时,NagiosQL也是一个开源软件。
如果你使用过Nagios,那么你一定感知到了它 的强大监控功能,以及它的可扩展性。然而,它的监控配置信息都存放于文件中,配置和修改都需要手工编辑文件,这样十分不便,尤其当监控的内容增多时,问题就更加明显。NagiosQL就是一款解决此类问题的软件,它提供了可视化的配置环境(基于web方式)。
NagiosQL的原理图如下
从图中不难看出NagiosQL的主要作用就是操作数据库和配置文件,其中包括将配置文件的信息写到数据库中,在数据库中修改Nagios的监控配置信息,并将数据库中存放的配置更新到文件中。用户可以通过NagiosQL提供的Web页面直观的修改配置。
安装部署:
Requirements
Webserver e.g. Apache 1.x or above
PHP 4.3 or above
MySQL 4.1 or above
Nagios 2 or above
PEAR Module: HTML_Template_IT 1.1 or above
PHP Extension: gettext
PHP Extension: mysql
PHP Extension: ftp
Javascript enabled at your Webbrowser
环境说明
Icinga根目录:/usr/local/icinga
Icinga配置文件目录:/usr/local/icinga/etc
Icinga的用户和用户组:icinga|icinga
Apached启动用户和用户组: icinga|icinga
1. 安装php扩展模块
debian:~# apt-get install php-pear php5-gd php5-curl php5-mysql php-gettext
2. 安装HTML_Template_IT
debian:~# pear install HTML_Template_IT
3. 从www.nagiosql.org 下载nagiosql最新源码包,并解压到某个目录下面,这里指定为/usr/local/icinga/nagiosql
4. 修改属主及权限
debian:~#chown -R icinga:icinga /usr/local/icinga/nagiosql
修改config目录的访问权限,以使apache对其具有写权限
root@icinga:/usr/local/icinga/nagiosql# chmod -R 777 config/
5. 创建nagiosql配置文件存放目录,并修改权限
debian:~#cd /usr/local/icinga/nagiosql
debian:/usr/local/icinga/nagiosql# mkdir -p etc/{hosts,services,backup}
debian:/usr/local/icinga/nagiosql# mkdir -p etc/backup/{hosts,services}
debian:/usr/local/icinga/nagiosql# mkdir -p etc/import
debian:/usr/local/icinga/nagiosql# chown -R icinga:icinga etc
说明:
/usr/local/icinga/nagiosql/etc -> Common configuration files
/usr/local/icinga/nagiosql/etc/hosts -> Host configuration files
/usr/local/icinga/nagiosql/etc/service -> Service configuration files
/usr/local/icinga/nagiosql/etc/backup/ -> Backups of the common configuration files
/usr/local/icinga/nagiosql/etc/backup/hosts -> Backups of the host configuration files
/usr/local/icinga/nagiosql/etc/backup/services -> Backups of the service configuration files
6. 修改apache的httpd.conf文件,重启apache服务
debian:/etc/apache2/conf.d# vim nagiosql.conf
# SAMPLE CONFIG SNIPPETS FOR APACHE WEB SERVER
Alias /nagiosql "/usr/local/icinga/nagiosql"
<Directory "/usr/local/icinga/nagiosql">
AllowOverride None
Order allow,deny
Allow from all
</Directory>
7. 通过浏览器进入如下地址http://<IP>/nagiosql,其中IP是apache服务主机的IP地址。
按照界面上的提示进行安装即可,最后删除install目录,完成配置。以下图为登录页面。
8. 进入NagiosQL,首先要基础配置,设置配置文件的位置,进入Administration -> Domains,编辑localhost。如下图所示:
9. 修改icinga.cfg文件(红色部分为新增),对配置文件检查并重启icinga服务。
debian:/usr/local/icinga/etc# vim icinga.cfg
# You can specify individual object config files as shown below:
#cfg_file=/usr/local/icinga/etc/objects/pnp4nagios.cfg
#cfg_file=/usr/local/icinga/etc/objects/commands.cfg
#cfg_file=/usr/local/icinga/etc/objects/contacts.cfg
#cfg_file=/usr/local/icinga/etc/objects/timeperiods.cfg
#cfg_file=/usr/local/icinga/etc/objects/templates.cfg
# Definitions for monitoring the local (Linux) host
#cfg_file=/usr/local/icinga/etc/objects/localhost.cfg
# Definitions for monitoring the Linux host
#cfg_file=/usr/local/icinga/etc/objects/linux.cfg
# Definitions for monitoring a Windows machine
#cfg_file=/usr/local/icinga/etc/objects/windows.cfg
# Definitions for monitoring a router/switch
#cfg_file=/usr/local/icinga/etc/objects/switch.cfg
# Definitions for monitoring a network printer
#cfg_file=/usr/local/icinga/etc/objects/printer.cfg
cfg_file=/usr/local/icinga/nagiosql/etc/contacttemplates.cfg
cfg_file=/usr/local/icinga/nagiosql/etc/contactgroups.cfg
cfg_file=/usr/local/icinga/nagiosql/etc/contacts.cfg
cfg_file=/usr/local/icinga/nagiosql/etc/timeperiods.cfg
cfg_file=/usr/local/icinga/nagiosql/etc/commands.cfg
cfg_file=/usr/local/icinga/nagiosql/etc/hostgroups.cfg
cfg_file=/usr/local/icinga/nagiosql/etc/servicegroups.cfg
cfg_dir=/usr/local/icinga/nagiosql/etc/hosts
cfg_dir=/usr/local/icinga/nagiosql/etc/services
cfg_file=/usr/local/icinga/nagiosql/etc/hosttemplates.cfg
cfg_file=/usr/local/icinga/nagiosql/etc/servicetemplates.cfg
cfg_file=/usr/local/icinga/nagiosql/etc/servicedependencies.cfg
cfg_file=/usr/local/icinga/nagiosql/etc/serviceescalations.cfg
cfg_file=/usr/local/icinga/nagiosql/etc/hostdependencies.cfg
cfg_file=/usr/local/icinga/nagiosql/etc/hostescalations.cfg
cfg_file=/usr/local/icinga/nagiosql/etc/hostextinfo.cfg
cfg_file=/usr/local/icinga/nagiosql/etc/serviceextinfo.cfg
# You can also tell Icinga to process all config files (with a .cfg
# extension) in a particular directory by using the cfg_dir
# directive as shown below:
#cfg_dir=/usr/local/icinga/etc/servers
#cfg_dir=/usr/local/icinga/etc/printers
#cfg_dir=/usr/local/icinga/etc/switches
#cfg_dir=/usr/local/icinga/etc/routers
# Definitions for broker modules like idoutils.cfg
cfg_dir=/usr/local/icinga/etc/modules
10. 配置好路径后,将Icinga的配置文件导入到数据库中,Tools -> Data import,选择文件Import。在Supervision -> Hosts下可看到刚导入的配置,可进行编辑并写回文件文件中。
附:
NagiosQL:
http://www.nagiosql.org/
Install Icinga-Web
1. 安装php扩展模块,其它php模块如php-gd,php-pear,php5,php5-mysql等已经安装;
debian:~# apt-get install php5-xmlrpc php5-xsl php5-ldap phpunit phpunit2
debian:~# pear install PHP_CodeSniffer
2. 从http://sourceforge.jp/projects/sfnet_icinga-cn/releases/下载汉化版icinga-cn-web-1.5.2.tar.bz2进行编译安装;
debian:~/icinga-cn-web-1.5.2# ./configure --prefix=/usr/local/icinga-web --with-web-user=icinga --with-web-group=icinga
debian:~/icinga-cn-web-1.5.2# make install
debian:~/icinga-cn-web-1.5.2# make install-apache-config
3. 测试php模块依赖性;
debian:~/icinga-cn-web-1.5.2# make testdeps
/usr/bin/php bin/testdeps.php
Icinga-web dependencies (running 23 test)
PHP (core) tests
1/23 Test php version >= 5.2.3 (REQUIRED) ... (version 5.2.6-1+lenny13 >= 5.2.3) OK
2/23 Test for PEAR (REQUIRED) ... OK
PHP extensions
3/23 Test php5-xsl (REQUIRED) ... (xsl found v0.1) OK
4/23 Test php5-ldap ... (ldap found) OK
5/23 Test php5-pdo (REQUIRED) ... (PDO found v1.0.4dev) OK
6/23 Test php5-dom (REQUIRED) ... (dom found v20031129) OK
7/23 Test php5-session (REQUIRED) ... (session found) OK
8/23 Test php5-spl (REQUIRED) ... (SPL found v0.2) OK
9/23 Test php5-pcre (REQUIRED) ... (pcre found) OK
10/23 Test php5-tokenizer (REQUIRED) ... (tokenizer found v0.1) OK
11/23 Test php5-libxml (REQUIRED) ... (libxml found) OK
12/23 Test php5-reflection (REQUIRED) ... (Reflection found v0.1) OK
13/23 Test php5-gettext (REQUIRED) ... (gettext found) OK
Optional pdo drivers
14/23 Test php5-pdo-mysql ... (pdo_mysql found v1.0.2) OK
15/23 Test php5-pdo-pgsql ... (Extension pdo_pgsql does not exist) FAIL
Optional php extension
16/23 Test php5-soap ... (soap found) OK
17/23 Test php5-xmlrpc ... (xmlrpc found v0.51) OK
18/23 Test php5-iconv ... (iconv found) OK
19/23 Test php5-gd ... (gd found) OK
20/23 Test php5-ctype ... (ctype found) OK
21/23 Test php5-json ... (json found v1.2.1) OK
22/23 Test php5-hash ... (hash found v1.0) OK
23/23 Test php.ini memory_limit ... (memory_limit='33554432') OK
All over result: PASS (required 12/12, optional 10/11, all 22/23, time 0.04s)
Exit (status=0)
4. 创建相应的数据库用户和DB,并初始化;
Icinga-Web 将会创建自己的数据库,默认为icinga_web;
mysql> GRANT USAGE ON *.* TO 'icinga_web'@'localhost' IDENTIFIED BY 'icinga_web';
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, INDEX ON icinga_web.* TO 'icinga_web'@'localhost';
Query OK, 0 rows affected (0.01 sec)
mysql> CREATE DATABASE icinga_web;
Query OK, 1 row affected (0.00 sec)
mysql> GRANT USAGE ON *.* TO 'icinga_web'@'localhost' IDENTIFIED BY 'icinga_web' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0;
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, INDEX ON icinga_web.* TO 'icinga_web'@'localhost';
Query OK, 0 rows affected (0.00 sec)
debian:~/icinga-cn-web-1.5.2# make db-initialize
5. 配置Icinga-web;
说明:Icinga-web将会首先读取位于/usr/local/icinga-web/etc/conf.d/ databases.xml 的数据库配置文件,升级时改文件不会被覆盖,这样避免丢失以前的配置。Icinga new web将会使用icinga-web数据库,这里有另一个icinga数据库,是供ido2db使用;以下两个文件保持默认即可;
debian:/usr/local/icinga-web# grep mysql app/config/databases.xml
<ae:parameter name="dsn">mysql://icinga_web:icinga_web@localhost:3306/icinga_web</ae:parameter>
<ae:parameter name="dsn">mysql://icinga:icinga@localhost:3306/icinga</ae:parameter>
文件access.xml 定义icinga命令路径等;
debian:/usr/local/icinga-web/etc/conf.d# grep icinga access.xml
<resource name="icinga_objects">/usr/local/icinga/etc/objects</resource>
<resource name="icinga_cfg">/usr/local/icinga/etc/icinga.cfg</resource>
<resource name="icinga_pipe">/usr/local/icinga/var/rw/icinga.cmd</resource>
<resource name="icinga_service">/etc/init.d/icinga</resource>
<resource name="icinga_bin">/usr/local/icinga/bin/icinga</resource>
注意:修改以上文件后,需要清除配置缓存。
debian:~# /usr/local/icinga-web/bin/clearcache.sh
5. 配置apache;
启用mod_rewrite
debian:~# a2enmod rewrite
验证:
debian:~# ls -ltr /etc/apache2/mods-enabled/rewrite.load
lrwxrwxrwx 1 root root 30 01-23 17:12 /etc/apache2/mods-enabled/rewrite.load -> ../mods-available/rewrite.load
切换到目录/usr/local/icinga-web/pub,修改.htaccess文件,调整RewriteBase指令所指向的目录,这里默认为/icinga-web/;
debian:/usr/local/icinga-web/pub# grep RewriteBase .htaccess
RewriteBase /icinga-web
检查由make install-apache-config命令生成的/etc/apache2/conf.d/icinga-web.conf 配置是否正确;
最后清除缓存并重启apache服务。
debian:~# /usr/local/icinga-web/bin/clearcache.sh
debian:~# /etc/init.d/apache2 restart
使用浏览器访问http://yourip/icinga-web/ ,初始用户和密码分别为root/password;
6. 将PNP4Nagios整合到Icinga-Web;
首先需要安装PNP4Nagios,关于PNP4Nagios安装,见前面描述。Pnp4naigos被安装在/usr/local/pnp4nagios/目录下。
修改配置文件config.php
debian:/usr/local/pnp4nagios/etc# vim config.php
$conf['nagios_base'] = "/icinga/cgi-bin";
拷贝pnp4nagios 主机和服务模板xml文件(适用于icinga-web version 1.5及以上版本)
debian:~/icinga-cn-web-1.5.2/contrib/PNP_Integration#cp templateExtensions/pnp-host-extension.xml /usr/local/icinga-web/app/modules/Cronks/data/xml/extensions
debian:~/icinga-cn-web-1.5.2/contrib/PNP_Integration# cp templateExtensions/pnp-service-extension.xml /usr/local/icinga-web/app/modules/Cronks/data/xml/extensions
最后清除缓存。
debian:~# /usr/local/icinga-web/bin/clearcache.sh
刷新页面后,性能绘图图标出现: