Install Oracle Database 12c on Red Hat AWS EC2 Instance — Part 2: Setup Red Hat (RHEL 7)

Luiz Eduardo Zappa
8 min readSep 4, 2021

--

This is a series of articles I’ve been describing from scratch how to provision an instance on AWS EC2 with Red Hat (RHEL 7), install the Oracle Database 12c just from the command line, and finally connect through SQL Developer from a remote computer.

So to the article doesn’t get too long, I divided it into parts. I recommended reading from the beginning, as the subjects are linked and an initial configuration can impact the final result you are here:

Part 1: Launch AWS EC2 Instance with RHEL 7 and connect with SSH (Windows using Putty)

Part 2 (This article): Setup Red Hat to receive the Oracle Database installation

Part 3: Download Oracle 12c and transfer to AWS EC2 instance with Secure Copy Client (SCP)

Part 4: Install Oracle Database and Create Instance

Setup Red Hat to receive the Oracle Database Installation

Once connected to our AWS EC2 Red Hat instance (explained in the first article), let’s change the hostname and add an entry in the Local DNS Resolver. Enter the following commands:

sudo hostnamectl set-hostname <desired-host-name>

In order for you hostname update to persist, you must verify that the preserve_hostname cloud-init setting is set to true. For that run the following command to add this settings:

sudo vi /etc/cloud/cloud.cfg

If you’re not used to the vi editor, I recommend reading this article that gives you an introduction. In the future, I plan to write an introductory article to vi for windows users. It’s the users that i perceive have the most difficulty with “vi way”.

I’ll assume you don’t know how to use vi. Just follow the indicated keys.

Press Shift+ G to go to the last line of the file. Then, press Shift + O to add a new line above the cursor. Type it:

preserve_hostname: true

Then, press ESC and type it to save the file and exit:

:wq

Esc is to exit from Insert Mode, :w is for save the file and :q is for exit. You can execute the save and close commands all at once with :wq

Copy your ip address with the command:

ip a

It’s the address after inet to the bar:

IP Address

Let’s edit the Local DNS Resolver with the command:

sudo vi /etc/hosts

Press Shift +G to go to the end of the file, then press i to enter Insert Mode. Type the ip address figured out in last step, and after that (followed by a blank space) the hostname you gave a few steps back

Editing Local DNS Resolver

Press ESC to exit the vi Inster Mode, then type it to save and close the file:

:wq

Then, we need to disable SELinux. For that, edit this file with vi:

sudo vi /etc/selinux/config

SELinux: Security-Enhanced Linux is a security architecture for Linux systems that defines access controls for the applications, processes and files on a system.

Press j to go down to the line containing the text SELINUX=, then press Shift + A to append new text, replace the default value with disabled.

Disable SELinux

Bonus: vi editor uses hjkl as arrow keys, the reason is when Bill Joy created the editor, he used the ADM-3A terminal, which had the arrows on hjkl keys. Naturally he reused the same keys. More information in this interesting article.

Press ESC to exit vi Insert Mode, then type :wq to save and exit the file.

Now let’s change the Kernel parameters in /etc/sysctl.conf, open this file with vi:

sudo vi /etc/sysctl.conf

Press Shift + G to go to the end of the file and press O to add a new blank line. Copy the lines below and past into the file. If you are using PuTTY, press Shift + Insert to paste.

fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmmax=536870912
kernel.shmmni=4096
kernel.shmall=262144
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048586

Press ESC to exit vi Insert Mode, then type :wq to save and exit the file.

To apply parameter changes without restarting the operating system, enter the following commands:

sudo sysctl -p
sudo sysctl -a

Set the shell limit for user oracle in the file /etc/security/limit.conf . Open this file with vi editor:

sudo vi /etc/security/limits.conf

Press Shift + G to go to the end of the file and press Shift + O to add a new blank line above. Paste the following lines there: (If you are using PuTYY, just press Shift + Insert to paste)

oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
oracle hard stack 32768

Press ESC to exit vi Insert Mode, then type :wq to save and exit the file.

We need to install prerequisite packages, but before that we need to register our Red Hat to be able to install/update packages. Access the Red Hat Developer Website, clique on Log in the top right corner of the screen

Register an Red Hat Developer Account

In the login page, in the top right corner of the screen, click on Register

Create a new account. You will receive a confirmation email, click on the link in that email to active your account.

Create a Red Hat Developer Account

Once your registration is activated, we will register your operating system through the command line. Enter the following command:

sudo subscription-manager register --username <your-username-registered-on-red-hat>

Let’s assume your user registered on the Red Hat is bob, the commando would be sudo subscription-manager register --username bob

You will be asked for the password for the account. Registration being successful, you will receive a message similar to this:

Message Red Hat successful registration

Attach subscriptions automatically for your server with below command:

sudo subscription-manager attach --auto

Enable the rhel-7-server-option-rpms repository to be able to install some of the necessary packages:

sudo subscription-manager repos --enable=rhel-7-server-optional-rpms

Now we can update OS packages with the command:

sudo yum update -y

Then, let’s install prerequisite packages using the following command:

sudo yum install binutils compat-libstdc++-33 gcc gcc-c++ glibc glibc-devel ksh libgcc libstdc++ libstdc++-devel libaio libaio-devel libXext libXtst libX11 libXau libxcb libXi make sysstat unixODBC unixODBC-devel zlib-devel -y

After installation, create required OS groups with the commands:

sudo groupadd -g 1101 oinstall
sudo groupadd -g 1102 dba
sudo groupadd -g 1103 oper
sudo groupadd -g 1104 backupdba
sudo groupadd -g 1105 dgdba
sudo groupadd -g 1106 kmdba
sudo groupadd -g 1107 asmdba
sudo groupadd -g 1108 asmoper
sudo groupadd -g 1109 asmadmin

Create the oracle user to install the database:

sudo useradd -g 1101 -g oinstall -G dba,oper,backupdba,dgdba,kmdba,asmdba,asmoper,asmadmin oracle

Set the oracle user password with the command:

Attention: the oracle password has some stricter restrictions than the OS. I recommend using only letters and numbers. I used the @ character in the password and lost some hours of my day trying to identify the cause of an error that was this.

sudo passwd oracle

Configure Linux Firewall to allow SQL*Net Listener to accept service requests on its default port. First, install the packaged firewalld with this command:

sudo yum install firewalld -y

Then, enable the firewall and start the service:

sudo systemctl enable firewalld
sudo systemctl start firewalld

Allow the port 1521/tcp:

sudo firewall-cmd --permanent --add-port=1521/tcp

Reload the firewall with this command:

sudo firewall-cmd --reload

Create directories for Oracle RDBMS Software:

sudo mkdir -p /u01/app/oracle/product/12.1.0.2/db_1
sudo mkdir -p /u01/app/oracle/product/12.1.0.2/db_1/network/admin
sudo mkdir -p /u01/app/oraInventory

Change the owner of these directories for the oracle user:

sudo chown -R oracle:oinstall /u01

Change directory permissions:

sudo chmod -R 755 /u01

Oracle Database needs a minimum 150MB swap file, let’s create a 2GB one.

sudo dd if=/dev/zero of=/myswap count=2000 bs=1MiB

Give these permissions:

sudo chmod 600 /myswap

Set up the swap area:

sudo mkswap /myswap

Enable the created swap:

sudo swapon /myswap

For this change to be permanent, we need to edit the File Systems Table (FSTAB):

sudo vi /etc/fstab

Press Shift + G to go to the end of the file, then press O to add new blank line. Paste this line there (If you’re using PuTTY, just press Shift + Insert)

/myswap swap swap defaults 0 0

Press ESC to exit the vi Insert Mode, then type :wqto save and exit the file.

As the installation process takes a long time, your connection sometimes goes down. To get around this, let’s use the screen package to keep the session active if that happens. Install the package with this command:

sudo yum install screen -y

Switch to oracle user that we created a few steps back:

su - oracle

After, entering the password, configure the enviroment variables of the oracle user with vi editor, enter this command:

vi .bash_profile

Press Shift +G to go to the end of the file, press O to create a new blink line and paste these codes there (If you’re using PuTTY, just press Shift + Insert to paste these codes)

export TMP=/tmp
TMPDIR=$TMP; export TMPDIR
export ORACLE_HOSTNAME=redhatsrv
export ORACLE_UNQNAME=orcl
ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/12.1.0.2/db_1; export ORACLE_HOME
ORACLE_SID=orcl; export ORACLE_SID
PATH=/usr/sbin:$ORACLE_HOME/bin:$PATH; export PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib:/usr/lib64; export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib; export CLASSPATH
alias cdob='cd $ORACLE_BASE'
alias cdoh='cd $ORACLE_HOME'
alias tns='cd $ORACLE_HOME/network/admin'
alias envo='env | grep ORACLE'
umask 022if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -u 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi
envo

ORACLE_HOSTNAME must be equal to the hostname defined in the first article

Press ESC to exit vi Insert Mode, and type :wq to save and close the file.

We finished the set up, in the part 3 we will download Oracle Database 12c and transfer it to our AWS EC2 isntance with Secure Copy Client (SCP).

--

--

Luiz Eduardo Zappa

Engineer breaking into the world of information technology 👨‍💻 I comment on what I'm developing on https://twitter.com/imluizzappa