Icinga

Icinga安装配置手册

Icinga介绍

ICINGA项目是 由Michael Luebben、Hendrik Backer和JoergLinge等人发起的,他们都是现有的Nagios项目社区委员会的成员,他们承诺,新的开源项 目将完全兼容以前的Nagios应用程序及扩展功能。在新项目的网站上,他们是如此定义ICINGA的,这将是一个介于Nagios社区版和企业版间的产 品。特别将致力于解决Nagios项目现在的问题,比如不能及时处理Nagios项目的bug、新功能不能及时添加等。还有在新的ICINGA项目中,将 更好的实现数据库集成方面的功能,标准化第三发应用程序的接口等。

中文项目地址:http://icinga-cn.sourceforge.net/

Icinga架构

Icinga的功能是监控服务和主机,但是他自身并不包括这部分功能,所有的监控、检测功能都是通过各种插件来完成的。

启动 Icinga后,它会周期性的自动调用插件去检测服务器状态,同时 Icinga 会维持一个队列,所有插件返回来的状态信息都进入队列,Icinga每次都从队首开始读取信息,并进行处理后,把状态结果通过 web 显示出来。

Icinga 提供了许多插件,利用这些插件可以方便的监控很多服务状态。安装完成后,在Icinga 主目录下的/libexec 里放有 Icinga 自带的可以使用的所有插件,如,check_disk 是检查磁盘空间的插件,check_load是检查CPU负载的,等等。每一个插件可以通过运行./check_xxx -h 来查看其使用方法和功能。Icinga 可以识别 4 种状态返回信息,即 :

  • 0(OK)表示状态正常
  • 1(WARNING)表示出现一定的异常
  • 2(CRITICAL)表示出现非常眼中的错误
  • 3(UNKNOWN)表示被监控的对象已经停止了

Icinga 根据插件返回来的值,来判断监控对象的状态,并通过 web 显示出来,以供管理员及时发现故障。

安装

Server side:

以下安装步骤都在监控服务器主机172.24.133.18上进行

Requirement

下载源包

wget <span style="color:#A9A9A9;">http://192.168.153.87:9999/icinga/httpd-2.2.27.tar.gz</span>  //使用yum install httpd替代

wget <span style="color:#A9A9A9;">http://192.168.153.87:9999/icinga/mysql-5.6.20-linux-glibc2.5-x86_64.tar.gz</span>  //使用yum install mysql mysql-server替代

wget <span style="color:#A9A9A9;">http://192.168.153.87:9999/icinga/php-5.3.27.tar.gz</span>  //使用yum install php替代

wget http://192.168.153.87:9999/icinga/icinga-core-1.11.7.tar.gz

wget http://192.168.153.87:9999/icinga/monitoring-plugins-2.0.tar.gz

wget http://192.168.153.87:9999/icinga/nrpe-2.15.tar.gz  //此处为配合icinga绑定,不使用yum源安装

wget http://192.168.153.87:9999/icinga/pnp4nagios-0.6.24.tar.gz

 

Apache2

tar zxvf httpd-2.2.27.tar.gz

cd httpd-2.2.27l

./configure --prefix=/usr/local/apache2 \

--enable-modules='deflate rewrite exprires ssl proxy' --with-ssl

make -j 4 && make install 

yum install httpd

MySQL

tar zxvf mysql-5.6.20-linux-glibc2.5-x86_64.tar.gz -C /usr/local/

mv /usr/local/mysql-5.6.20-linux-glibc2.5-x86_64  /usr/local/mysql

cd /usr/local/mysql

echo 'export PATH=/usr/local/apache2/bin:/usr/local/mysql/bin:$PATH' >> /etc/profile

source /etc/profile

echo /usr/local/mysql/lib >> /etc/ld.so.conf

ldconfig 

useradd -M -s /sbin/nologin mysql

rm -f /etc/my.cnf

./scripts/mysql_install_db --user=mysql

/usr/local/mysql/support-files/mysql.server start

mysqladmin -uroot password dbpasswd -S /tmp/mysql.sock

 yum install mysql mysql-server

PHP

tar zxvf php-5.3.27.tar.gz

cd php-5.3.27

./configure --prefix=/usr/local/php5  \

--with-apxs2=/usr/local/apache2/bin/apxs \

--with-mysql=mysqlnd --with-mysqli=mysqlnd  --with-pdo-mysql=mysqlnd \

--with-gd --with-zlib --with-iconv --enable-sockets \

--enable-ftp --enable-xml --enable-zip --enable-mbstring \

--enable-soap --with-xmlrpc --with-libxml-dir --with-curl   \

--with-jpeg-dir  --with-png-dir --with-mhash --with-freetype-dir \

--with-gettext --disable-debug --disable-dom 

make -j 8 && make install 

cp  php.ini-production  /usr/local/php5/lib/php.ini

echo 'addtype application/x-httpd-php .php'>> /usr/local/apache2/conf/httpd.conf

 

yum install php

图形处理库gd

yum install libjpeg libjpeg-devel libpng libpng-devel

yum install gd gd-devel

 

icinga

yum install libdbi libdbi-devel libdbi-dbd-mysql -y

tar xvf icinga-core-1.11.7.tar.gz

cd icinga-core-1.11.7

groupadd  icinga

useradd -s /sbin/nologin -g icinga icinga

./configure --prefix=/usr/local/icinga \

--with-icinga-user=icinga --with-icinga-group=icinga \

--with-command-user=icinga --with-command-group=icinga \

--enable-idoutils --enable-nanosleep --enable-event-broker \

--with-web-user=daemon -with-web-group=daemon \

--with-httpd-conf=/etc/httpd/conf.d/ \

-with-gd-lib=/usr/lib

 

make -j 4 all 

make fullinstall

make install-config

配置web界面

make cgis

make install-cgis

make install-html

make install-webconf

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

数据库建立

mysql -uroot -p

mysql> CREATE DATABASE icinga;

mysql> GRANT USAGE ON icinga.* TO 'icinga'@'localhost'

IDENTIFIED BY 'icinga'

WITH MAX_QUERIES_PER_HOUR 0

MAX_CONNECTIONS_PER_HOUR 0

MAX_UPDATES_PER_HOUR 0;

mysql> GRANT SELECT, INSERT, UPDATE, DELETE, DROP, CREATE VIEW, INDEX, EXECUTE ON icinga.* TO 'icinga'@'localhost';

mysql>FLUSH PRIVILEGES;

mysql> quit;

mysql -uroot -D icinga < module/idoutils/db/mysql/mysql.sql

DB配置IDOUtils

cd /usr/local/icinga/etc

cp ido2db.cfg-sample ido2db.cfg

vi /usr/local/icinga/etc/ido2db.cfg

db_servertype=mysql

db_port=3306

db_user=icinga

db_pass=icinga

icinga plugin

tar zxvf monitoring-plugins-2.0.tar.gz

cd monitoring-plugins-2.0

./configure --prefix=/usr/local/icinga \

--with-nagios-user=icinga --with-nagios-group=icinga \

--enable-perl-modules

make -j 4 && make install 


cd /usr/local/icinga/libexec/  && scp 192.168.153.87:/root/box/icinga/check_ceph/* ./

chown -R icinga:icinga check_ceph_*

若bin/ceph路径不同,需修改check_ceph_*中的"CEPH_COMMAND = "和 "RGW_COMMAND = "

nrpe

tar zxvf nrpe-2.15.tar.gz

cd nrpe-2.15

./configure --prefix=/usr/local/icinga \

--with-nrpe-user=icinga --with-nrpe-group=icinga \

--with-nagios-user=icinga --with-nagios-group=icinga


make -j 4 all

make install

make install-plugin

make install-daemon

make install-daemon-config


cp init-script /etc/init.d/nrpe

chmod +x /etc/init.d/nrpe

 

 

配置nrpe

vi /usr/local/icinga/etc/nrpe.cfg

allowed_hosts=127.0.0.1,172.24.133.18 

command[check_ssh]=/usr/local/icinga/libexec/check_ssh -H localhost 

command[check_swap]=/usr/local/icinga/libexec/check_swap -w 20% -c 10% 

command[check_mysql]=/usr/local/icinga/libexec/check_mysql -H localhost -uroot -ptomcat2008 

command[check_apache]=/usr/local/icinga/libexec/check_apachestatus -H localhost -p 80 

command[check_ntp]=/usr/local/icinga/libexec/check_ntp -H localhost -w 0.5 -c 1 

command[check_snmp]=/usr/local/icinga/libexec/check_snmp_service -H localhost -C monitor_energysh

command[check_osd]=/usr/local/icinga/libexec/check_ceph_osd -H 172.24.133.17
command[check_rgw]=/usr/local/icinga/libexec/check_ceph_rgw -i radosgw.node3
command[check_ceph_health]=/usr/local/icinga/libexec/check_ceph_health
command[check_mon]=/usr/local/icinga/libexec/check_ceph_mon  -H 172.24.133.17 -I node3


Start service

service httpd restart

/etc/init.d/ido2db start

/etc/init.d/icinga start

/etc/init.d/nrpe start

 

pnp4nagios

yum install rrdtool*

yum install php-gd

yum install perl-Time-HiRes

 

tar zxvf pnp4nagios-0.6.24.tar.gz

cd pnp4nagios-0.6.24

./configure  --prefix=/usr/local/icinga \

--with-nagios-user=icinga --with-nagios-group=icinga \

--with-httpd-conf=/etc/httpd/conf.d

 

make -j 4 all 

make fullinstall

make install-config

make install-webconf

cp /usr/local/icinga/etc/rra.cfg-sample /usr/local/icinga/etc/rra.cfg

vi /etc/httpd/conf.d/pnp4nagios.conf

Alias /pnp4nagios "/usr/local/icinga/share"

<Directory "/usr/local/icinga/share">

        ..................

        AuthName "icinga Access"

        AuthType Basic

        AuthUserFile /usr/local/icinga/etc/htpasswd.users

        Require valid-user

       .......................

</Directory>

配置pnp4nagios

vi /usr/local/icinga/etc/icinga.cfg

process_performance_data=1

host_perfdata_command=process-host-perfdata

service_perfdata_command=process-service-perfdata

enable_environment_macros=1

vi /usr/local/icinga/etc/objects/commands.cfg  //最后两项

define command {

       command_name    process-service-perfdata

       command_line    /usr/bin/perl /usr/local/icinga/libexec/process_perfdata.pl

}

define command {

       command_name    process-host-perfdata

       command_line    /usr/bin/perl /usr/local/icinga/libexec/process_perfdata.pl -d HOSTPERFDATA

}

vi /usr/local/icinga/etc/objects/templates.cfg  //复制追加到尾部

define host{

        name            host-pnp4

        action_url      /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_ 

        register                0

        process_perf_data       0

}

define service{

        name            service-pnp4

        action_url  /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$ 

        register             0

        process_perf_data    0

}

vi /usr/local/icinga/etc/objects/localhost.cfg 

//所有linux-server后加”,host-pnp4”和”,service-pnp4” 

对应define host/service

define host{

        use                     linux-server,host-pnp4

….....

}

define service{

        use                             local-service, service-pnp4

        host_name                       localhost

….....

}

rm -fv /usr/local/icinga/share/install.php 

bulk +NPCD 模式

make install-webconf

make install-init

icinga.cfg

process_performance_data=1

host_perfdata_command=process-host-perfdata

service_perfdata_command=process-service-perfdata

 

host_perfdata_file=/tmp/host-perfdata

service_perfdata_file=/tmp/service-perfdata

 

host_perfdata_file=/usr/local/icinga/var/host-perfdata

service_perfdata_file=/usr/local/icinga/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$\tHOSTSTAT

ETYPE::$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

event_broker_options=-1

新增

broker_module=/usr/local/icinga/lib/npcdmod.o config_file=/usr/local/icinga/etc/npcd.cfg

command.cfg

  1.  'check_nrpe' command definition

define command{

       command_name     check_nrpe

       command_line     $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$

       }

define command{

       command_name    process-service-perfdata-file

       command_line    /bin/mv /usr/local/icinga/var/service-perfdata /usr/local/icinga/var/spool/service-perfdata.$TIMET$

}

define command{

       command_name    process-host-perfdata-file

       command_line    /bin/mv /usr/local/icinga/var/host-perfdata /usr/local/icinga/var/spool/host-perfdata.$TIMET$

}

templates.cfg

define host{

        name            host-pnp4

        action_url      /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_ 

        register                0

}

define service{

        name            service-pnp4

        action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$ 

        register   0

}

Start service

> service npcd start

> service icinga restart

> service httpd restart

[[File:|File:]] 

Client side:

假设:安装被监控端服务器:172.24.133.17

创建icinga用户和组,使用icinga启动nrpe

  1. groupadd icinga
  1. useradd -s /sbin/nologin -g icinga icinga
  • 编译安装nrpe,参考上文
  • 编译安装monitoring-plugin,参考上文

被监控端配置

  • # vi /usr/local/icinga/etc/nrpe.cfg   //磁盘容量等监控根据具体信息(df -h)进行修改

allowed_hosts=127.0.0.1,172.24.133.18

command[check_ssh]=/usr/local/icinga/libexec/check_ssh -H localhost 

command[check_swap]=/usr/local/icinga/libexec/check_swap -w 20% -c 10% 

command[check_mysql]=/usr/local/icinga/libexec/check_mysql -H localhost -uroot -ptomcat2008 

command[check_apache]=/usr/local/icinga/libexec/check_apachestatus -H localhost -p 80 

command[check_ntp]=/usr/local/icinga/libexec/check_ntp -H localhost -w 0.5 -c 1 

command[check_snmp]=/usr/local/icinga/libexec/check_snmp_service -H localhost -C monitor_energysh

 

[root@nd0302014911 ~]# cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/nds/lib

  • # /etc/init.d/nrpe restart  or service nrpe restart
  • 若出现"ImportError: No module named ceph_rados",  cd /usr/loca/nds/tool/  && ln -s ../lib/pybind/*.py ./

服务器端配置

  • vi /usr/local/icinga/etc/conf.d/172.24.133.17.cfg //添加client.cfg

define host{

        use                     linux-server,host-pnp4 

        host_name               172.24.133.17

        alias                   172.24.133.17

        address                 172.24.133.17

        }

define service{

        use                           linux-service,service-pnp4

        host_name                     172.24.133.17

        service_description             Current Users

        check_command                check_nrpe!check_ssh

        }

...............................

 

  • reload icinga

/etc/init.d/icinga reload

监控命令范例:

监控流量

check_traffic.sh

监控CPU

check_load -w $ARG1$ -c $ARG2$

check_load  -r -w 2.0,3.0,4.0 -c 5.0,6.0,7.0

监控主机live

check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5

监控交换分区

check_swap -w $ARG1$ -c $ARG2$

check_swap -w 80 -c 70

监控磁盘

check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$

监控进程

check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$

监控http服务

check_http -I $HOSTADDRESS$ $ARG1$

监控ssh服务

check_ssh $ARG1$ $HOSTADDRESS$

监控tcp端口

check_tcp -H $HOSTADDRESS$ -p $ARG1$ $ARG2$

监控ceph服务

command[check_osd]=/usr/local/icinga/libexec/check_ceph_osd -H 172.24.133.18
command[check_rgw]=/usr/local/icinga/libexec/check_ceph_rgw -i radosgw.node3
command[check_ceph_health]=/usr/local/icinga/libexec/check_ceph_health
command[check_mon]=/usr/local/icinga/libexec/check_ceph_mon  -H 172.24.133.18 -I node3

重要配置项

/etc/httpd/conf.d/icinga.conf

/usr/local/icinga/etc/nrpe.cfg

web demo

[http://172.24.133.18:81/]  组内集群监控

你可能感兴趣的:(icinga)