Installing Oracle 11g inside an Xubuntu Linux VMWare Image

December 11, 2008 - zenoconsultingzenoconsulting


In this entry, I'm going to show you how to install Oracle 11g on Xubuntu 8.10 inside a VMWare image.

Introduction

You may be a developer that has to use Oracle. You need to write and test your data access layer.1 Having a portable instance of Oracle around is very handy for this. Why install it on a portable VMWare image?

  • Oracle is a beast — it eats up lots of system resources unless you explicitly shut it down. That said, I prefer not to install it locally for this very reason, and because I don't like corrupting my development machines with unnecessary infrastructure software.
  • You may want to run Oracle on a separate box on the network and have your development machine smack it over the network instead of at localhost. This gives your local machine even more resources, and will likely be a more realistic deployment scenario.
  • You don't want to be at the mercy of IT/DBA staff when it comes to troubleshooting problems with the database/code. If you test against a development database that is maintained by staff…they may decide to give you limited access to it. With this approach, you have complete control over Oracle, and you have all the tools you need to troubleshoot any issue.
  • If the database or the OS somehow gets corrupted, you can throw it in the trash, open a clean image, and re-import your data, and you are ready to go again.
  • Its portable; I can run it locally on the same host OS or I can run it on another machine (either a Linux or Windows host).
  • I can share the image with other team members via network file share or DVD
  • When I'm done with it I shut down VMWare Player and say good bye until I need it again
  • When I need it again I start VMWare Player — and the state can re-appear (e.g. like hibernate/sleep mode). This means I don't have to reboot the OS everytime and wait for it.
  • When I no longer want Oracle, I throw the image in the trash…no un-installation necessary.

You may be wondering why VMWare and not something like Virtual Box? Simply because I like VMWare and it works and I'm happy with it. If you want to do it with Virtual Box, I'm sure you could. Why Oracle? Simply because that is the DBMS I have had to use on several projects. I'm sure you can do the same with any DBMS. Why Xubuntu? Because I like Ubuntu/Debian flavored Linux, and it has the lightest weight X-Windows framework (xfce). I'm sure you could get Oracle installed on a UNIX variant that does not contain a windowing system, but this is just easier. As far as I know, the Oracle installer cannot run headless. Once you get it installed and running, you can always choose to boot it without X or remove the X packages altogether.

What you need

Installing Xubuntu

I'm not going to spend a lot of time describing this. It is pretty simple. Fire up VMWare Fusion (or Windows equivalent) and choose New… to create a new image. Follow the screenshots below.
VMWareAssistant1.png

VMWareAssistant2.png

This screen is slightly important to get right. I'm setting the value to 20GB, but we won't immediately allocate all that on disk. This simply means we'll allow it to grow up to 20GB. You can adjust this up if you think you will be needing more space. I think on average Xubuntu default install takes a few GB and Oracle with the defaults takes several GB — in the end I think you can expect the fresh install to eat up about 7 GB, which leaves you ~13 GB for data. Later, I will show you how to compress the image down so it is more portable. Make sure you allow it to split the image across 2GB files.

VMWareAssistant3.png

Browse to the Xubuntu ISO you downloaded.

VMWareAssistant4.png

The rest of it is fairly straightforward. The defaults work fine. Go with Guided Partitioning and tell it to use up the whole disk. When it asks you to create a user, this is a good time to make the oracle user. I just make the password also oracle to make things nice and hard to forget.

Update Xubuntu

Right after you login to Xubuntu the first time, the Update Manager is likely to tell you that there are a whole lot of out-of-date packages that can be updated. Go ahead and do that…be prepared to hurry up and wait.
XubuntuUpdateManager.png

Install VMWare Tools

One thing you want to install right away is VMWare Tools. This allows nice things like drag-n-drop between your host/guest OS, as well as better mouse support for clicking in and out of the guest OS window. Choose Virtual Machine -> Install VMWare Tools from the application. This will mount a pseudo-CDROM that contains the rpm or a tar.gz of the VMWare tools package. I always use the tar.gz. Copy it to your home dir, and run the installer:

oracle@xubuntu-oracle:~$ tar -xzvf VMWareTools-7.6.3-94249.tar.gz
oracle@xubuntu-oracle:~$ cd vmware-tools-distrib/
oracle@xubuntu-oracle:~/vmware-tools-distrib$ sudo ./vmware-install.pl

Take the defaults for the perl script. This will install vmware-tools. I have noticed that installing the tools takes down the ethernet interface. You can try to restart networking sudo /etc/init.d/networking restart or just reboot. You have to restart X anyway to make the tools take effect for mouse/keyboard stuff…

Preparing Xubuntu for the Oracle Installation

Oracle won't install on Ubuntu out-of-the-box. You have to make a number of tweaks (shown below).

First, install a bunch of packages Oracle will need:

oracle@xubuntu-oracle:~$ sudo apt-get install gcc libaio1 lesstif2 lesstif2-dev make rpm libc6 libstdc++5

Let's trick the Oracle installer into thinking it is on Red Hat (supported):

oracle@xubuntu-oracle:~$ sudo vi /etc/redhat-release

The contents of this file should be

Red Hat Enterprise Linux AS release 3 (Taroon)

Now edit system configuration:

oracle@xubuntu-oracle:~$ sudo vi /etc/sysctl.conf

Append the following values to the end of that file:

# Added for Oracle
kernel.shmall = 2097152
kernel.shmmax = 2147483648
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
fs.file-max = 6553600
net.ipv4.ip_local_port_range = 1024 65000

Force a re-read of the configuration to do a sanity check.

oracle@xubuntu-oracle:~$ sudo /sbin/sysctl -p
kernel.shmall = 2097152
kernel.shmmax = 2147483648
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
fs.file-max = 6553600
net.ipv4.ip_local_port_range = 1024 65000

Edit limits.conf

oracle@xubuntu-oracle:~$ sudo vi /etc/security/limits.conf

Append the following to the end of that file:

# Added for Oracle
* soft nproc 2047
* hard nproc 16384
* soft nofile 1024
* hard nofile 65536
# End of file

Edit login

oracle@xubuntu-oracle:~$ sudo vi /etc/pam.d/login

Append the following to the end of that file:

# Added for Oracle
session required /lib/security/pam_limits.so
session required pam_limits.so

Now we have to make a bunch of symlinks to binaries where Oracle expects them:

oracle@xubuntu-oracle:~$ sudo ln -s /usr/bin/awk /bin/awk
oracle@xubuntu-oracle:~$ sudo ln -s /usr/bin/rpm /bin/rpm
oracle@xubuntu-oracle:~$ sudo ln -s /lib/libgcc_s.so.1 /lib/libgcc_s.so
oracle@xubuntu-oracle:~$ sudo ln -s /usr/bin/basename /bin/basename

Create the oracle user if you haven't done so already. I created the oracle user when I installed the OS. Now, add the proper groups.

oracle@xubuntu-oracle:~$ sudo groupadd oinstall
oracle@xubuntu-oracle:~$ sudo groupadd dba
oracle@xubuntu-oracle:~$ sudo groupadd nobody

Now make the directory where we will install Oracle

oracle@xubuntu-oracle:~$ sudo mkdir /oracle
oracle@xubuntu-oracle:~$ sudo mkdir /oracle/11g
oracle@xubuntu-oracle:~$ sudo chown -R oracle:oinstall /oracle
oracle@xubuntu-oracle:~$ sudo chmod -R 775 /oracle

Now edit /etc/profile to set the proper environment variables

oracle@xubuntu-oracle:~$ sudo vi /etc/profile

Append this to the bottom of that file

export ORACLE_BASE=/oracle
export ORACLE_HOME=/oracle/11g
export ORACLE_SID=orcl
export PATH=$ORACLE_HOME/bin:$PATH:.
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib

Now is a good time to clean out aptitude and check our disk space (appears we've used up 2.5G for Xubuntu).

oracle@xubuntu-oracle:~$ sudo apt-get clean
oracle@xubuntu-oracle:~$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              19G  2.3G   16G  13% /
tmpfs                 252M     0  252M   0% /lib/init/rw
varrun                252M  104K  252M   1% /var/run
varlock               252M     0  252M   0% /var/lock
udev                  252M  2.7M  249M   2% /dev
tmpfs                 252M     0  252M   0% /dev/shm
lrm                   252M  2.0M  250M   1% /lib/modules/2.6.27-9-generic/volatile

Now, we are ready to install Oracle.

Installing Oracle

Getting the Giant Zip File

If you installed VMWare tools, you can just drag-n-drop the Oracle .zip from your host OS to the Xubuntu desktop. If you did not install VMWare tools you can do any of the following alternatives:

  • Download the .zip from inside Xubuntu using Firefox
  • Mount a shared folder with VMWare and copy it that way
  • Use scp to copy it over

OK - drag-n-drop fails for some reason. Try setting up a shared folder. First, shut down the guest OS (this seems to help) Virtual Machine -> Shut Down Guest OS. Now edit the VM Settings.

Enable shared folders:

EnableSharedFolders.png

Add a shared folder:

AddSharedFolder.png

Just for good measure — if you distribute this VM, you want it to auto-detect the CD/DVD drive, so fix that now:

CDROM-Settings.png

OK - shared folders still won't mount this is really annoying. Go for scp

oracle@xubuntu-oracle:~$ sudo apt-get install openssh-server

Now, just scp it over. Look up the IP address of Xubuntu with ifconfig

zeno-mbp:download davisford$ scp linux_11gR1_database_1013.zip oracle@172.16.244.134:linux_11gR1_database_1013.zip
The authenticity of host '172.16.244.134 (172.16.244.134)' can't be established.
RSA key fingerprint is dd:ac:46:bb:96:9e:ec:71:c8:5b:25:d7:82:c0:a4:7a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.16.244.134' (RSA) to the list of known hosts.
oracle@172.16.244.134's password: oracle

Yay… I dunno why shared folders or drag-n-drop failed to work. They have worked for me before on other VMs I have built. If someone has a clue, please drop a comment.

Now, that we have the oracle distro, unzip it. It is large

oracle@xubuntu-oracle:~$ unzip linux_11gR1_database_1013.zip

Run the Installer

Now, push the button and cross your fingers:

oracle@xubuntu-oracle:~$ cd database
oracle@xubuntu-oracle:~/database$ ls
doc  install  README  runInstaller  stage  welcome.html
oracle@xubuntu-oracle:~/database$ ./runInstaller

So far, so good. I use the same password oracle here.
OracleInstall1.png

Next -> the installer complains about the oraInventory permissions. Change it to this directory:
OracleInstall2.png

Next you have to go through pre-requisite checks. Some of the checks may have warnings. I ignore them and proceed.
OracleInstall3.png

I skip the next screen which asks if you want to setup some kind of registration/configuration. Now it has all it needs to install.
OracleInstall4.png

Yay!
OracleInstall5.png

Now you have to run a couple of scripts as root (i.e. sudo), so go do that:
OracleInstall6.png

Finally…
OracleInstall7.png

Validat it works…

oracle@xubuntu-oracle:~$ sqlplus SYS/oracle as SYSDBA

SQL*Plus: Release 11.1.0.6.0 - Production on Thu Dec 11 01:58:47 2008

Copyright (c) 1982, 2007, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select * from scott.emp;

     EMPNO ENAME      JOB           MGR HIREDATE        SAL       COMM
---------- ---------- --------- ---------- --------- ---------- ----------
    DEPTNO
----------
      7369 SMITH      CLERK          7902 17-DEC-80        800
    20

Configuring Xubuntu to Auto-Start Oracle

Now that you've got Oracle up and running, you'd probably like it to auto-start when the OS boots. Create this file:

sudo vi /etc/init.d/oracledb

…with this content:

#!/bin/bash
#
# /etc/init.d/oracledb
#
# Run-level Startup script for the Oracle Listener and Instances
# It relies on the information on /etc/oratab

export ORACLE_BASE=/oracle
export ORACLE_HOME=$ORACLE_BASE/11g
export ORACLE_OWNR=oracle
export PATH=$PATH:$ORACLE_HOME/bin

if [ ! -f $ORACLE_HOME/bin/dbstart -o ! -d $ORACLE_HOME ]
then
   echo "Oracle startup: cannot start"
   exit 1
fi

case "$1" in
   start)
       # Oracle listener and instance startup
       echo -n "Starting Oracle: "
       su $ORACLE_OWNR -c "$ORACLE_HOME/bin/lsnrctl start"
       su $ORACLE_OWNR -c "$ORACLE_HOME/bin/dbstart"
       touch /var/lock/oracle
       echo "OK"
       ;;
   stop)
       # Oracle listener and instance shutdown
       echo -n "Shutdown Oracle: "
       su $ORACLE_OWNR -c "$ORACLE_HOME/bin/lsnrctl stop"
       su $ORACLE_OWNR -c $ORACLE_HOME/bin/dbshut
       rm -f /var/lock/oracle
       echo "OK"
       ;;
   reload|restart)
       $0 stop
       $0 start
       ;;
   *)
       echo "Usage: `basename $0` start|stop|restart|reload"
       exit 1
esac

exit 0

Next install the script to run on startup

sudo chmod a+x oracledb
sudo chown root:root oracledb
sudo update-rc.d oracledb defaults 99

Now you can use the script to do the following things

sudo /etc/init.d/oracledb stop
sudo /etc/init.d/oracledb start
sudo /etc/init.d/oracledb restart

Compressing the Image

The image with Oracle installed is now pretty huge. It won't even fit on a DVD. There are a few tricks we can do to shrink it down.

The first thing you want to do is delete the oracle zip file and the unzipped contents. You don't need them anymore. This will save several gigabytes.

Next we zero out all the unused disk bits. This will allow compression algorithms like bz2 run much more efficiently.

sudo time dd if=/dev/zero of=/tmpfile bs=10M; sudo rm /tmpfile

Ok, now let's check the disk space:

oracle@xubuntu-oracle:/etc/init.d$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              19G  7.2G   11G  41% /
tmpfs                 252M     0  252M   0% /lib/init/rw
varrun                252M  108K  252M   1% /var/run
varlock               252M     0  252M   0% /var/lock
udev                  252M  2.7M  249M   2% /dev
tmpfs                 252M  1.5M  250M   1% /dev/shm
lrm                   252M  2.0M  250M   1% /lib/modules/2.6.27-9-generic/volatile

Before Oracle install we used up 2.4G, now we used up 7.2G.

The other thing you can do is use vmware tools to shrink the image.

sudo /usr/bin/vmware-toolbox

This pops up a GUI that has a shrink tab.
VMWareShrink.png

Now that you've shrunk it as much as you can, shut down the virtual machine, and use bzip2 to compress it into a single compressed, distributable file. This is on the Mac:

tar -cvfjp Xubuntu8.10_Oracle11gR1.tar.bz2 Xubuntu8.10_Oracle11gR1.vmwarevm

Beware of Snapshot

Just a word of caution — don't ever use VMWare's snapshot feature on this image if you want to distribute it. If you do, you cannot compress it as well because the snapshot feature just writes diff changes to a different set of files. Just avoid snapshot, and you'll be fine.


Backlinks


Add a New Comment
or Sign in as Wikidot user
(will not be published)
- +
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License