Você está na página 1de 4

Install Oracle Instant Client and DBDOracle perl modules

in Linux (Redhat, Centos, Debian,Ubuntu).


Introduction.
There are many plugins for Nagios for the purpose of monitoring Oracle, from simple tnsping to
monitor listener response to various possibilities to monitor the status of tablespaces, instances,
disks,...
When we address the need to use Oracle plugins we will always find two possibilities: locally
execution (in Oracle server) by a nagios client/agent (NRPE, NSClient + +,) or execution from
the Nagios server itself. If we opt for latter, its required to install an Oracle client on the Nagios
server, ideally Oracle Instant Client which is lighter than the full client. Besides this, most plugins
are written in Perl, so you need the Perl modules needed for these to work. In this post we are going
to talk about the installation and configuration of Oracle Instant Client and usually required Perl
modules. Although focused for distributions Redhat / CentOS also mention how to install on Debian
type Linux.

Install
We are going yo test with Oracle Instant Client 12. Software client can be downloaded from Oracle.
If you have not an Oracle account, you need register one previously. We must download packages
basic, sqlplus and devel. For Oracle client 12 in Redhat / Centos there are RPM packages
available. For Debian / Ubuntu we can convert packages from rpm format to deb format with
alien tool.
Example packages version to download:
oracle-instantclient12.1-basic-12.1.0.1.0-1.x86_64
oracle-instantclient12.1-sqlplus-12.1.0.1.0-1.x86_64
oracle-instantclient12.1-devel-12.1.0.1.0-1.x86_64.rpm

To install RMPs en Redhat / Centos:


yum localinstall oracle* --nogpgcheck

Libaio package will be installed by dependences.


To install in Debian / Ubuntu we must install dependencies previously and convert packages to
rpm format:
apt-get install libaio-dev libaio1
alien --scripts *.rpm
dpkg -i *.deb

This basic packages install create next directories:


/usr/lib/oracle/12.1/client64/bin (sqlplus)
/usr/lib/oracle/12.1/client64/lib (basic)
/usr/share/oracle/12.1 (devel)

http://www.aboutmonitoring.com/

Install Oracle Instant Client and DBDOracle perl modules in Linux.


pag. 1

20/04/14

Configure and test Oracle Instant client.


Tnsnames.ora
After install packages we must create tnsnames.ora file to connect remote systems using Oracle
tnsnames services. We must create a directory in standard oracle path:
mkdir /usr/lib/oracle/12.1/client64/network/admin -p
and create or copy from Oracle server your tnsnames into.
Environment variables
We need add in user home .bash_profile the correct environment variables. Next are the classical
and requires variables.
export PATH=$PATH:$HOME/bin:/usr/lib/oracle/12.1/client64/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/oracle/12.1/client64/lib
export ORACLE_HOME=/usr/lib/oracle/12.1/client64
export TNS_ADMIN=$ORACLE_HOME/network/admin
Login with user and test connect to Oracle server with sqlplus:
#sqlplus user@tnsnames_service

Install perl libraries for Oracle DBD.


We need now install and compile necessary perl libraries for use from perl scripts to connect to
Oracle. Are needed libraries: DBI.pm and DBD::Oracle
We can install DBI.pm from Operating System packages (prefered) or with CPAN.
Redhat / Centos
yum install perl-DBI

Debian / Ubuntu:
apt-get install libdbi-perl

Or with CPAN:
cpan> install DBI.pm

DBD::Oracle. Problem is this library. It's necessary download library source package and compile.
This perl library need use installed oracle libraries. Correct steps are:
1.- Oracle client or instant client installed and tested with tnsnames (environment variables
configured). CPAN is going to use this environment variables to find and oracle modules to
compile perl library.
2.- CPAN installed (yum install cpan)
3. With CPAN we must download DBD module
cpan> get DBD::Oracle

Downloaded modules must be in home user in .cpan/build/DBD-Oracle-v.vv-xxxx


4.

From this directory compile and install:

perl Makefile.PL
make
make install

http://www.aboutmonitoring.com/

Install Oracle Instant Client and DBDOracle perl modules in Linux.


pag. 2

20/04/14

Make must find oracle libraries and compile and install correctly.
At this point can be interesting to add library paths to /etc/ld.so.conf.d. Example paths:
/usr/local/lib64/perl5/auto/DBD
/usr/lib/oracle/12.1/client64/lib

We can now test nagios perl plugins for Oracle or another perl script to connect to Oracle. Try with
this script copied from http://www.idevelopment.info/
#!/usr/bin/perl
# TO CHANGE VARIABLES IN -> sub declareGlobalVariables
require "ctime.pl";
require "flush.pl";
use DBI;
&declareGlobalVariables;
&printHeader;
$dbh = &getOracleLogin("$ORACLE_SID", "$ORACLE_USERID", "$ORACLE_PASSWORD");
$dbh->{LongReadLen} = 64000;
&logoffOracle($dbh);
&printFooter;
exit;
# +--------------+
# | SUB ROUTINES |
# +--------------+
sub declareGlobalVariables {
# Change SID, USERID, PASSWORD and HOME!
$ORACLE_SID
= "SID_IN_TNSNAMES";
$ORACLE_USERID
= "user";
$ORACLE_PASSWORD
= "pass";
$ENV{'ORACLE_SID'}
= "$ORACLE_SID";
$ENV{'ORACLE_HOME'}
= "/usr/lib/oracle/11.2/client641";
}
sub printHeader {
print "\n";
print "Running testDBDOracle.pl...\n";
print "\n";
}
sub printFooter {
print "Ending testDBDOracle.pl...\n";
print "\n";
}
sub getOracleLogin {
local ($oracle_sid, $username, $password) = @_;
local ($temp_dbh);

http://www.aboutmonitoring.com/

Install Oracle Instant Client and DBDOracle perl modules in Linux.


pag. 3

20/04/14

local($tempID, $tempPassword, $tempKey);


print " (*) Attempting Oracle Login ...\n";
unless ( $temp_dbh = DBI->connect( "DBI:Oracle:$oracle_sid"
, "$username"
, $password
, {AutoCommit => 0}) ) {
&programError( "Oracle Login Failed as $username"
, ""
, "$DBI::errstr"
, "dba-mail"
, "dba-pager");
exit;
}
print "
OK\n\n";
return $temp_dbh;
}
sub logoffOracle {
($dbh) = @_;
print " (*) Attempting Oracle Logoff ...\n";
unless ($dbh->disconnect) {
1;
}
print "
OK\n\n";
}

You can download testOracleConnect.py script from here.

http://www.aboutmonitoring.com/

Install Oracle Instant Client and DBDOracle perl modules in Linux.


pag. 4

20/04/14

Você também pode gostar