Friday, October 30, 2009

Installing Oracle 11g on Linux / Centos (Including VMWare)

An Oracle database can be a very handy thing to have around. I do database design and development, Business Intelligence, Data Warehousing, and also database administration. People often ask me how they can get an Oracle database up and running easily. Here is the answer.

I have become a huge fan of VMWare. The VMWare Server version is free software that can be downloaded from My laptop has VMs available for Windows 7, Windows Vista, Windows XP Professional, Windows Server 2003, and Centos 5.3.

While the Oracle database can be created on Windows 7 or Windows Vista, the business intelligence tools I use cannot. Specifically Informatica Server is not supported on any non-server version of Windows. So I chose to create a simple default database configuration on Linux for the purposes of getting Informatica Server up and running.

If you are using VMware see the section at the end with specific VMware tips on how to create and use your virtual machine most effectively.

Installing and Configuring Centos

When you install Centos, the default is just a desktop configuration. Make sure you check the box to install the Server components as well. Because I am running on VMware and don't have any worries about attackers getting into my virtual machine, I am disabling the firewall and disabling SELinux. By doing this you greatly simplify the process of connecting from your host machine to the VM. If you choose to not follow this advice, you will be on your own in figuring out security or network connection issues. Also tick the box that allows you to install software from the Centos Extras repository.

Create Oracle User Account

You should run Oracle as a separate user account under Linux. To prepare for the install, we create a new group called "dba" and a new user called "oracle" as follows:

groupadd dba
tail -1 /etc/group
useradd -g 501 oracle
passwd oracle

Changing password for user oracle.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.

Create Oracle Software Installation Directory

Oracle by default will install software in the Oracle user's home directory. This poses complications down the road and is not standards compliant. You should create a new directory as the "Oracle Base" which is where the database software will be installed.

As the root user:

mkdir /opt/oracle
chown oracle:dba /opt/oracle
chmod 755 /opt/oracle

Oracle by default will install software in the Oracle user's home directory. This poses complications down the road and is not standards compliant. You should create a new directory as the "Oracle Base" which is where the database software will be installed.

Install Additional Centos Packages

In order to install Oracle, there are a variety of extra packages required on Centos. To install those extra packages, simply open a command line prompt as root and run:

yum install binutils compat-db control-center gcc gcc-c++ glibc glibc-common gnome-libs libstdc++ libstdc++-devel make pdksh sysstat xscreensaver libaio openmotif21 libaio-devel-0.3.106 compat-libstdc++-33 unixODBC-2.2.11 unixODBC-devel-2.2.11 elfutils-libelf-devel

You will be prompted to confirm, and at each prompt say YES. You will see each of the libraries being downloaded first, then you will be prompted about trusting the key signature of the software, then you will see the downloaded libraries being installed. This installs all of the necessary Oracle files as well as any dependent files. Note that yum is using your internet connection to download the libraries, so if you don't have access to the Internet this will fail.

Adding Swap Space

Oracle likes to have lots of memory and swap. If you are running in VM and did a default Centos installation, you should increase your swap space by 2GB as follows:

dd if=/dev/zero of=/swapfile2 bs=1024 count=2097152
mkswap /swapfile2
swapon /swapfile2

Add this entry to the /etc/fstab file to make the swap automount:

/swapfile2 swap swap defaults 0 0

Downloading Oracle

Download the media from Once you get through the license agreement and export restrictions, choose "Oracle Database" in the Product Pack drop down box, and then choose "Linux x86" in the Platform drop down box. Choose the most appropriate database release for your needs, in my case I chose "Oracle® Database 11g Release 2 ( Media Pack for Linux x86." When you get to the next screen you will see the download is 2 parts, download both. Unzip the files into whatever directory you choose, and make sure the files are accessible by the oracle user account.

Installing Oracle

Open a terminal session and become the "oracle" user:

su - oracle

Navigate into the the folder that you downloaded and unzipped the Oracle software to. You will find a subfolder named "database", navigate there and execute the commands:

export ORACLE_BASE=/opt/oracle

Tips on the Installer Prompts
  • If you don't have an Oracle Metalink support account, you will have to uncheck the option of receiving updates via My Support
  • Choose "Desktop Class"
  • When you get to the prerequisite checks you will get errors. Click on "fix and run again" which will generate a shell script for you to run as root to correct the kernel parameters. After running this script you should be down to warnings on swap and memory. Click ignore all.
Post Installation

Run /opt/oracle/product/11.2.0/dbhome_1/ as the root user.

Database Startup & Shutdown

After installation, your new database should be running. To verify, logon as the oracle user in a terminal session and execute ". oraenv" (that's dot-space-oraenv). At the prompt, type the database name you specified in the installation (default is orcl). Now you should be able to logon to the database as the sys account by running "sqlplus / as sysdba" -- if that doesn't work, it's troubleshooting time.

To startup the database & listener:

1. lsnrctl start

2. sqlplus / as sysdba

To shutdown the database & listener:

1. sqlplus / as sysdba
shutdown immediate;

2. lsnrctl stop

VMware Specific Tips

Creating the VM

If you are running on a real Linux server then this step can be skipped. If you are getting all of this running on VMware, like me, then make sure you allocate 1GB of memory and at least ??GB of disk space to the VM. I am using Centos, which is the community version of Red Hat. So when creating your VM choose Red Hat Enterprise 5.3. Configure two network adapters. The first network adapter is host only, which puts your VMs and host onto a private network segment. These IP addresses are DHCP assigned by VMware which means the IP addresses don't change frequently. The second network adapter is bridged. Bridged network adapters look like a separate network adapter on your network. They will request a DHCP IP address from your router, and the subnet of the IP address will be the same as the subnet of your PC's IP address. This bridged connection gets you outside to the internet.

Important Note: Linux will take the DNS settings of the last network adapter brought up. This is why your bridged network connection must be 2nd, otherwise Linux tries to use the host-only network which has no DNS server.

VMware Tools

You must install VMware tools into your Linux VM. This gives you more options for display resolutions and sound, but more importantly it must be re-run anytime you modify you virtual server configuration. For example, if you add a network interface to your virtual server, but you don't re-run the config tool, your network probably won't be working like you want it to!

Once you mount the VMware tools ISO image, just click on the RPM file. Configure VMware Tools for your kernel by executing /usr/bin/ Once installed, /usr/bin/vmware-toolbox can be used within an X session to make changes.

Networking Explained

As suggested, create two networks on your VM: bridged and host-only. Bridged network adapters use the host network card, but emulate a separate network card on the same network with the host. Bridged adapters will request a DHCP IP address from the same router as your host PC, and the subnet of the IP address will be the same as the subnet of your PC's IP address. This bridged connection gets you outside to the internet. The second network adapter is host only, which puts your VMs and host onto a private network segment. Although these are still DHCP assigned, the DHCP server is VMware (instead of the host network router) which means the IP addresses don't change frequently. I would also suggest using the "Manage Virtual Networks" component of VMware to change the lease duration on IP addresses assigned by the VMware DHCP server to a very high number. Doing this prevents you from ever getting a different assigned IP address on your VM host-only network.

Once you have your network adapters on your VM then you need to make some entries in the hosts file on Centos. We will be using the host-only network interface to communicate internally to the VMware. With VMware up and running you will find you have additional virtual network adapters in your device list on your host operating system. I am using Windows Vista, so this example demonstrates how to find the information for Windows. Substitute the appropriate commands if you host operating system is not Windows.

Open a command window prompt and type the command "ipconfig". You may see several screens of data, but you are looking for the network adapter VMnet1 as below, specifically the IPv4 Address. This will show you the IP address of your host computer on the host-only network. This is the IP address that you must use in order to access your host computer from within the VM.

Ethernet adapter VMware Network Adapter VMnet1:
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::3929:19ce:278d:feaa%14
IPv4 Address. . . . . . . . . . . :
Subnet Mask . . . . . . . . . . . :
Default Gateway . . . . . . . . . :

Now go to your Centos VM and we are going to look at the network configuration of the virtual machine. Open a terminal window and run "/sbin/ifconfig -a" command. You are looking for the IP address that is assigned to your virtual machine in the same subnet mask as your host VMNet1 adapter (above). You will be looking for data similar to below:

eth0 Link encap:Ethernet HWaddr 00:0C:29:D2:80:E5
inet addr: Bcast: Mask:
inet6 addr: fe80::20c:29ff:fed2:80e5/64 Scope:Link
RX packets:20 errors:0 dropped:0 overruns:0 frame:0
TX packets:38 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2994 (2.9 KiB) TX bytes:8806 (8.5 KiB)
Interrupt:75 Base address:0x2024

In the world of VMware these are your IP addresses you need to use and know about. To make your life simpler with Oracle configuration, you should create new entries in your centos hosts file that correspond to these names. DO NOT configure the database or SQLNet using IP addresses or "localhost" as this will cause you many problems down the line. So logon to centos as root and add the lines in bold red to your /etc/hosts. The lines in black already existed in my default /etc/hosts file.

# Do not remove the following line, or various programs

# that require network functionality will fail. localhost.localdomain localhost vmhostname.localdomain vmhostname centos.localdomain centos

Accessing Host Shares

You will need to make the Oracle software visible to your VM. So you have a couple of options. You can download the software using the browser within your VM, or you can download the software using your host operating systems and share it with the VM. Sooner or later you are going to want to transfer files from your host to your VM, so I suggest setting up the shared filesystem.

To make a shared filesystem available within a Linux VM, you need to first share the filesystem in windows. Then, as root from your VM, you mount the share like this:
mount -t cifs -o username=winuser,password=winpassword,dirmode=0777,filemode=0777 //vmhost/share_name /mnt/linux_mount_point_name
Now you can navigate to /mnt/linux_mount_point_name on centos and see the contents of the windows share. This share is read-only from Linux, which I haven't bothered to debug why files cannot be written to the share from Linux.

Note: For Samba to work, the host name you defined in the /etc/hosts file for your VM host machine must match the actual host name reported by windows, or you will get

No comments: