nagios check_oracle_health

2014-04-11

check_oracle_health is a plugin to check various parameters of an Oracle database

1、nagios提供一个shell脚本check_oracle用来监测oracle,但是更复杂的监测还需配置check_oracle_health.
http://labs.consol.de/download/shinken-nagios-plugins/check_oracle_health-1.9.3.4.tar.gz
tar zxvf check_oracle_health-1.9.3.4.tar.gz
cd check_oracle_health-1.9.3.4
./configure;make;make install
参考文档:
http://labs.consol.de/lang/en/nagios/check_oracle_health/

2、为了连接Oracle,需要配置oracle参数,远程简单化,可以用instantclient代替,如果在oracle数据库上配置监测,没有必要
instantclient-basic-linux.x64-11.2.0.4.0.zip
instantclient-sdk-linux.x64-11.2.0.4.0.zip
instantclient-sqlplus-linux.x64-11.2.0.4.0.zip
cd /;unzip *.zip
###########################################
vi ~/.bash_profile增加
export PATH=$PATH:/instantclient_11_2
export LD_LIBRARY_PATH=/instantclient_11_2
export ORACLE_HOME=/instantclient_11_2
export NLS_LANG=AMERICAN_CHINA.ZHS16GBK
export TNS_ADMIN=/instantclient_11_2
alias lsqlplus='rlwrap sqlplus /nolog'

3、check_oracle_health是Perl脚本,为了使用check_oracle_health,需要安装perl-DBI,perl-DBD-oracle
perl-DBI可以用yum安装
yum install perl-DBI (perl-DBD-mysql )
或者下载
wget http://search.cpan.org/CPAN/authors/id/T/TI/TIMB/DBI-1.631.tar.gz
#tar -zxvf DBI-1.631.tar.gz
#cd DBI-1.631
#perl Makefile.PL
#make all
#make install

perl-DBD-oracle安装需要提前配置好oracle客户端环境
wget http://www.cpan.org/authors/id/P/PY/PYTHIAN/DBD-Oracle-1.70.tar.gz
tar zxf DBD-Oracle-1.70.tar.gz
perl Makefile.PL
make;make install

4、为了使用sqlplus,可以安装rlwrap
wget http://utopia.knoware.nl/~hlub/rlwrap/rlwrap-0.37.tar.gz
tar zxf rlwrap-0.37.tar.gz
cd rlwrap-0.37
./configure --prefix=/usr
make;make install

5、配置/instantclient_11_2/tnsnames.ora
DB01 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.10.1)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = backupdb)
)
)

6、实例:
./check_oracle_health --connect DB01 --mode tnsping
./check_oracle_health --connect DB01 --username system --password 123456 --mode list-tablespaces
./check_oracle_health --connect DB01 --username system --password 123456 --mode latch-waiting --name 'user lock'
./check_oracle_health --connect DB01 --username system --password 123456 --mode tablespace-usage --name SYSTEM
./check_oracle_health --connect DB01 --username system --password 123456 --mode tablespace-free --name USERS
./check_oracle_health --mode pga-in-memory-sort-ratio
./check_oracle_health --mode sga-shared-pool-free

7、oracle也可以创建nagios监测专用账户
CREATE USER nagios IDENTIFIED BY oraclemon;
GRANT CREATE SESSION TO nagios;
GRANT SELECT any dictionary TO nagios;
GRANT SELECT ON V_$SYSSTAT TO nagios;
GRANT SELECT ON V_$INSTANCE TO nagios;
GRANT SELECT ON V_$LOG TO nagios;
GRANT SELECT ON SYS.DBA_DATA_FILES TO nagios;
GRANT SELECT ON SYS.DBA_FREE_SPACE TO nagios;

 

8、数据库nrpe.cfg配置实例

command[check_oracle_health_soft]=/usr/local/nagios/libexec/check_oracle_health --connect=prod --user=nagios --password=oradbmon --mode=soft-parse-ratio
command[check_oracle_health_tnsping]=/usr/local/nagios/libexec/check_oracle_health --connect=prod --user=nagios --password=oradbmon --mode=tnsping
command[check_oracle_health_tbs]=/usr/local/nagios/libexec/check_oracle_health --connect=prod --user=nagios --password=oradbmon --mode=tablespace-usage
command[check_oracle_health]=/usr/local/nagios/libexec/check_oracle_health --connect=你oracle的SID --user=oracle用户 --password=oracle密码 --mode=tablespace-usage

9、nagios配置实例

/usr/local/nagios/libexec/check_nrpe -H 你的被监控机IP地址 -c check_oracle_health
/usr/local/nagios/libexec/check_nrpe -H 192.168.10.10 -c check_oracle_health_tnsping
/usr/local/nagios/libexec/check_nrpe -H 192.168.10.10 -c check_oracle_health_tbs

define service{
use                     generic-service
host_name               172.10.1.019
service_description     tnsping
check_command              check_nrpe!check_oracle_health_tnsping
}

10、常见问题

1)CRITICAL - cannot connect to DB01. install_driver(Oracle) failed: Can't load '/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/DBD/Oracle/Oracle.so' for module DBD::Oracle: libclntsh.so.10.1: cannot open shared object file: No such file or directory at /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/DynaLoader.pm line 230.

将nagios用户添加组oinstall

[root@server74 ~]# usermod -G oinstall nagios

[root@server74 ~]# id nagios
uid=502(nagios) gid=503(nagios) groups=503(nagios),500(oinstall)

2)libnnz10.so: cannot restore segment prot after reloc: Permission denied

chcon -t texrel_shlib_t  $ORACLE_HOME/lib/libnnz10.so
chcon -t texrel_shlib_t  $ORACLE_HOME/lib/libclntsh.so.10.1

3) setenforce 0

setenforce: SELinux is disabled

4)/etc/ld.so.conf添加$ORACLE_HOME/lib(一般此步骤非必须)

执行ldconfig

分类:Linux操作系统 | 标签: |

相关日志

评论被关闭!