Showing posts with label amazon. Show all posts
Showing posts with label amazon. Show all posts

2011/03/16

Setting listener.ora and tnsnames.ora on Amazon EC2

Every time you start your Amazon EC2 instance, your public and private DNS change. This is a problem because we have to modify the files listener.ora and tnsnames.ora many times. If not, your listener (among other things) will not work.

The following bash script creates the two files with the private ip that you pass as argument and starts the listener. The old files are renamed in the same folder (just in case you want to recover them).

Check that the LISTENER_DIR variable is correct in your system.

#!/bin/bash

EXPECTED_ARGS=1
LISTENER_DIR=/u01/app/oracle/product/11.2.0/db_1/network/admin

if [ $# -ne $EXPECTED_ARGS ]
then
echo "Usage: `basename $0` {private_ip}"
exit 0
fi

cp ${LISTENER_DIR}/listener.ora ${LISTENER_DIR}/listener.ora.old

echo "LISTENER =" > ${LISTENER_DIR}/listener.ora
echo " (DESCRIPTION_LIST =" >> ${LISTENER_DIR}/listener.ora
echo " (DESCRIPTION =" >> ${LISTENER_DIR}/listener.ora
echo " (ADDRESS = (PROTOCOL = TCP)(HOST = "${1}")(PORT = 1521))" >> ${LISTENER_DIR}/listener.ora
echo " )" >> ${LISTENER_DIR}/listener.ora
echo " )" >> ${LISTENER_DIR}/listener.ora

lsnrctl start

cp ${LISTENER_DIR}/tnsnames.ora ${LISTENER_DIR}/tnsnames.ora.old

echo "ORCL =" > ${LISTENER_DIR}/tnsnames.ora
echo " (DESCRIPTION =" >> ${LISTENER_DIR}/tnsnames.ora
echo " (ADDRESS = (PROTOCOL = TCP)(HOST = "${1}")(PORT = 1521))" >> ${LISTENER_DIR}/tnsnames.ora
echo " (CONNECT_DATA =" >> ${LISTENER_DIR}/tnsnames.ora
echo " (SERVER = DEDICATED)" >> ${LISTENER_DIR}/tnsnames.ora
echo " (SERVICE_NAME = orcl)" >> ${LISTENER_DIR}/tnsnames.ora
echo " )" >> ${LISTENER_DIR}/tnsnames.ora
echo " )" >> ${LISTENER_DIR}/tnsnames.ora