Tuesday, September 21, 2010

Installing Oracle on Ubuntu

Most of the applications we write here at CTP depend on an Oracle database.
After putting some effort on configuring our development environment for a new project and figuring out the process wasn't as straightforward as I expected, I decided to share my finding in this walkthrough.
It describes the steps required to install Oracle on a Ubuntu Server.

Prerequisites


The instructions apply to Oracle 11g (version 11.2.0.1.0) on an Ubuntu 10.04.1 Server Edition 64-bit.
Download Ubuntu's installation ISO from http://www.ubuntu.com/server/get-ubuntu/download and Oracle's ZIPs from http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html.
A Windows environment is used as client. You will need the following tools:


Server configuration



Installation


Install Ubuntu in your server. In this example a virtual machine with 32 Gb of disk and 2Gb of RAM is used.
During the installation process, select the "SSH server" to be installed. To do it after installation, run:

sudo apt-get install openssh-server openssh-client

X Forwarding


You should configure PuTTY to forward the graphical applications from the Ubuntu server (the 'server') to your Windows workstation (the 'client'),
as the Oracle 11g installation depends on it.
Open PuTTY and enter the IP address of your server, give a name to the session and save it. Configure the following options:

  • In "Connection > SSH > X11", check "Enable X11 forwarding" and for "X display location" enter "localhost:0"

  • Go to the "Session" menu and save your session again, to persist the configuration changes.



Start the X server in your client computer before connecting to the server through PuTTY. In the programs menu, open "Cygwin-X" and run "XWin Server".
It may start a graphical terminal (XTerm) but you should close it, to avoid confusion. All you need is to keep the server running, indicated by the fancy X icon in the system tray.
Now you can establish the SSH connection. To test if the X Forwarding is properly configured, run xeyes in the server (if not found, run sudo apt-get install x11-apps) and you should see the eyes in your desktop.

Swap configuration


The amount of swap space required by the Oracle DB depends on the available RAM:

Available RAMSwap required
Between 1 and 2 Gb1.5 x RAM
Between 2 and 16 Gb1 x RAM
More than 16 Gb16 Gb

To check the existing configured space, run

$ free
total used free shared buffers cached
Mem: 2057836 181680 1876156 0 12268 91092
-/+ buffers/cache: 78320 1979516
Swap: 1417208 0 1417208

In this walkthrough I'm going to add 2Gb to the existing swap space.

# Creates a swap file, may take a while to execute
$ sudo dd if=/dev/zero of=/mnt/2Gb.swap bs=1M count=2048
# Activating the swap file
sudo mkswap /mnt/2Gb.swap
sudo swapon /mnt/2Gb.swap

To have the swap file mounted automatically after a reboot, add the following line to the /etc/fstab file:

/mnt/2Gb.swap none swap sw 0 0

Updating and installing dependencies



$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install build-essential libaio1 libaio-dev libmotif3 libtool expat alien ksh pdksh unixODBC unixODBC-dev sysstat elfutils libelf-dev binutils lesstif2 lsb-cxx rpm lsb-rpm gawk unzip x11-utils ia32-libs

Installing libstdc++ 5


Ubuntu comes with libstdc++ version 6, but Oracle requires version 5. To fix it:

$ wget http://mirrors.kernel.org/ubuntu/pool/universe/g/gcc-3.3/libstdc++5_3.3.6-17ubuntu1_amd64.deb
$ dpkg-deb -x libstdc++5_3.3.6-17ubuntu1_amd64.deb ia64-libs
$ sudo cp ia64-libs/usr/lib/libstdc++.so.5.0.7 /usr/lib64
$ cd /usr/lib64
$ sudo ln -s libstdc++.so.5.0.7 libstdc++.so.5
$ ls -al libstdc++.*
lrwxrwxrwx 1 root root 18 2010-09-17 14:19 libstdc++.so.5 -> libstdc++.so.5.0.7
-rw-r--r-- 1 root root 829424 2010-09-17 14:18 libstdc++.so.5.0.7
lrwxrwxrwx 1 root root 19 2010-09-14 12:05 libstdc++.so.6 -> libstdc++.so.6.0.13
-rw-r--r-- 1 root root 1044112 2010-03-27 01:16 libstdc++.so.6.0.13

Links update


Update the symbolic link /bin/sh from /bin/dash to /bin/bash.

$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 2010-09-14 12:05 sh -> dash
$ cd /bin
$ sudo ln -sf bash /bin/sh
$ ls -l sh
lrwxrwxrwx 1 root root 4 2010-09-14 14:19 sh -> bash

Some links need to be created as well:

ln -s /usr/bin/awk /bin/awk
ln -s /usr/bin/rpm /bin/rpm
ln -s /usr/bin/basename /bin/basename

System users & groups


Change to root and create the following users and groups

ctp@oracle11g:~$ sudo -s
root@oracle11g:~# addgroup oinstall
Adding group `oinstall' (GID 1001) ...
Done.
root@oracle11g:~# addgroup dba
Adding group `dba' (GID 1002) ...
Done.
root@oracle11g:~# addgroup nobody
Adding group `nobody' (GID 1003) ...
Done.
root@oracle11g:~# usermod -g nobody nobody
root@oracle11g:~# useradd -g oinstall -G dba -p password -d /home/oracle -s /bin/bash oracle
root@oracle11g:~# passwd -l oracle
passwd: password expiry information changed.
root@oracle11g:~# mkdir /home/oracle
root@oracle11g:~# chown -R oracle:dba /home/oracle

Creating ORACLE_HOME



root@oracle11g:~# mkdir -p /u01/app/oracle
root@oracle11g:~# chown -R oracle:dba /u01

System parameters


Some Linux kernel parameters need to be modified, as specified in Oracle's installation guide. To do that, add the parameters below to the file /etc/sysctl.conf:

fs.file-max = 65535
kernel.shmall = 2097152
kernel.shmmax = 2147483648
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 1024 65535
net.core.rmem_default = 1048576
net.core.rmem_max = 1048576
net.core.wmem_default = 262144
net.core.wmem_max = 262144

The oracle user needs to have some shell limits increased by adding the parameters below to the file /etc/security/limits.conf:

oracle soft nproc 2047
oracle hard nproc 16383
oracle soft nofile 1023
oracle hard nofile 65535

Add the parameters below to the file /etc/pam.d/login:

session required /lib/security/pam_limits.so
session required pam_limits.so

Reboot the system to reload the configuration.

Oracle installation


From the directory you extracted the Oracle zip files, run database/runInstaller as the user oracle created above (see Unix Tips if you need help). You can ignore the DISPLAY warning, if any. If you receive an error regarding the X forwarding permission, use this remote X forwarding trick.

Installation options


The suggested installation options:

  • Create and configure a database

  • Server class

  • Single instance database installation

  • Advanced install

  • Enterprise Edition

  • General purpose/Transaction processing

  • Memory, Character sets, Security and Sample Schemas - as default


Run the fixup script following the instructions and then ignore the package dependencies.

To check if everything is ok, open the following address in your browser:

https://<server>:1158/em


Startup script


First, edit the file /etc/oratab or create one if you don't have it already. Make sure that the last parameter is "Y", meaning you want the database to be started during boot.

oracle:/u01/app/oracle/product/11.2.0/dbhome_1:Y

Now create the startup script /etc/init.d/oracledb.

cd /etc/init.d
sudo touch oracledb
sudo chmod a+x oracledb

Add the following content to the startup script

#!/bin/bash
#
# /etc/init.d/oracledb
#
# Run-level Startup script for the Oracle Enterprise Manager

export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export ORACLE_OWNR=oracle
export ORACLE_SID=oracle
export PATH=$PATH:$ORACLE_HOME/bin

if [ ! -f $ORACLE_HOME/bin/emctl -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: "
sudo -u $ORACLE_OWNR -E $ORACLE_HOME/bin/lsnrctl start
sudo -u $ORACLE_OWNR -E $ORACLE_HOME/bin/dbstart $ORACLE_HOME
sudo -u $ORACLE_OWNR -E touch /var/lock/oracle
# Oracle enterprise manager startup
sudo -u $ORACLE_OWNR -E $ORACLE_HOME/bin/emctl start dbconsole
echo "OK"
;;
stop)

echo -n "Shutdown Oracle: "
# Oracle enterprise manager shutdown
sudo -u $ORACLE_OWNR -E $ORACLE_HOME/bin/emctl stop dbconsole
# Oracle listener and instance shutdown
sudo -u $ORACLE_OWNR -E $ORACLE_HOME/bin/lsnrctl stop
sudo -u $ORACLE_OWNR -E $ORACLE_HOME/bin/dbshut $ORACLE_HOME
sudo -u $ORACLE_OWNR -E 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


To execute the script automatically during server startup:

sudo update-rc.d oracledb defaults 99


General tips n' tricks



Unix tips


Open a shell as anoter user:

sudo -u <username> -s


Remote X session config



$ xauth list
oracle/unix:10 MIT-MAGIC-COOKIE-1 a18621a7bf2c102fc2b27758007b56a0
# Copy the line returned above
sudo -u oracle -s
export HOME=/home/oracle
# Paste the copied line after xauth add
xauth add oracle/unix:10 MIT-MAGIC-COOKIE-1 a18621a7bf2c102fc2b27758007b56a0


References


No comments: