Nagios+Centreon+Nrpe集成(一)

1、实验环境

操作系统

debian-6.0.5-amd64-DVD-1

serverIP192.168.113.5

Centreon

centreon-2.3.9.tar.gz

clientIP: 192.168.113.6

Nagios

nagios-3.4.1.tar.gz

源码安装

Nagios插件

nagios-plugins-1.4.16.tar.gz

 

Ndoutils

ndoutils-1.5.2.tar.gz

 

Nrpe

nrpe-2.13.tar.gz

 

MySQL

mysql-5.5.15.tar.gz

 

2、服务端在线安装内容

Program groups

Command

System base

apt-get install sudo tofrodos bsd-mailx lsb-release heirloom-mailx build-essential

Database server

apt-get install mysql-server libmysqlclient16 libmysqlclient-dev libmysql++-dev

###备注:这是在线安装内容,红色字体内容是源码安装mysql5.5.15后也需要安装的内容

WebServer and

PHP5

apt-get install apache2 apache2-mpm-prefork php5 php5-mysql php-pear php5-ldap php5-snmp php5-gd

RRDTools

apt-get install rrdtool librrds-perl

### 备注:安装后路径:/usr/bin/rrdtool

Perl modules

apt-get install libconfig-inifiles-perl libcrypt-des-perl libdigest-hmac-perl libdigest-sha1-perl libgd-gd2-perl

SNMP

apt-get install snmp snmpd libnet-snmp-perl libsnmp-perl

GD-libraries

and othes pack

apt-get install libgd2-xpm libgd2-xpm-dev libpng12-dev fping libmcrypt4 libldap2-dev libgnutls-dev libssl-dev smbclient libpq-dev libradiusclient-ng-dev dbi-link

3、服务端集成应用

3.1 Mysql

源码安装省略……
# insserv mysqld   //创建自启动
# insserv -d mysqld
# mysqladmin -u root password '111111'   //修改root密码


3.2 Ngigos

3.2.1安装

### 版本:nagios-3.4.1.tar.gz  
下载地址:http://www.nagios.org/download/
          http://sourceforge.net/projects/nagios/files/
# apt-get install nagios3  //在线安装
# /usr/sbin/useradd -m nagios     //以下是源码安装
# /usr/sbin/groupadd nagcmd
# /usr/sbin/usermod -G nagios,nagcmd www-data
# tar zxvf nagios-3.4.1.tar.gz
# cd nagios/
# ./configure --prefix=/usr/local/nagios --with-command-group=nagcmd --enable-nanosleep --enable-event-broker
# make all
# make install
# make install-init
# make install-commandmode
# make install-config
# make install-webconf
# htpasswd -c /usr/local/nagios/etc/htpasswd.users nadmin
# htpasswd -c /etc/nagios3/htpasswd.users nadmin   //在线安装时
//创建nogios登陆用户名和密码,apache自动安装后/usr/bin/htpasswd路径
# vim /etc/rc.local   //设置nagios自启动
/etc/init.d/nagios start

3.2.2 配置

# vim /usr/local/nagios/etc/cgi.cfg
  use_authentication=0   //修给cgi权限验证问题
# vim /usr/local/nagios/etc/nagios.cfg   //待定
//验证nagios配置文件是否正确
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg -d

3.3 Ngigos Plugins

### 版本:nagios-plugins-1.4.16.tar.gz 
下载地址:http://www.nagios.org/download/plugins/
# apt-get install nagios-plugins   //在线
# tar zxvf nagios-plugins-1.4.16.tar.gz
# cd nagios-plugins-1.4.16
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl=/usr/bin/openssl --enable-perl-modules
# make 
# make install

3.4 Nrpe install for server

### 版本:nrpe-2.13.tar.gz
下载地址:http://sourceforge.net/projects/nagios/files/nrpe-2.x/
# apt-get install nagios-nrpe-server nagios-nrpe-plugin //在线安装
# tar zxvf nrpe-2.13.tar.gz //以下为源码安装
# cd nrpe-2.13
# ./configure
# make all
# make install-plugin
# make install-daemon
# make install-daemon-config
# vim /usr/local/nagios/etc/nrpe.cfg
### 备注,在线安装目录:/etc/nagios/nrpe.cfg
server_address=192.168.113.5      //修改nrpe服务器IP地址
allowed_hosts=127.0.0.1,192.168.113.5  //允许访问的IP地址
//nrpe启动并测试是否启动成功,且加入/etc/rc.local使得开机自启动
# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
# netstat -antup |grep 5666
### 或者:
# cp init-script.debian /etc/init.d/nrpe
# chmod +x /etc/init.d/nrpe    # /etc/init.d/nrpe start
//验证客户端nrpe是否正常连接,显示:NRPE v2.13 说明服务正常
# /usr/local/nagios/libexec/check_nrpe -H 192.168.113.5
# /usr/lib/nagios/plugins/check_nrpe -H 192.168.113.5  //在线安装路径

3.5 Ndoutils

3.5.1安装

### 版本:ndoutils-1.5.2.tar.gz
下载地址:http://sourceforge.net/projects/nagios/files/ndoutils-1.x/
# apt-get install ndoutils-nagios3-mysql   //在线安装
# tar zxvf ndoutils-1.5.2.tar.gz   //以下是源码安装
# cd ndoutils-1.5.2
#./configure --prefix=/usr/local/nagios/ --enable-mysql \
--with-ndo2db-user=nagios --with-ndo2db-group=nagios \
--with-mysql-lib=/usr/local/mysql/lib/mysql \
--with-mysql-inc=/usr/local/mysql/include/mysql \
# make
# make install
# cp ./config/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg
# cp ./config/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg
# cp src/ndomod-3x.o /usr/local/nagios/bin/
# cp src/ndo2db-3x /usr/local/nagios/bin/
# chmod 774 /usr/local/nagios/bin/ndo*
# chown nagios:nagios /usr/local/nagios/bin/ndo*
# chown nagios:nagios /usr/local/nagios/etc/ndo*
# cp ./daemon-init.in /etc/init.d/ndo2db
# chmod +x /etc/init.d/ndo2db
# insserv ndo2db
# insserv -d ndo2db
//创建数据库且导入库内容
mysql> create database nagios;   
./installdb -u root -p 111111 -h localhost -d nagios
或者:
# cd /root/ndoutils-1.5.2/db
# mysql -uroot -p nagios<./mysql.sql

3.5.2配置

# vim /usr/local/nagios/etc/nagios.cfg
 broker_module=/usr/local/nagios/bin/ndomod-3x.o 
config_file=/usr/local/nagios/etc/ndomod.cfg
### 备注:以上内容是一行连接的,中间使用空格隔开的
# vim /usr/local/nagios/etc/ndo2db.cfg
  socket_type=tcp
#socket_name=/usr/local/nagios/var/ndo.sock
db_user=root
db_pass=111111
# vim /usr/local/nagios/etc/ndomod.cfg
  output=127.0.0.1
#output=/usr/local/nagios/var/ndo.sock
output_type=tcpsocket
#output=/usr/local/nagios/var/ndo.sock
# touch /usr/local/nagios/var/ndo2db.debug
# chown nagios:nagios /usr/local/nagios/var/ndo2db.debug
# vim /etc/init.d/ndo2db   //修改内容如下:
servicename=ndo2db
prefix=@prefix@
exec_prefix=${prefix}
#Ndo2dbBin=@bindir@/ndo2db
Ndo2dbBin=/usr/local/nagios/bin/ndo2db-3x
Ndo2dbCfgFile=@sysconfdir@/ndo2db.cfg
Ndo2dbCfgFile=/usr/local/nagios/etc/ndo2db.cfg
Ndo2dbVarDir=@localstatedir@
#Ndo2dbRunFile=$Ndo2dbVarDir/ndo2db.lock
Ndo2dbRunFile=/usr/local/nagios/var/ndo2db.lock
Ndo2dbLockDir=/var/lock/subsys
Ndo2dbLockFile=ndo2db
Ndo2dbUser=nagios
Ndo2dbGroup=nagios
//测试启动否
# /etc/init.d/ndo2db start   或者如下测试:
# /usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg
# netstat -antup |grep 5668     //查看端口是否打开
# tail -f /usr/lcoal/nagios/var/nagios.log  //出现以下提示则启动成功
ndomod: Successfully connected to data sink.  5000 queued items to flush.
ndomod: Successfully flushed 5000 queued items to data sink.
Event broker module '/usr/local/nagios/bin/ndomod-3x.o' initialized successfully.
Finished daemonizing... (New PID=9807)
//查看数据库表nagios.nagios_hosts是否写入数据
mysql> select host_id,address,display_name from nagios_hosts;
+---------+-----------+--------------+
| host_id | address   | display_name |
+---------+-----------+--------------+
|       3 | 127.0.0.1 | localhost    |
+---------+-----------+--------------+
1 row in set (0.00 sec)
//在线安装启动/etc/init.d/ndoutils start前,需要编辑:
# vim /etc/default/ndoutils

ENABLE_NDOUTILS=1     //修改成 1

//问题解决:
问题(1./installdb nagios数据库时报:
failed: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) at ./installdb line 41
解决:# mkdir -p /var/run/mysqld  
# ln -s /tmp/mysql.sock /var/run/mysqld/mysqld.sock
问题(2./installdb nagios数据库时报:
DBD::mysql::db do failed: Table 'nagios.nagios_dbversion' doesn't exist at ./installdb line 51.
解决:可以忽略,核实nagios数据库59个表即可
问题(3tail -f  nagios.log时,提示:
ndomod: Could not open data sink!ndomod: Still unable to connect to data sink.
解决:按照以上操作,且进程ps均可见,则尝试重启ndo2db nagiosmysql