czwartek, 16 stycznia 2014

How to install Oracle database 11g on Ubuntu 12.04



Generally you should look at two post that help you manage this problem:
Oracle Forum how-to

Links on this topic available in one place

I used first link and it worked for me. I used other blog to resolve common problem with
ORA-00845: MEMORY_TARGET not supported on this system that can look pretty
scary.

Here are repeated steps that I did:
Before installing Oracle 11g you should preinstall packages:
sudo apt-get install alien libaio1 unixodbc

 Ubuntu does not have swap memory installed so I need to install it.
To install a 1 GB swapfile named swapfile in /, for example:
sudo dd if=/dev/zero of=/swapfile bs=1024 count=1048576
(this may take a while)
sudo mkswap /swapfile
sudo swapon /swapfile
sudo cp /etc/fstab /etc/fstab.orig
sudo echo '/swapfile swap swap defaults 0 0' >> /etc/fstab
Also it is good idea to create separate partition for our database and label it /u01.
 I used gparted for it and create separate partition as ext3. Currently Ubuntu 12.04 uses
filesystem ext4 as default and it can be not compatible with Oracle database.

You need to remember to modify fstab when you add swap space and add new partition.
Backup is also recommended.
Modify /etc/fstab to automatically mount the volume at system startup:
sudo cp /etc/fstab /etc/fstab.original
sudo nano /etc/fstab

(Add the following, using determined UUID, for example)

UUID=d19a2d8f-da43-4802-8bdb-0703c855e23a /u01 ext3 defaults,errors=remount-ro 0 1

(Save the file)

Create the mount-point, mount the new volume and set ownership and privileges:
sudo mkdir /u01
sudo mount -a
sudo chown root:root /u01
sudo chmod 755 /u01
After you created new partition you need to link it to your Ubuntu installation filesystem.
I use /opt/oracle-xe for my installation directory

Create a symbolic link to store the installation into an existing directory, for instance:
sudo mkdir /opt/oracle-xe
sudo ln -s /opt/oracle-xe /u01

You can download rpm version for 64 bit Oracle Express Edition 11g from here
Oracle Download Page
Here is what you need to type to convert it to Debian installation package.
sudo unzip linux.x64_11gR2_OracleXE.zip
sudo alien --to-deb --scripts oracle-xe-11.2.0-0.5.x86_64.rpm
(This may take a while)

There are 2 config file that is good to create with pico or nano as you can paste to them
from graphical terminal unlike in vim.
sudo nano /etc/sysctl.d/60-oracle.conf
(Enter the following)

# Oracle 11g XE kernel parameters
fs.file-max=6815744
net.ipv4.ip_local_port_range=9000 65000
kernel.sem=250 32000 100 128
kernel.shmmax=536870912

(Save the file)

Note: kernel.shmmax = max possible value, e.g. size of physical RAM.

Verify: sudo cat /etc/sysctl.d/60-oracle.conf

Load new kernel parameters: 
sudo service procps start
Verify: 
sudo sysctl -q fs.file-max
-> fs.file-max = 6815744
sudo pico /sbin/chkconfig
(Cut and paste the following)

#!/bin/bash
# Oracle 11gR2 XE installer chkconfig hack for Debian by Dude
file=/etc/init.d/oracle-xe
if [[ ! `tail -n1 $file | grep INIT` ]]; then
   echo >> $file
   echo '### BEGIN INIT INFO' >> $file
   echo '# Provides:             OracleXE' >> $file
   echo '# Required-Start:       $remote_fs $syslog' >> $file
   echo '# Required-Stop:        $remote_fs $syslog' >> $file
   echo '# Default-Start:        2 3 4 5' >> $file
   echo '# Default-Stop:         0 1 6' >> $file
   echo '# Short-Description:    Oracle 11g Express Edition' >> $file
   echo '### END INIT INFO' >> $file
fi
update-rc.d oracle-xe defaults 80 01

(Save the file)

Set appropriate execute privileges:
chmod 755 /sbin/chkconfig

There
Now that you have swapfile, partition for oracle Database and 2 config files and converted install package you can make final installation procedures:
sudo dpkg --install ./oracle-xe_11.2.0-2_amd64.deb
/etc/init.d/oracle-xe configure
(This will take a while)

Remove the /sbin/chkconfig script, which is no longer needed.
sudo rm /sbin/chkconfig

Then you need to setup your sqlplus client by coping it to your bash shell script:
sudo echo '. /u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh' >> /home/oracle/.bashrc

After that I downloaded also Oracle client in order to be able to connect to my database:
This are recommended package that you unpack into one folder directory:
instantclient-sqlplus-linux-x86-64-11.2.0.2.0.zip
oracle-instantclient11.2-basic-11.2.0.2.0.x86_64.rpm
oracle-instantclient11.2-sqlplus-11.2.0.2.0.x86_64.rpm
oracle-instantclient11.2-devel-11.2.0.2.0.x86_64.rpm

After that you need to update path so we know where to look for sqlplus.

export PATH=<Your Oracle Home Path>/instantclient_11_2:$PATH

You can also create user dba and add it to oracle group, however I am not sure if it is essential:
sudo userdel oracle
sudo useradd -s /bin/bash -G dba -g dba -m oracle
sudo passwd oracle

You can start and stop service like this:
sudo service oracle-xe start|stop

But before that there is one more bug to fix:
I took this from this page Hardly readable fix

Do the following to avoid getting MEMORY TARGET error ( ORA-00845: MEMORY_TARGET not supported on this system ) :
sudo rm -rf /dev/shm
sudo mkdir /dev/shm
sudo mount -t tmpfs shmfs -o size=2048m /dev/shm

The reason of doing all this is that on a Ubuntu system /dev/shm is just a link to /run/shm but Oracle requires to have a seperate /dev/shm mount point.
And finally
sudo service oracle-xe start|stop

Here is permanent fix this error:
To make the change permanent do the following :

a) create a file named S01shm_load in /etc/rc2.d :


sudo vim /etc/rc2.d/S01shm_load
Now copy and paste following lines into the file :


#!/bin/sh
case "$1" in
start) mkdir /var/lock/subsys 2>/dev/null
touch /var/lock/subsys/listener
rm /dev/shm 2>/dev/null
mkdir /dev/shm 2>/dev/null
mount -t tmpfs shmfs -o size=2048m /dev/shm ;;
*) echo error
exit 1 ;;esac

b) Save the file and provide execute permissions :

chmod 755 /etc/rc2.d/S01shm_load

However I prefer first method as messing with shm can be dangerous
for your encrypted filesystem.
So you could put this 4 lines in script like config_oracle.sh and run
it every time you want to experiment with Oracle 11g database.