本文介绍完整的nagios和centreon安装过程。


安装环境:

CentOS5.6,X64 updated。

Monitor Engine:Nagios

Broker module:NDoutils

假设:

已安装并启动mysql

路径为:/usr/local/mysql/

sock路径:/var/lib/mysql/mysql.sock

步骤参考英文原文:http://documentation.centreon.com/docs/centreon/en/latest/installation/from_sources.html


1、下载安装包

#下载nagios、nagios-plugin、nrpe、ndoutils以及ndoutils的一个patch

1
cd/data/tool
1
2
3
4
5
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.5.1.tar.gz
wget --no-check-certificate https://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz
wget http://jaist.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz
wget http://nchc.dl.sourceforge.net/project/nagios/ndoutils-1.x/ndoutils-1.5.2/ndoutils-1.5.2.tar.gz
wget http://svn.centreon.com/trunk/ndoutils-patch/ndoutils1.5.2_light.patch

#在 http://www.centreon.com/Content-Products-IT-network-monitoring/supported-software-and-requirements 检查安装centreon所需要的软件包 
#下载 centreon 2.4.0 

1
wget http://download.centreon.com/index.php?id=4264

#安装一些必要的package

1
yum install -y wget httpd php gcc glibc glibc-common gd gd-devel make net-snmp

2、开始安装nagios
#建立用户和组

1
2
3
4
5
chattr -i /etc/passwd /etc/shadow /etc/group /etc/gshadow
useradd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd apache

#安装 nagios-core

1
2
3
4
5
6
7
8
9
10
11
12
tar-zxvf nagios-3.5.1.tar.gz
cdnagios
./configure--prefix=/usr/local/nagios--with-command-group=nagcmd \
--enable-event-broker --enable-embedded-perl --with-perlcache
makeall
makeinstall
makeinstall-init
makeinstall-config
makeinstall-commandmode
makeinstall-webconf
cp-R contrib/eventhandlers//usr/local/nagios/libexec/
chown-R nagios:nagios /usr/local/nagios/libexec/eventhandlers

#启动 nagios apache

1
2
3
/usr/local/nagios/bin/nagios-v/usr/local/nagios/etc/nagios.cfg
/etc/init.d/nagiosstart
/etc/init.d/httpdstart

#创建nagios用户用于登录  

1
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

#安装 nagios-plugins

1
2
3
4
5
6
7
8
9
tar -zxvf nagios-plugins-1.5.tar.gz
cd ../nagios-plugins-1.5
./configure --with-nagios-user=nagios \
--with-nagios-group=nagios \
--prefix=/usr/local/nagios \
--enable-redhat-pthread-workaround --with-ipv6=no \
--enable-perl-modules \
--with-mysql=/usr/local/mysql
make && make install

#安装nrpe

1
2
3
4
5
6
7
tar-zxvf nrpe-2.15.tar.gz
./configure--prefix=/usr/local/nagios
makeall
makeinstall-plugin
makeinstall-daemon
makeinstall-daemon-config
makeinstall-xinetd

安装xinetd以便管理

1
2
3
4
yum install xinetd -y
sed -i 's/127.0.0.1/127.0.0.1 183.61.70.34/'/etc/xinetd.d/nrpe
sed -i '578 i\nrpe 5666/tcp # NRPE'/etc/services
service xinetd restart
1
2
/usr/local/nagios/libexec/check_nrpe -H localhost -c check_users
sed -i 's/allowed_hosts=127.0.0.1/allowed_hosts=127.0.0.1,<your ip addr>/'/usr/local/nagios/etc/nrpe.cfg

3、安装 ndoutils

1
2
3
4
tar-zxvf ndoutils-1.5.2.tar.gz
cdndoutils-1.5.2
patch -p1 -N < ../ndoutils1.5.2_light.patch
./configure--prefix=/usr/local/nagios/--enable-mysql --with-mysql=/usr/local/mysql--with-ndo2db-user=nagios --with-ndo2db-group=nagios

默认的源文件 make 会报错 修改如下

1
2
3
4
sed-i -e 's/#include <mysql\/mysql.h>/#include <\/usr\/local\/mysql\/include\/mysql.h>/'include/config.h
sed-i -e 's/#include <mysql\/errmsg.h>/#include <\/usr\/local\/mysql\/include\/errmsg.h>/'include/config.h
make
makeinstall
1
2
cp./config/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg
cp./config/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg

#编辑/usr/local/nagios/etc/nagios.cfg 在broker_module处添加

1
broker_module=/usr/local/nagios/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfg

#安装启动文件

1
2
chmod+x daemon-init
cpdaemon-init /etc/init.d/ndo2db

#创建数据库用户 

1
2
3
4
mysql -p
>>createdatabasenagios;
GRANTALLPRIVILEGESONnagios.* TO'nagios'@'localhost'IDENTIFIED BY'nagios';
>>FLUSH PRIVILEGES;

#安装数据库

1
2
cddb/
./installdb-u nagios -p nagios -h localhost -d nagios

4、安装 centreon

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
usermod-a -G apache centreon
usermod-a -G nagios centreon
wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.1-1.el5.rf.x86_64.rpm
wget http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
rpm --importRPM-GPG-KEY.dag.txt
rpm -ivh rpmforge-release-0.5.1-1.el5.rf.x86_64.rpm
yum clean all
yum update
yum upgrade
yum installhttpd gd fontconfig-devel libjpeg-devel libpng-devel gd-devel perl-GD \
openssl-devel perl-DBD-MySQL mysql-server mysql-devel php php-mysql php-gd php-ldap php-xml php-mbstring \
perl-Config-IniFiles perl-DBI perl-DBD-MySQL rrdtool perl-rrdtool perl-Crypt-DES perl-Digest-SHA1 \
perl-Digest-HMAC net-snmp-utils perl-Socket6 perl-IO-Socket-INET6 net-snmp net-snmp-libs php-snmp \
dmidecode lm_sensors perl-Net-SNMP net-snmp-perl fping cpp gcc gcc-c++ libstdc++ glib2-devel \
php-pear

1
2
3
4
usermod-U apache
pear channel-update pear.php.net
peardev upgrade-all
pear upgrade-all

报错处理:[PHP Fatal error: Allowed memory size of 8388608 bytes exhausted] 

1
echo'memory_limit = 256M'>>/etc/php.ini

#开始安装centreon

1
./install.sh -i

#经过一系列回车(保持默认配置)以及需要填写的路径完成命令行下的centreon安装。

#此处不一一贴出

#需要注意的两个路径RRDs.pm、PEAR.php 可使用find 找到准确路径

1
2
/usr/local/rrdtool/lib/perl/5.8.8/x86_64-linux-thread-multi/RRDs.pm
/usr/share/pear/PEAR.php

#配置centreon数据库用户

1
2
3
4
GRANTALLPRIVILEGESON`centreon`.* TO'centreon'@'localhost'identified by'centreon';
GRANTALLPRIVILEGESON`centreon_storage`.* TO'centreon'@'localhost'identified by'centreon';
GRANTALLPRIVILEGESON`centreon_status`.* TO'centreon'@'localhost'identified by'centreon';
FLUSH PRIVILEGES;

#登录web界面进行下一步安装:

http://SERVER_ADDRESS/centreon

#检查php拓展

161914280.png

#配置Nagios相关路径

161914671.png

#配置NDoutils路径

161914235.png

#管理员账户密码

161914488.png

#数据库连接信息

161915138.png

#开始安装数据库

161915392.png

#安装完成可登录

161915414.png


以上为centreon安装完整步骤,坑稍微有点多。

特别是centreon命令行模式安装时每个路径、文件名都不要写错。