Fast Oracle 12c Installation on Linux with RPMs (1/2)

Installing Oracle Software is boring!
Obviously, if you use Oracle Linux, you know about oracle-validated, oracle-rdbms-server-11gR2-preinstall and oracle-rdbms-server-12cR1-preinstall RPMs which create users, set parameters and install the required packages… Still!

Once the prerequisites are fulfilled, installing Oracle Software requires you to
(1)upload the distribution to a staging location, (2) run the installer, (3) apply the « latest » PSU and (4) run the root.sh script. Obviously you can use Oracle cloning feature to speed-up the job. What about doing all this in one go?

The first part of this article explains how the whole installation process can be automated on Oracle Linux 6 x86_64 by creating a single RPM. Once the RPM built, the 2nd part of the article will be explaining how to create your own YUM repository so that the install can be as simple as a yum install command.

A few questions before you begin

 
Before you rush on the technical section of this article, there are a few questions, you might want to consider.
Question: Why hasn’t this been done before?
For most part, there is nothing new with this method. People have been using it for a couple of years now even if there is little on the Internet on the subject. By the way, it’s worth mentioning the most interesting blog post on the matter by Martin Bach[1]! Still not convinced? If you’re familiar with Oracle, you’ve already noticed Oracle XE is available as a RPM! However, with Oracle/Redhat Linux 5, this method was not as easy to use as it is with Oracle Linux 6 x86_64. That’s because up to RPM 4.6[2] and on Linux 32bits, RPM file size is limited to 2GB. On Oracle Linux 6 x86_64 which embarks RPM 4.8, it works fine.
Question: Why not provide the RPM for RHEL or Suse?
It is possible to do the same with RHEL and Suse that are supported by Oracle. However, because there is no oracle-rdbms-server-12cR1-preinstall RPM on those platforms that would require you build a RPM to make sure the prerequisites are met. Even if it’s no big deal, it is beyond the scope of this article. Another reason is that Oracle Linux is gaining momentum to run Oracle Software: it provides a single point of support, it’s usually less expensive and it adds value to the platform with UEK2 and KSplice.
Question: What are the cons with this method?
Unfortunately, the method isn’t a panacea. There are several reasons why you would/could prefer to use the regular installer. Reason #1 is when you want to use some advanced configuration including ASM or Grid Infrastructure. In this case, you will need to set some configuration parameters at install time and it makes the RPM method of little or no interest. Another issue is the location of the distribution on servers that can host several RDBMS (see section called “Step 2 – About the HOME, BASE and Inventory”). Last but not least you might be concerned with the way RPM manages updates. But in many ways, this method is very efficient, especially if you mix it with virtualized environments like OracleVM.
Question: Can you get the project code?
Yes. I plan to publish the project code on a public Git repository at some point with a GPL license. It still requires some work to make the build process go smoothly (there are a few known issues) and document the tool. If you’re interested, feel free to contact me twitter @ArKZoYd; I’ll share it with you, if you agree to provide your feedback. Obviously, we can also build some specific RPMs for you but that’s another story

Step 1 – Oracle Software Clone

 

The fastest way to install an Oracle Database Software is by cloning. It allows to provide the exact distribution you need with the right PSU. In order to build a clone, all you need is to perform a regular Installation with your method of choice. Once done, remove the log files from the software home and create a compressed tarball, like below:

cd $ORACLE_HOME
rm install/make.log
rm install/*.log
rm cfgtoollogs/oui/*.log
rm cfgtoollogs/cfgfw/*.log
cd ..
sudo tar -zcvf oracledb-ee-121010.tar.gz db_1

Note:
In this procedure, we assume the ORACLE_HOME ends with the db_1 subdirectory. If that’s not the case, change the script above accordingly and change the curloc macro in the rpmbuild specification file. It’s also worth noticing that what you install, including the edition and the embedded languages are part of the clone. This article assumes that’s an Oracle Database 12.1.0.1 Enterprise Edition that has been installed.

Step 2 – About the HOME, BASE and Inventory

Here comes the bad part of the story… RPMs should not take any parameter to install. You might come up with some workarounds including the use of the –prefix parameter to change the software location, like you’ll see Below. However one of RPM’s fundamental principles is that to be useful it should work without any parameters. The result is that you’ll have to make some assumption and they will be included in the distribution. That’s why you can probably only distribute those for a one-only organization. In the specification file of this example, you’ll assume the following:

  • INVENTORY_LOC=/u01/app/oraInventory
  • ORACLE_BASE=/u01/app/oracle
  • ORACLE_HOME=$ORACLE_BASE/product/12.1.0/db_1

Those values are defined as macros in the file so you can easily change them for a particular distribution. However, you might want to fix them organization-wide.

Step 3 – Rpmbuild Specification File

 

The next step consists in creating a specification file, called oracledb-ee-121010.spec, so that you can use it with rpmbuild to build the RPM. This is the content of that file, you can create it anywhere:

%define curloc db_1
%define inventory /u01/app/oraInventory
%define base /u01/app/oracle
%define home product/12.1.0/db_1
Name: oracledb-ee-121010
Version: 0.8
Release: 1.ol6
Summary: Oracle Database 12.1.0.1 in a RPM
Vendor: Oracle Corp.
Group: Applications/Databases
License: Commercial
URL: http://www.oracle.com
Source0: oracledb-ee-121010.tar.gz
BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
Prefix: %{base}
Requires: oracle-rdbms-server-12cR1-preinstall
AutoReqProv: no
%description
Oracle Database 12.1.0.1 Enterprise Edition is Oracle Flagship Database Server.
The release included in this RPM requires you have purchased the appropriate
License from Oracle.
%prep
%setup -q -n %{curloc}
%pre
curdir=`pwd`
rdir=`echo "$RPM_INSTALL_PREFIX" |cut -d'/' -f 1-2`;
if [ "$rdir" != "/u01" ]; then
roots="/u01 and $rdir"
else
roots="/u01"
fi
if [ ! -d "/u01" ] || [ ! -d "$rdir" ]; then
echo "$roots must exist to install the RPM"
exit 1
else
dsize=`df -Pk $rdir |tail -n 1|awk '{print $4}'`
if [ "$dsize" -lt "6400000" ]; then
echo "$rdir must contain at least 6.4GB to install"
exit 1
fi
fi
if [ ! -f "/etc/oraInst.loc" ]; then
echo "inventory_loc=%{inventory}" >/etc/oraInst.loc;
echo "inst_group=oinstall" >>/etc/oraInst.loc;
mkdir -p %{inventory};
chown oracle:oinstall %{inventory}/..;
chown oracle:oinstall %{inventory};
chmod 664 /etc/oraInst.loc;
fi
if [ ! -d "$RPM_INSTALL_PREFIX" ]; then
mkdir -p $RPM_INSTALL_PREFIX
chown oracle:oinstall $RPM_INSTALL_PREFIX
fi
cd $RPM_INSTALL_PREFIX
for i in `echo "%{home}"| tr '/' 'n'`; do
if [ ! -d "$i" ]; then
mkdir $i
chown oracle:oinstall $i
cd $i
fi
done
cd $curdir
%post
curdir=`pwd`
chown oracle:oinstall $RPM_INSTALL_PREFIX
cd $RPM_INSTALL_PREFIX
for i in `echo "%{home}"| tr '/' 'n'`; do
chown oracle:oinstall $i
cd $i
done
cd $curdir
echo "" > /var/log/oracle.log
chown oracle:oinstall /var/log/oracle.log
su - oracle -c "cd $RPM_INSTALL_PREFIX/%{home}/clone/bin; perl clone.pl ORACLE_BASE=$RPM_INSTALL_PREFIX ORACLE_HOME=$RPM_INSTALL_PREFIX/%{home} DECLINE_SECURITY_UPDATES=true" >> /var/log/oracle.log
$RPM_INSTALL_PREFIX/%{home}/root.sh >> /var/log/oracle.log
%build
mkdir -p $RPM_BUILD_ROOT%{prefix}/%{home}
mv * $RPM_BUILD_ROOT%{prefix}/%{home}
%install
%clean
rm -rf %{buildroot}
%files
%defattr(-,oracle,dba,-)
%{prefix}/%{home}/*
%changelog
* Tue Jul 23 2013 Gregory Guillou 0.8
- Package for Oracle 12c R1

For more information about how to build a RPM, read “Maximum RPM” by Edward C. Bailey on rpm.org[4]. However, below are a few comments about this file:

  • oracle owner and groups are hardcoded as it is the case with the oracle-rdbms-server-12cR1-preinstall RPM
  • curloc, inventory, base and home are macros. They are set at the beginning of the file so that you can easily change them to match your environment.
  • Here are a few notes about the header section:
    • Source0 defines the location of your database clone. Its name should be oracledb-ee-121010.tar.gz and it should be located in the ~/rpmbuild/SOURCES directory of your Oracle Linux server
    • The oracle-rdbms-server-12cR1-preinstall is mandatory for the RPM to be created. That’s why this program will only work with Oracle Linux and not RHEL
    • The Prefix allows to change the ORACLE_BASE and by it the ORACLE_HOME at install time. However that’s an optional parameter
    • AutoReqProv: no prevents the system from checking the required RPMs automatically.
  • The %prep section changes the distribution name to %curloc as the name of the directory containing the Oracle distribution in the oracledb-ee-121010.tar.gz file
  • The %build section move the content of the BUILD Directory to the BUILDROOT directory
  • The %file section defines that all the files from the BUILDROOT should be copied to the RPM and installed on the server with oracle:dba for owner.
  • The %pre section ensures there is enough space on the server and creates the inventory if it doesn’t exist yet
  • The %post section performs the cloning and runs root.sh

Step 4 – Here Comes the RPM

In order to build the RPM, one must put the oracledb-ee-121010.tar.gz file in the /home/oracle/rpmbuild/SOURCES directory of your server and run the rpmbuild -bb oracledb-ee-121010.spec command, as below:

time rpmbuild -bb oracledb-ee-121010.spec
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.NE5Ehu
+ umask 022
+ cd /home/oracle/rpmbuild/BUILD
+ cd /home/oracle/rpmbuild/BUILD
+ rm -rf db_1
+ /usr/bin/gzip -dc /home/oracle/rpmbuild/SOURCES/oracledb-ee-121010.tar.gz
+ /bin/tar -xf -
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd db_1
+ /bin/chmod -Rf a+rX,u+w,g-w,o-w .
+ exit 0
Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.nWj1c5
+ umask 022
+ cd /home/oracle/rpmbuild/BUILD
+ cd db_1
+ mkdir -p /home/oracle/rpmbuild/BUILDROOT/oracledb-ee-121010-0.8-1.ol6.x86_64/u01/app/oracle/product/12.1.0/db_1
+ mv OPatch [...] /home/oracle/rpmbuild/BUILDROOT/oracledb-ee-121010-0.8-1.ol6.x86_64/u01/app/oracle/product/12.1.0/db_1
+ exit 0
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.NcQDaG
+ umask 022
+ cd /home/oracle/rpmbuild/BUILD
+ cd db_1
+ /usr/lib/rpm/brp-compress
+ /usr/lib/rpm/brp-strip
+ /usr/lib/rpm/brp-strip-static-archive
+ /usr/lib/rpm/brp-strip-comment-note
Processing files: oracledb-ee-121010-0.8-1.ol6.x86_64
Checking for unpackaged file(s): /usr/lib/rpm/check-files /home/oracle/rpmbuild/BUILDROOT/oracledb-ee-121010-0.8-1.ol6.x86_64
Wrote: /home/oracle/rpmbuild/RPMS/x86_64/oracledb-ee-121010-0.8-1.ol6.x86_64.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.rZC3Vf
+ umask 022
+ cd /home/oracle/rpmbuild/BUILD
+ cd db_1
+ rm -rf /home/oracle/rpmbuild/BUILDROOT/oracledb-ee-121010-0.8-1.ol6.x86_64
+ exit 0
real 18m1.939s
user 15m1.701s
sys 2m26.325s

The RPM is created in the /home/oracle/rpmbuild/RPMS/x86_64 directory. You’ll find some of its metadata by running the command below:

rpm -qip ~/rpmbuild/RPMS/x86_64/oracledb-ee-121010-0.8-1.ol6.x86_64.rpm
Name : oracledb-ee-121010 Relocations: /u01/app/oracle
Version : 0.8 Vendor: Oracle Corp.
Release : 1.ol6 Build Date: Tue 23 Jul 2013 08:49:53 PM CEST
Install Date: (not installed) Build Host: sage.easyteam.fr
Group : Applications/Databases Source RPM: oracledb-ee-121010-0.8-1.ol6.src.rpm
Size : 5063616673 License: Commercial
Signature : (none)
URL : http://www.oracle.com
Summary : Oracle Database 12.1.0.1 in a RPM
Description :
Oracle Database 12.1.0.1 Enterprise Edition is Oracle Flagship Database Server.
The release included in this RPM requires you have purchased the appropriate
License from Oracle.

Step 5 – Testing the RPM

 

Last but not least, you should test the RPM on your server. In order to proceed, delete the previous installation and run different scenarios, assuming this is a test server and no Oracle Software was installed on it before:

  • Test #1: Install Oracle in its default location
sudo su -
rm -f /etc/oraInst.loc
rm -rf /u01/app
cd /home/oracle/rpmbuild/RPMS/x86_64/
rpm -ivh oracledb-ee-121010-0.8-1.ol6.x86_64.rpm
        Preparing... ########################################### [100%]
1:oracledb-ee-121010 ########################################### [100%]

su - oracle
export ORACLE_HOME=/u01/app/oracle/product/12.1.0/db_1
export PATH=$ORACLE_HOME/bin:$PATH
cd $ORACLE_HOME/OPatch
./opatch lsinv
Oracle Home : /u01/app/oracle/product/12.1.0/db_1
Central Inventory : /u01/app/oraInventory
from : /u01/app/oracle/product/12.1.0/db_1/oraInst.loc
OPatch version : 12.1.0.1.0
OUI version : 12.1.0.1.0
Log file location :opatch2013-07-23_21-11-08PM_1.log
Lsinventory Output file location :lsinventory2013-07-23_21-
11-08PM.txt
--------------------------------------------------------------------------------
Installed Top-level Products (1):
Oracle Database 12c 12.1.0.1.0
There are 1 products installed in this Oracle Home.
There are no Interim patches installed in this Oracle Home.
--------------------------------------------------------------------------------
OPatch succeeded.
  • Test #2: Install a relocated Oracle Software
sudo su -
yum -y erase oracledb-ee-121010-0.8-1.ol6.x86_64
Loaded plugins: security
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package oracledb-ee-121010.x86_64 0:0.8-1.ol6 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
==========================================================================
Package Arch Version Repository Size
==========================================================================
Removing:
oracledb-ee-121010 x86_64 0.8-1.ol6 installed 4.7 G
Transaction Summary
==========================================================================
Remove 1 Package(s)
Installed size: 4.7 G
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Erasing : oracledb-ee-121010-0.8-1.ol6.x86_64 1/1
Verifying : oracledb-ee-121010-0.8-1.ol6.x86_64 1/1
Removed:
oracledb-ee-121010.x86_64 0:0.8-1.ol6
Complete!

rm -f /etc/oraInst.loc
rm -rf /u01/app
rm -rf /u02/app
mkdir /u02
chown oracle:oinstall /u02
rpm -ivh oracledb-ee-121010-0.8-1.ol6.x86_64.rpm --prefix=/u02/app/oracle
        Preparing... ########################################### [100%]
1:oracledb-ee-121010 ########################################### [100%]

su - oracle
export ORACLE_HOME=/u02/app/oracle/product/12.1.0/db_1
export PATH=$ORACLE_HOME/bin:$PATH
cd $ORACLE_HOME/OPatch
./opatch lsinv
Oracle Interim Patch Installer version 12.1.0.1.0
Copyright (c) 2012, Oracle Corporation. All rights reserved.
Oracle Home : /u02/app/oracle/product/12.1.0/db_1
Central Inventory : /u01/app/oraInventory
from : /u02/app/oracle/product/12.1.0/db_1/oraInst.loc
OPatch version : 12.1.0.1.0
OUI version : 12.1.0.1.0
Log file location :opatch2013-07-23_21-17-14PM_1.log
Lsinventory Output file location :lsinv/lsinventory2013-07-23_21-17-14PM.txt
--------------------------------------------------------------------------------
Installed Top-level Products (1):
Oracle Database 12c 12.1.0.1.0
There are 1 products installed in this Oracle Home.
There are no Interim patches installed in this Oracle Home.
--------------------------------------------------------------------------------
OPatch succeeded.

Step 6 – It Ain’t Over Yet

One serious concern is *always* security. Consider signing your RPMs with PGP keys.
Once done, you should be able to deploy your database installation in a YUM repository. That’s the subject of the 2nd Part of this article…

Bibliography:

[1] Provision Oracle RDBMS software via RPM, Martin Bach on December 13, 2011
[2] RPM 4.6.0 Release Notes
[3] Passing user defined argument to RPM is possible while installing? on Stackoverflow.com
[4] Maximum RPM

4 réflexions sur “Fast Oracle 12c Installation on Linux with RPMs (1/2)”

  1. Ping : Cloning Oracle Database Home 12.1.0.2 on new Oracle Linux machine | Pierre blog

  2. Gregory Guillou

    Hey Gleb,
    It looks like your doing good. You are obviously right and the 1st one to read the article afaik. tty
    -Gregory

  3. Awesome article Gregory! I am definitely going to use it. Only one thing. Maybe I am wrong but the step:
    sudo tar -zcvf db_1 oracledb-ee-121010.tar.gz
    should be like:
    sudo tar -zcvf oracledb-ee-121010.tar.gz db_1

  4. Ping : #DB12c by Gregory Guillou : Fast Oracle 12c Installation on Linux with RPMs – Part 1 | Database Scene

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *