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

7 comments:

  1. Great content material and great layout. Your website deserves all of the positive feedback it’s been getting.
    see this

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete

  3. ERPTREE Offering Oracle fusion HCM online training, Oracle Fusion SCM Online Training, Oracle fusion financials online
    training, Oracle fusion hcm training, Oracle fusion scm training, Oracle fusion financials training,
    Oracle fusion dba online training in Hyderabad, Bangalore,Gurgon, Noida, India, Dubai, UAE, USA, Kuwait, UK, Singapore, Saudi Arabia, Canada,
    Delhi, Chennai, Kolkata, Pune, Mumbai, Ahmedabad.


    Oracle fusion HCM Online Training

    Oracle Fusion HCM Training

    ReplyDelete
  4. It was really a nice article and i was really impressed by reading this AWS Online Training

    ReplyDelete
  5. Thanks for sharing great article, Hope you will post many more articles like this.

    Oracle Fusion Financials Online Training

    ReplyDelete
  6. Hey Really Thanks for sharing the best information regarding oracle,hope you will write more great blogs.

    oracle fusion financials online training

    oracle fusion financials training in hyderabad

    ReplyDelete