Deploying Oracle Database 12c on AWS EC2 Instance

Standard

YouTube Playlist – Oracle Database and APEX on AWS EC2

See companion post Deploying Oracle APEX on EC2 against Oracle Database on EC2

So if you have ever used AWS (Amazon Web Services) before you probably know they have an RDS service that will allow you to auto-deploy several flavors of database.  In this youtube playlist I show my students how to do just that.

But if you have deployed Oracle databases via RDS you may have also noticed that you don’t really get the kind of access (no root and no sysdba) to the instance you really need if you want to truly be able to utilize the full power of the database.

So what are you to do?

Well thankfully AWS also allows you to deploy EC2 instances of various OS (Operating System) flavors which are really just VM’s (Virtual Machines).  Additionally, lots of helpful people have created VM’s that have OS’s, like Oracle Linux, already installed that you can use as the basis of new instances.  In this post I explore how to accomplish this feat using lots of great resources I’ve found around the net.  If you have never touched a Linux OS or AWS or an Oracle Database then don’t be scared this post is for you!  If you have done these things, but not on AWS, then this post is also for you but I will definitely do my best to assume you are a beginner.

This example is done on a t2.small instance size (1 vCPU + 2GB RAM) which is one step above AWS’s free tier but still a very reasonable 2 cents an hour for powered on instances (no charge when they are off).  It seems to run just fine and I have used even smaller instances to run APEX development work spaces for 15 students.  Makes me wonder about just how over licensed / resourced a lot of people might be.

First let me list some super helpful resources –

A post by Tim Hall explaining Installation of Oracle on EC2 and it’s companion Oracle Database 12c Release 1 (12.1) Installation On Oracle Linux 7 (OL7) which are really the basis for most of what I show you but with a few key changes, by me, for beginners.

Other posts by Tim Hall for auto-starting database and pdb’s –

See heading ‘The “runuser” Command’ on this post for auto-starting 12c

See ‘Pluggable Database (PDB) Automatic Startup’ on this post for auto-starting PDB’s

Also uber helpful –

MobaXterm Download

AWS On-Demand Instance Prices (remarkably cheap)

Managing User Accounts on Your Linux Instance

Retrieving the Public Key for Your Key Pair on Linux

Making an Amazon EBS Volume Available for Use

Oracle Database Software Downloads

20 Linux YUM (Yellowdog Updater, Modified) Commands for Package Management

YUM COMMAND CHEAT SHEET

Linux Add a Swap File – Howto

Amazon EC2 Pricing

Cannot connect to Oracle DB on EC2 instance (Firewall NOT the issue)

And finally a video on how to create AWS account I’ve used with my students in case you need it.

Workflow for creating Oracle EC2 database instance:

This YouTube video follows the workflow I’ve created below –

  1. Download MobaXterm
  2. Set up Ec2 instance using OL7.2-x86_64-HVM-2015-12-10 Amazon Machine Image (AMI) with three additional volumes of 5, 8 and 10 gb (this will make your life easier).
  3. Login via MobaXterm as ec2-user and change password
    • sudo passwd ec2-user
  4. Install packages needed for instance
    • sudo yum install wget zip unzip -y
    • sudo yum install perl-libwww-perl.noarch -y
    • sudo yum install oracle-rdbms-server-12cR1-preinstall -y
  5. Mount volumes, format disks, mkdir
    1. sudo mkfs -t ext4 /dev/xvdb (be super careful here)
    2. sudo mkfs -t ext4 /dev/xvdc (be super careful here)
    3. sudo mkdir -p /swapfile1
    4. sudo mount /dev/xvdb /swapfile1 (swap file)
    5. sudo mkdir -p /u01/software
    6. sudo mount /dev/xvdf /u01/software (zip files)
    7. sudo mkdir -p /u01/app/oracle/oradata/orcl
    8. sudo mount /dev/xvdc /u01/app/oracle/oradata/orcl (data files)
  6. Add swap file
    • sudo dd if=/dev/zero of=/swapfile1/swapfile  bs=1024 count=3145728 (creates 3G swapfile)
    • sudo chown root:root /swapfile1/swapfile
    • sudo chmod 0600 /swapfile1/swapfile
    • sudo  mkswap /swapfile1/swapfile
    • sudo swapon /swapfile1/swapfile
    • free -m
  7. Make fstab entries
    • lsblk (gives names of volumes)
    • sudo cp /etc/fstab /etc/fstab.orig (back up fstab)
    • sudo vi /etc/fstab
    • /swapfile1 none swap sw 0 0
    • /dev/xvdc /u01/app/oracle/oradata/orcl ext4 defaults 0 0
    • /dev/xvdf /u01/software ext4 defaults 0 0
    • sudo mount -a (remount everything to make sure it worked)
  8.  Give oracle user ownership of directories
    • sudo chown -R oracle.oinstall /u01/app/oracle/oradata/orcl
    • sudo chown -R oracle.oinstall  /u01/software
    • sudo chown -R oracle.oinstall /u01
  9. Change hostfile for instance by adding hostname to localhost
    • hostname
    • sudo vi /etc/hosts
  10. Change password for oracle user and make it possible for user to connect remotely (Managing User Accounts on Your Linux Instance)
    • sudo passwd oracle
    • su oracle (switch to oracle user)
    • cd ~(make sure your are in oracle user home)
    • mkdir .ssh (create location for key file)
    • chmod 700 .ssh (set permissions)
    • touch .ssh/authorized_keys (create file)
    • chmod 600 .ssh/authorized_keys (set permissions)
    • “GET http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key>.ssh/authorized_keys” (copy public key to file)
    • log out and login as oracle user
  11. Upload database zip files into /u01/software (this takes a while)
  12. Unzip files
    • cd /u01/software
    • unzip linuxamd64_12102_database_1of2.zip
    • unzip linuxamd64_12102_database_2of2.zip
  13. Start install
    • cd /ora_software/database
    • ./runInstaller
  14. Run scripts as root (careful here you need to open separate instance of MobaXterm)
    • sudo /u01/app/oraInventory/orainstRoot.sh
    • sudo /u01/app/oracle/product/12.1.0/dbhome_1/root.sh
  15. Say OK to run dbca to create a database
  16. Update tnsnames.ora, listener.ora files by replacing localhost with actual host name
    • cd /u01
    • find -name tnsnames.ora
    • find -name listener.ora
    • hostname
    • vi ./app/oracle/product/12.1.0/dbhome_1/network/admin/tnsnames.ora
    • vi ./app/oracle/product/12.1.0/dbhome_1/network/admin/listener.ora
  17. Restart listener and database
    • . oraenv
    • lsnrctl stop
    • lsnrctl start
    • sqlplus sys as sysdba
    • shutdown immediate;
    • startup;
  18. At this point you should be able to connect to your database remotely with SQL Developer or your favorite tool, remember if you are shutting down your EC2 instance to first stop the listener and the database.

 

 

7 thoughts on “Deploying Oracle Database 12c on AWS EC2 Instance

  1. Cloudguru

    Excellent video, thanks for explaining the installation process step by step.
    I have one question, how can I download the zip files in 8 GB disk which u have attached. This step was missed in the video can u let me know how to complete this. Thank you so much.

    Liked by 1 person

  2. hello Sir, I followed the steps made this installation successfully in EC2 instance however i cannot connect to the database from my desktop.. I feel I have some issues with the host name of my machine
    I get hostname as follows : ip-10-0-0-253.ap-south-1.compute.internal

    It would be great if you help me out of this issue.
    I have explained more about my issue in the following post

    https://dba.stackexchange.com/questions/196632/aws-oracle-linux-7-4-connection-issue

    Like

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 )

Google+ photo

You are commenting using your Google+ 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 )

w

Connecting to %s