Anda di halaman 1dari 4

Install Oracle Instant Client and DBDOracle perl modules

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

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,
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.

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:

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)

Install Oracle Instant Client and DBDOracle perl modules in Linux.

pag. 1


Configure and test Oracle Instant client.

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: and DBD::Oracle
We can install 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

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


From this directory compile and install:

perl Makefile.PL
make install

Install Oracle Instant Client and DBDOracle perl modules in Linux.

pag. 2


Make must find oracle libraries and compile and install correctly.
At this point can be interesting to add library paths to /etc/ Example paths:

We can now test nagios perl plugins for Oracle or another perl script to connect to Oracle. Try with
this script copied from
# TO CHANGE VARIABLES IN -> sub declareGlobalVariables
require "";
require "";
use DBI;
$dbh = &getOracleLogin("$ORACLE_SID", "$ORACLE_USERID", "$ORACLE_PASSWORD");
$dbh->{LongReadLen} = 64000;
# +--------------+
# +--------------+
sub declareGlobalVariables {
= "user";
= "pass";
= "/usr/lib/oracle/11.2/client641";
sub printHeader {
print "\n";
print "Running\n";
print "\n";
sub printFooter {
print "Ending\n";
print "\n";
sub getOracleLogin {
local ($oracle_sid, $username, $password) = @_;
local ($temp_dbh);

Install Oracle Instant Client and DBDOracle perl modules in Linux.

pag. 3


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");
print "
return $temp_dbh;
sub logoffOracle {
($dbh) = @_;
print " (*) Attempting Oracle Logoff ...\n";
unless ($dbh->disconnect) {
print "

You can download script from here.

Install Oracle Instant Client and DBDOracle perl modules in Linux.

pag. 4