Debian 系统 Nagios+Centreon+Nrpe集成

1、软件包信息

操作系统

debian-6.0.5-amd64-DVD-1

 

Centreon

centreon-2.3.9.tar.gz

 

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 NgigosPlugins

### 版本:nagios-plugins-1.4.16.tar.gz 
# 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

### 版本: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
//验证客户端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

4centreon集成

4.1应用程序安装

### 版本:centreon-2.3.9.tar.gz
下载地址:http://www.centreon.com/Content-Download/donwload-centreon
安装参考文档:(1http://documentation.centreon.com/01-centreon/centreon_web/documentation/01-setup/installation_from_sources/step_05_-_centreon
2http://blog.sina.com.cn/s/blog_5611597901016qd2.html
 
# tar zxvf centreon-2.3.9.tar.gz
# cd centreon-2.3.9
# ./install.sh -i //以下是安装过程中需要根据实际路径修改的地方,其他均为y 回车(当然你也可以自己定制)

Where is your NDO ndomod binary ?

default to [/usr/sbin/ndomod.o]

> /usr/local/nagios/bin/ndomod.o

/usr/local/nagios/bin/ndomod.o                             OK

4.2 web installation

(1)以下服务均已启动

# /etc/init.d/apache2 start
# /etc/init.d/mysqld start
# /etc/init.d/ndo2db start
# /etc/init.d/nagios start

(2)开始安装:http://192.168.113.5/centreon/

### 备注参考内容:

http://documentation.centreon.com/01-centreon/centreon_web/documentation/01-setup/installation_from_sources/step_05_-_centreon

http://blog.sina.com.cn/s/blog_5611597901016qd2.html

### 部分配图:其他基本next

图示1mysql root密码填写,三个新库密码设置

 

图示2:配置centreon管理员用户、密码、其他三项自定义

 

4.3在线安装nagios

Centreon安装时,其他应用在线安装的,需要修改以下可能出现的路径问题:

 

Where is installed Nagios ?

default to [/usr/local/nagios]

>  /usr/share/nagios3/

Path /usr/share/nagios3/                                   OK

 

Where is your nagios config directory

default to [/usr/local/nagios/etc]

> /etc/nagios3

Path /etc/nagios3                                          OK

 

Where is your Nagios var directory ?

default to [/usr/local/nagios/var]

>  /var/log/nagios3/

Path /var/log/nagios3/                                     OK

 

Where is your Nagios plugins (libexec) directory ?

default to [/usr/local/nagios/libexec]

> /usr/lib64/nagios/plugins

Path /usr/lib64/nagios/plugins                             OK

/usr/sbin/nagios3                                          OK

 

Where is your Nagios p_w_picpath directory ?

default to [/usr/local/nagios/share/p_w_picpaths/logos]

> /usr/share/nagios3/htdocs/p_w_picpaths/logos/

Path /usr/share/nagios3/htdocs/p_w_picpaths/logos/               OK

 

Where is your NDO ndomod binary ?

default to [/usr/sbin/ndomod.o]

> /usr/lib/ndoutils/ndomod-mysql-3x.o

/usr/lib/ndoutils/ndomod-mysql-3x.o                        OK

4.4 Web 安装centreon完成后

### 参考链接:http://www.xodino.it/?page_id=968

Finalize Centreon configuration:

Open in webrowser: "http://<yourserverip>/centreon/", replace "<yourserverip>" with your Centreon server ip address or hostname.

 

Go to: Configuration -> Nagios -> cgi (in sidebar), Press on "CGI.cfg" link

Change settings to some options, as writed below:

- Physical HTML Path: /usr/share/nagios3/htdocs

- URL HTML Path : /nagios3

- Nagios Process Check Command: /usr/lib/nagios/plugins/check_nagios /var/cache/nagios3/status.dat 5 '/usr/sbin/nagios3'

Press Save

 

Go to: Configuration -> Nagios -> nagios.cfg (in sidebar), Press on "Nagios CFG 1" link, you should be in "Files" section of the configuration screen.

Make sure to set folowing configuration values:

- Log File : /var/log/nagios3/nagios.log

- Downtime File : /var/lib/nagios3/downtime.dat

- Comment File : /var/lib/nagios3/comment.dat

- Temp File : /var/cache/nagios3/nagios.tmp

- P1 File : /usr/lib/nagios3/p1.pl

- Lock File : /var/run/nagios3/nagios3.pid

- Object Cache File : /var/cache/nagios3/objects.cache

- Status File : /var/cache/nagios3/status.dat

- External Command File : /var/lib/nagios3/rw/nagios.cmd

 

Now Press on "Logs Options" tab to go to "Logs Options" section.

Make sure to set folowing configuration values:

- Log Archive Path : /var/log/nagios3/archives/

- State Retention File : /var/lib/nagios3/retention.dat

Press Save

 

Go to: Administration -> Options -> CentStorage (in sidebar)

Make sure to set folowing configuration values:

- Nagios current log file to parse: /var/log/nagios3/nagios.log

Press Save

 

Now let's apply our changes, go to: Configuration -> Nagios

Select as below:

- Generate Configuration Files

- Include Comments

- Run Nagios debug (-v)

- Move Export Files

- Restart Nagios

- Method: "External Command"

Press Export

 

This will restart Nagios & apply all changes you made in Web Interface.

You will do it every time you make changes, e.g. adding/modifying of hosts, commands, contacts, services...etc...

 

The installation of Centreon is completed.

 

Final fixes (very important):

Go to terminal console, then...

 

In Debian/Ubuntu the user "nagios" is set to "/bin/false" shell. Because of it "centcore" and "centstorage" daemons won't start. A reason for that is because those daemons use "su -c" command which requires a real shell, so the shell for

 

"nagios" user must be set to "/bin/sh":

# usermod -s /bin/sh nagios

 

Apply permissions for Web interface to be able to send "External Commands", perform the following commands to change directory permissions and to make the changes permanent:

# invoke-rc.d nagios3 stop

# dpkg-statoverride --update --add nagios www-data 2710 /var/lib/nagios3/rw

# dpkg-statoverride --update --add nagios nagios 751 /var/lib/nagios3

 

Add htaccess user with password "P@ssw0rd" for nagios CGI:

# htpasswd -bc /etc/nagios3/htpasswd.users nagiosadmin P@ssw0rd

 

Allow SNMP readonly access:

# echo "rocommunity public" > /etc/snmp/snmpd.conf

 

If you want to allow SNMP access only for localhost then use this instead:

# echo "rocommunity public 127.0.0.1" > /etc/snmp/snmpd.conf

# ls -al /usr/lib/nagios/plugins  //查看权限,需要具有sudo权限

# cd /usr/lib/nagios/

# chmod -R u+s plugins   //权限修改成 -rwsr-xr-x

### 不修改权限会报:Warning: This plugin must be either run as root or setuid root.

Now, restart the server

# reboot

4.5 可能的报错信息

1)报错解决:

Error: Could not create external command file '/var/log/nagios3/rw/nagios.cmd'

解决:mkdir /var/log/nagios3/rw

Chown nagios.nagios rw

2)在线安装ndoutils,启动ndo2前一定要修改:/etc/default/ndoutils

ENABLE_NDOUTILS=1

### 说明,debian操作系统下安装比较麻烦,建议还是用我参考的完整系统吧呵呵!