一、环境:
OS: CentOS 6.2 Minimal
IP: 172.16.51.9
HOSTNAME: icinga.hqew.com
二、搭建
源码包存放位置:/usr/local/src
1、安装基本软件包
- # yum install -y make automake gcc-c++ httpd gcc glibc glibc-common gd gd-devel libjpeg libjpeg-devel libpng libpng-devel mysql mysql-server libdbi libdbi-devel libdbi-drivers libdbi-dbd-mysql
关闭防火墙,禁用selinux
- # chkconfig iptables off >> service iptables stop
- # sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
2、下载icinga源码包及nagios插件
- # cd /usr/local/src
- # wget -c
- # wget -c
3、创建icinga用户
- # useradd – m icinga
- # passwd icinga
- # groupadd icinga-cmd
- # usermod -a -G icinga-cmd icinga
- # usermod -a -G icinga-cmd apache
4、编译安装icinga
- # yum install -y xz
- # xz -d icinga-cn-1.7.0.tar.xz
- # tar xf icinga-cn-1.7.0.tar
- # cd icinga-cn-1.7.0
- # ./configure –with-command-group=icinga-cmd –enable-idoutils
- # make all
- # make install
- # make install-init
- # make install-config
- # make install-eventhandlers
- # make install-commandmode
或者更简便:
- # make fullinstall
- # make install-config
5、编辑警报联系人
- # vi /usr/local/icinga/etc/objects/contacts.cfg
6、启用idomod event broker module
- # cd /usr/local/icinga/etc/module
- # cp idoutils.cfg-sample idoutils.cfg
- # chown icinga.icinga idoutils.cfg
7、创建数据库
- # service mysqld start
- # mysql
- mysql> drop database test;
- Query OK, 0 rows affected (0.00 sec)
-
- mysql> use mysql
- Reading table information for completion of table and column names
- You can turn off this feature to get a quicker startup with -A
-
- Database changed
- mysql> delete from user where user='';
- Query OK, 2 rows affected (0.00 sec)
-
- mysql> update user set password=password('123456') where user='root';
- Query OK, 3 rows affected (0.00 sec)
- Rows matched: 3 Changed: 3 Warnings: 0
-
- mysql> flush privileges;
- Query OK, 0 rows affected (0.00 sec)
-
- 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> \q
8、导入数据库
- # mysql -p icinga < /usr/local/src/icinga-cn-1.7.0/module/idoutils/db/mysql
- Enter password:
- ERROR 1273 (HY000) at line 627: Unknown collation: 'utf8_general_cs'
解决:
编辑mysql.sql,删除utf8_geneal_cs,共有四个,然后重新导入。
9、配置ido2db.cfg
- # vi /usr/local/etc/icinga/etc/ido2db.cfg
确保如下内容:
- db_servertype=mysql
- db_port=3306
- db_user=icinga
- db_pass=icinga
10、配置Classic Web界面
- # cd /usr/local/src/icinga-cn-1.7.0
- # make cgis
- # make install-cgis
- # make install-html
- # make install-webconf
11、启动httpd服务
- # chkconfig httpd on >> service httpd start
12、编译安装Nagios插件
- # cd /usr/local/src
- # tar xf nagios-plugins-1.4.15.tar.gz
- # cd 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
- # make >> make install
13、启动idoutils和icinga
- # service ido2db start
- # service icinga start
- # chkconfig –add icinga >> chkconfig icinga on
PS:
启动icinga之前可以先测试一下配置文件
- # /usr/local/icinga/bin/icinga -v /usr/local/icinga/etc/icinga.cfg
编译安装nrpe
- # cd /usr/local/src
- # wget -c
- # tar xf nrpe-icinga-2.12.tar.bz2
- # ./configure
- # make all
-
- Makefile:86: *** missing separator. Stop.
解决:
编辑Makefile,删除85-92行(判断操作系统)
- # vi Makefile
- # make all
- # make install
- # make install-plugin
- # make install-init
- # make install-xinetd
- # make install-daemon-config
测试
- # /usr/local/icinga/libexec/check_nrpe -H 127.0.0.1
- NRPE v2.12
- # /usr/local/icinga/libexec/check_nrpe -H 172.16.51.7
- CHECK_NRPE: Error - Could not complete SSL handshake.
解决:
配置被监控linux主机
- # vi /usr/local/icinga/etc/nrpe.cfg
- allowed_hosts=127.0.0.1,172.16.51.9
- # /etc/init.d/icinga-nrpe restart
- # /usr/local/icinga/libexec/check_nrpe -H 172.16.51.7
- NRPE v2.12