Starting an Oracle XE listener on Amazon EC2 instance


I have written a few posts regarding getting Oracle listener working on Oracle, I though I would post and independent piece of writing regarding this subject.

I have installed Oracle 11 express version, there are two ways to get Oracle working. The issue is that every time that you reboot an Amazon instance you will get a new IP address and name. When you create Oracle for the first time it uses the server name in the .ora files. This means that when you reboot the server the Oracle listener will fail to start.

 

Modify the listener.ora and tnsnames.ora files to contain a stack name for the serve and then map the static name to an ever changing host file where the information is inserted when the service is started. The other way is to register the server with Amazons route 53 service. This would allow you to set a FQDN in the two files and when the server is restarted it would work.

As I use more of Amazon AWS then I am starting to use Route 53 even more, but if you just want to get Oracle working without the added expense of Route 53 then the below solution will work.

Modify the tnsnames.ora file

vi /u01/app/oracle/product/11.2.0/xe/network/admin/tnsnames.ora

My tns file looks like this

# tnsnames.ora Network Configuration File:

XE =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = servername)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = XE)
)
)

EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)

This is a read only file so you will need to use

:wq!

To save the file

You also need to change the listener.ora file as this also contains the host name of the server.

vi /u01/app/oracle/product/11.2.0/xe/network/admin/listener.ora 

My file looks like this

# listener.ora Network Configuration File:

SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/xe)
(PROGRAM = extproc)
)
)

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE))
(ADDRESS = (PROTOCOL = TCP)(HOST = servername)(PORT = 1521))
)
)

DEFAULT_SERVICE_LISTENER = (XE)

This is a read only file so you will need to use

:wq!

To save the file

You need to create the following file, to recreate the hosts file every time the server is rebooted, this will allow the oracle to work properly.

The script file I called createhostfile.ksh and the contents is

#!/bin/bash
getip=`/sbin/ifconfig eth0 | grep ‘inet addr’ | awk ‘{print $2}’ | sed -e ‘s/.*://’`
newhost=”${getip} servername
rm -f /etc/hosts
echo “127.0.0.1 localhost localhost.localdomain” > /etc/hosts
echo $newhost >> /etc/hosts

Note that server name must match what is used in the tnsnames and listener ora files.

To create the file

mdir /opt/scripts

cd /opt/scripts

vi createhostfile.ksh

paste the script above

chmod 755 createhostfile.ksh

Now we can change the oracle-xe file that is used to start and stop oracle.

vi /etc/init.d/oracle-xe

After all of the comment insert the following line

/etc/createhostfile.ksh

This will call the host file creating every time that oracle is started

Advertisements

One Comment on “Starting an Oracle XE listener on Amazon EC2 instance”

  1. […] Starting an Oracle XE listener on Amazon EC2 instance […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s