分类: 系统运维
2009-06-19 19:05:55
10) 安装配置NDOUtils
NDOUtils是一个插件,让您的数据存储Nagios (当前状态信息,历史状态,历史的通知等)在MySQL数据库。
准备软件包
使用yum安装所需组件
yum -y install mysql mysql-devel mysql-server gcc-c++
/etc/init.d/mysqld start
chkconfig --add mysqld
make sure it's running
ps -ef | grep mysql
安装ndoutils
cd /usr/local/nagios-share
wget
tar zxfv ndoutils-1.4b7.tar.gz
cd ndoutils-1.4b7
./configure
make
创建NDO 数据库
mysql -u root –p root123
mysql>create database nagios;
Query OK, 1 row affected (0.00 sec)
mysql>show databases;
+----------+
| Database |
+----------+
| database |
| mysql |
| nagios |
| test |
+----------+
4 rows in set (0.01 sec)
mysql -u root -p nagios < db/mysql.sql
mysql -u root -p nagios < db/mysql-mods-1.4b7.sql
mysql> GRANT SELECT , INSERT , UPDATE , DELETE ON `nagios`.* TO mysql>'nagios'@'localhost';
mysql>FLUSH PRIVILEGES;
复制ndomod 和ndo2db
ndomod-2x.o = NDOMOD module for Nagios 2.x ndomod-3x.o = NDOMOD module for Nagios 3.x (unstable)
cp /src/ndomod-3x.o /usr/local/nagios/bin/ndomod.o
ndo2db-2x.o = NDO2DB daemon for Nagios 2.x ndo2db-3x.o = NDO2DB daemon for Nagios 3.x (unstable)
cp src/ndo2db-3x /usr/local/nagios/bin/ndo2db
配置ndo2db.cfg
cp /config/ndo2db.cfg /usr/local/nagios/etc/nagios/
修改 ndo2db.cfg 文件
# SOCKET TYPE
# This option determines what type of socket the daemon will create
# an accept connections from.
# Value:
# unix = Unix domain socket (default)
# tcp = TCP socket
socket_type=unix
#socket_type=tcp
. . .
# SOCKET NAME
# This option determines the name and path of the UNIX domain
# socket that the daemon will create and accept connections from.
# This option is only valid if the socket type specified above
# is "unix".
#socket_name=/usr/local/nagios/var/ndo.sock
socket_name=/var/run/nagios/ndo.sock
. . .
# DATABASE USERNAME/PASSWORD
# This is the username/password that will be used to authenticate to the DB.
# The user needs at least SELECT, INSERT, UPDATE, and DELETE privileges on
# the database.
#db_user=ndouser
#db_pass=ndopassword
db_user=nagios
db_pass=nagios
mkdir /var/run/nagios
chmod -R nagios:nagios /var/run/nagios
配置ndomod.cfg
cp /config/ndomod.cfg /usr/local/nagios/etc/nagios/
在/usr/local/nagios/etc/nagios.cfg中增加一行
broker_module=/usr/local/nagios/bin/ndomod.o config_file=/usr/local/nagios/etc/ndomod.cfg 确认有以下参数
event_broker_options=-1
编辑 ndomod.cfg 设置
output=/var/run/nagios/ndo.sock
和ndo2db.cfg中的 socket_name 参数设置一样
[1192222122] ndomod: Error writing to data sink! Some output may get lost...
启动 NDO2DB 进程
/usr/local/nagios/bin/ndo2db –c /usr/local/nagios/etc/nagios/ndo2db.cfg
[root@localhost nagios]# ps -ef | grep ndo2db
nagios 26516 1 0 19:36 ? 00:00:00 ndo2db -c /etc/nagios/ndo2db.cfg
root 26536 26460 0 19:40 pts/0 00:00:00 grep ndo
[root@localhost nagios]#
重启 Nagios
/etc/init.d/nagios restart
查看是否正常
tail /var/log/messages
Jun 19 12:38:16 Centos5 nagios: LOG VERSION: 2.0
Jun 19 12:38:16 Centos5 nagios: ndomod: NDOMOD 1.4b7 (10-31-2007) Copyright (c) 2005-2007 Ethan Galstad (nagios@nagios.org)
Jun 19 12:38:16 Centos5 ndo2db: Successfully connected to MySQL database
Jun 19 12:38:16 Centos5 nagios: ndomod: Successfully connected to data sink. 0 queued items to flush.
Jun 19 12:38:16 Centos5 nagios: Event broker module '/usr/local/nagios/bin/ndomod.o' initialized successfully.
Jun 19 12:38:16 Centos5 nagios: Finished daemonizing... (New PID=22322)
Jun 19 13:38:16 Centos5 nagios: Auto-save of retention data completed successfully.
11)NRPE配置
NRPE是nagios的一个扩展,它被用于被监控的服务器上,向nagios监控平台提供该服务器的一些本地的情况。例如,cpu负载、内存使用、硬盘使用等等。NRPE可以称为nagios的for linux 客户端。
监控平台上的安装:
先安装 openssl-devel
yum install openssl-devel Installing for dependencies: e2fsprogs-devel krb5-devel
再安装 NRPE:
tar zxvf nrpe-2.12.tar.gz cd nrpe-2.12 ./configure make all make install-plugin
在 objects/commands.cfg 中定义 check_nrpe 使用的命令:
# 'check_nrpe' command definition define command{ command_name check_nrpe command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ }
被监控主机的安装:
同样需要安装 openssl-devel
创建 nagios 用户和组
groupadd nagios
useradd -g nagios -d /usr/local/nagios -s /sbin/nologin nagios
先安装 nagios-plugin: tar zxvf nagios-plugins-1.4.12.tar.gz cd nagios-plugins-1.4.12 ./configure --prefix=/usr/local/nagios make make install
再安装 NRPE:
tar zxvf nrpe-2.12.tar.gz cd nrpe-2.12 ./configure make all make install-plugin make install-daemon make install-daemon-config
chown -R nagios:nagios /usr/local/nagios
配置 NRPE:
vi /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=127.0.0.1, $Nagios监控平台的地址或域名
启动 NRPE 守护进程:
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
可以将此命令加入 /etc/rc.local ,以便开机自动启动。
检查 NRPE 是否正常:
在被监控主机上
/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
在监控平台上
/usr/local/nagios/libexec/check_nrpe -H $目标主机地址
都应该可以输出 NRPE 的版本: NRPE v2.12
在被监控端的 nrpe.cfg 文件中,可以看到这样的配置:
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
这是用来检查 CPU 负载的。
这样,就可以在监控平台上定义如下服务来监控被监控端的 CPU 负载了:
define service{ host_name remotehost service_description check_load ... check_command check_nrpe!check_load }
引用文档: