RHEL6+icinga-pnp4监控服务器搭建                                         

  

  

ICINGA官网:http://www.icinga.com

 ICINGA中文化与集成项目:http://icinga-cn.sourceforge.net/

  1. 1.       

YUM来安装所需要的软件包,搭建YUM服务器:

[root@mail~]# mount /dev/cdrom /mnt

在/etc/yum.repos.d目录下创建一个以.repo结尾的文件:

[root@mail~]# vi /etc/yum.repos.d/server1.repo

然后执行 rpm--import/etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release      ---导入gpgkey

p_w_picpath

  1. 2.      安装相关软件并创建icinga用户

Yum -y install freetype libjpeg libpng fontconfig libdbi  libdbi-devel gcc glibc glibc-common gdgd-devel libjpeg libjpeg-devel libpng libpng-devel net-snmp*  http* mysql*  php* rrdtool  rrdtool-perl  gd php-gd

注:以上有些软件包可能会在默认的RHEL中不存在,可以在http://pkgs.org中选择相应版本下载

[root@localhost  /]# useradd –s /sbin/noggin   icinga

  1. 3.      复制绘图文件RRD模块

yum install  perl-rrdtool

[root@localhost  /]# cd/usr/lib64/perl5/

# cp RRDs.pm/usr/lib64/perl5/5.10.0/x86_64-linux-thread-multi/

[root@localhost  /]# cd/usr/lib64/perl5/auto/RRDs/

# cp RRDs.so /usr/lib64/perl5/5.10.0/x86_64-linux-thread-multi/

32位系统文件在/usr/lib/perl5下

  1. 4.      下载ICINGA-PNP4和其它软件

 

Icinga-pnp4-cn:

http://nchc.dl.sourceforge.net/project/icinga-cn/icinga-pnp4nagios-cn/icinga-pnp4-cn-1.7.1.tar.xz

nrpe-icinga:

http://nchc.dl.sourceforge.net/project/icinga-cn/nrpe-icinga/nrpe-icinga-2.12.tar.bz2

nagios-plugins:

http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz

  1. 5.      安装软件:

由于软件是以.xz结尾的,所以要用xz来解压

spacer.gif

[root@localhost opt]#cd  icinga-pnp4-cn-1.7.1

[root@localhost icinga-pnp4-cn-1.7.1]# ./configure--prefix=/usr/local/icinga --with-rdbm --with-rdbm-incdir=/usr/include/rdbm/--with-rdbm-libdir=/usr/lib64/ --enable-idoutils--with-web-apache-path=/etc/httpd/conf.d/ --with-perl_lib_path=/usr/lib64/perl5/5.10.0/x86_64-linux-thread-multi--with-command-group=icinga --with-command-user=icinga

 

 

configure: error: Perl Module Time::HiRes not available

需要安装一个perl-Time-HiRes扩展包的支持,我们运行如下命令:

[root@localhost pnp4nagios-0.6.21]# yuminstall perl-Time-

 

spacer.gif

   #make all

   spacer.gif

  解决方法:

编辑cgi/status.c这个文件

  spacer.gif

  源码包出现一个小小的错误if 少了一i,我们把i添加上。Make clean后再使用make all

  spacer.gif

   #make install

#makeinstall-init  加入到服务中/etc/init.d/

#make install-api

#makeinstall-commandmode  生成icingaNaNd

#makeinstall-idoutils  默认已启用ido2db

#makeinstall-webconf  生成apache配置文件/etc/httpd/conf.d

#makeinstall-processperfdata  安装process_perfdata.pl

#makeinstall-plugins  安装pnp4相关工具

#makeinstall-config  生成配置文件

chkconfig --addicinga  mka

chkconfig icingaon

chkconfig httpd on

chkconfig mysqldon

  1. 6.      创建数据库并导入数据

mysql  –u  root

spacer.gif

导入数据时报错

spacer.gif

解决方法:vim module/idoutils/db/mysql/mysql.sql 删除4处“collate utf8_general_cs”重新导入

  1. 7.      安装nagios-plugins

[root@localhost opt]#tarzxvf nagios-plugins-1.4.15.tar.gz

[root@localhost opt]#cdnagios-plugins-1.4.15

[root@localhost 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

[root@localhost nagios-plugins-1.4.15] make

icinga支持check_snmp

spacer.gif

[root@localhost nagios-plugins-1.4.15] make install

  1. 8.      安装nrpe-icinga

   [root@localhost  opt]#tar jxvf  nrpe-icinga-2.12.tar.bz2

 

[root@localhost  opt]#cd nrpe-icinga-2.12

[root@localhost nrpe-icinga-2.12]#./configure--prefix=/usr/local/nrpe --with-nrpe-user=icinga --with-nrpe-group=icinga--with-nagios-user=icinga --with-nagios-group=icinga

[root@localhost nrpe-icinga-2.12]#make all

spacer.gif

解决方法:删除Makefile 868992行前面的空格,并用tab键对齐。同时在91suse后面加上“:”

[root@localhost nrpe-icinga-2.12]#make  install

[root@localhost nrpe-icinga-2.12]#make install-daemon-config

[root@localhost nrpe-icinga-2.12]#cp /usr/local/nrpe/libexec/check_nrpe/usr/local/icinga/libexec/

[root@localhost nrpe-icinga-2.12]#cp /usr/local/nrp/bin/nrpe  /usr/local/icinga/bin/ 

[root@localhost nrpe-icinga-2.12]#cp sample-config/nrpe.cfg  /usr/local/incinga/etc/

 [root@localhost  nrpe-icinga-2.12]# rm –rf /usr/local/nrpe

 

  1. 9.      设置icinga的访问密码

htpasswd  -c  /usr/local/icinga/etc/htpasswd.users   icingaadmin

输入两次密码

  1. 10.  测试文件

    /usr/local/icinga/bin/icinga -v/usr/local/icinga/etc/icinga.cfg

  1. 11.  启动服务

service  icinga start

service httpd start

service ido2db start

chkconfig  ido2db on

  1. 12.  访问icinga

spacer.gif

spacer.gif

 

 

spacer.gif

 

  1. 13.  测试PNP4

点击服务旁边spacer.gif

spacer.gif

根据提示对install.php进行改名,改完成刷新一下页面

spacer.gif

查看current load

spacer.gif

  1. 14.  使用sendemail发送报警邮件

下载 sendEmail-v1.56.tar.gz

[root@localhost  nrpe-icinga-2.12]#cd sendEmail-v1.56

[root@localhost  sendEmail-v1.56]# cp sendEmail /usr/local/bin

发送测试邮件:

/usr/local/bin/sendEmail–f luodi@cdld.com –t luodi@cdld.com –s mail.cdld.com–u “from icinga” –xu luodi –xp ldcdld123–m test mail

注:-t 表示接收者的邮箱
-s 表示SMTP服务器的域名或者ip
-u 表示邮件的主题
-xu 表示SMTP验证的用户名
-xp 表示SMTP验证的密码(注意,这个密码貌似有限制,例如我用d!5neyland就不能被正确识别)
-m 表示邮件的内容如果你不带-m参数的话,就会提示你自行输入

vi /usr/local/icinga/etc/objects/commands.cfg
# 'notify-host-by-email' command definition
define command{
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** icinga*****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState:$HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time:$LONGDATETIME$\n" | /usr/local/bin/sendEmail –f
luodi@cdld.com–t $CONTACTEMAIL$–s mail.cdld.com–u "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is$HOSTSTATE$ **" –xu luodi@cdld.com –xp ldcdld123 }

# 'notify-service-by-email'command definition
define command{
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** icinga *****\n\nNotificationType: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress:$HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditionalInfo:\n\n$SERVICEOUTPUT$" | /usr/local/bin/sendEmail –f
luodi@cdld.com–t $CONTACTEMAIL$ –s mail.cdld.com–u "** $NOTIFICATIONTYPE$ ServiceAlert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" –xu luodi–xp ldcdld123 }

 

   注:使用#注释commands.cfg中默认定义的邮件配置文件

 

  1. 15.  Icinga基本配置完成,关于主机定义、服务定义可以查看文档

 

spacer.gif