Just start from your heart.
分类: Oracle
2015-03-02 14:45:40
tar zxvf nagios-plugins-1.4.14.tar.gz
cd nagios-plugins-1.4.14
./configure
make
make install
1.2 添加nagios用户和组
groupadd nagios
useradd -g nagios -s /sbin/nologin nagios
1.3 在被监控机上安装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
1.4修改nrpe的配置文件
vim /usr/local/nagios/etc/nrpe.cfg
#nrpe_user=nagios
nrpe_user=oracle ---以oracle用户运行
allowed_hosts=127.0.0.1,192.169.1.22 --添加监控允许IP
1.5修改check_oracle插件脚本
vim /usr/local/nagios/libexec/check_oracle
添加两行
#! /bin/sh
#
# latigid010@yahoo.com
# 01/06/2000
#
# This Nagios plugin was created to check Oracle status
#
ORACLE_HOME=/sfb/db/oracle/product/11.2.0/dbhome_1
PATH=$ORACLE_HOME/bin:$PATH
vim +257 /usr/local/nagios/libexec/check_oracle
257 ON a.tablespace_name=b.tablespace_name WHERE a.tablespace_name=upper('${5}');---方便监控
1.6 被监控机上配置 nrpe 服务
修改 /usr/local/nagios/etc/nrpe.cfg 文件。加入以下内容:
#Check Oracle
command[check_oracle_tns]=/usr/local/nagios/libexec/check_oracle –tns orcl
command[check_oracle_db]=/usr/local/nagios/libexec/check_oracle –db orcl
command[check_oracle_login]=/usr/local/nagios/libexec/check_oracle –login orcl
command[check_oracle_cache]=/usr/local/nagios/libexec/check_oracle –cache orcl system lkjsdf 80 90
command[check_oracle_tablespace]=/usr/local/nagios/libexec/check_oracle –tablespace orcl system lkjsdf tab 90 80
1.7 启动被监控机上的nrpe
启动 NRPE 守护进程:
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
将此命令加入 /etc/rc.local ,以便开机自动启动。
echo "/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
查看相应的端口:netstat -an |grep 5666
防火墙开启5666 允许局域网IP或固定IP连接
在监控主机上
/usr/local/nagios/libexec/check_nrpe -H 192.168.1.222 $目标主机地址(被监控端地址)
都应该可以输出 NRPE 的版本: NRPE v2.12
cd /usr/local/nagios/etc/objects/
vim oracle.cfg
define host {
use linux-server
host_name oracle
alias Oracle 11g
address 192.168.1.123
}
define service {
use generic-service
host_name oracle
service_description TNS Check
check_command check_nrpe!check_oracle_tns
}
define service {
use generic-service
host_name oracle
service_description DB Check
check_command check_nrpe!check_oracle_db
}
define service {
use generic-service
host_name oracle
service_description Login Check
check_command check_nrpe!check_oracle_login
}
define service {
use generic-service
host_name oracle
service_description Cache Check
check_command check_nrpe!check_oracle_cache
}
define service {
use generic-service
host_name oracle
service_description Tablespace Check
check_command check_nrpe!check_oracle_tablespace
}
2.2 把oracle.cfg添加到nagios主机:
echo "cfg_file=/usr/local/nagios/etc/objects/oracle.cfg" >> /usr/local/nagios/etc/nagios.cfg
2.3 检查nagios的配置文件并重新启动nagios
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
重启nagios
service nagios restart