Install Oracle Database 19c (NON CDB) in Oracle Linux7.9

 -- This Script will Install Oracle Database 19c (NON CDB) in Oracle Linux 7.9

-- VM Config :

-- -----------

   Core  : 4
   Ram   : 16 GB
   Space : 512 GB
   DB    : orcl


Server Time Zone :
------------------
------------------

sudo timedatectl set-timezone Asia/Dhaka

Swap Space : (16 GB Ram)
------------------------
------------------------

swapon -s

free -m

df -h

sudo fallocate -l 32G /swapfile

ls -lh /swapfile

sudo mkswap /swapfile

sudo dd if=/dev/zero of=/swapfile count=32768 bs=1MiB

sudo chmod 600 /swapfile

sudo mkswap /swapfile

sudo swapon /swapfile

vi /etc/fstab

/swapfile   swap    swap    sw  0   0

-- run this command

sudo sysctl vm.swappiness=10

vi /etc/sysctl.conf

--- add this line

vm.swappiness = 10

vm.vfs_cache_pressure = 50

To verify swap's size

swapon --summary

free -h


Upgrade the system :

yum upgrade -y

Minimal CentOS installation:

There's a utility called chrony for this purpose in the minimal CentOS installation:

systemctl start chronyd

systemctl enable chronyd

SElinux disable :
-----------------
-----------------

vi /etc/sysconfig/selinux

And change the value SELINUX=enforcing to SELINUX=disabled, then save the config file. After doing this, execute this to disable selinux in the runtime:

setenforce 0

Firewall Enable :
-----------------
-----------------

systemctl start firewalld

systemctl enable firewalld

firewall-cmd --permanent --zone=public --add-port=8080/tcp

firewall-cmd --permanent --zone=public --add-port=1521/tcp

firewall-cmd --permanent --zone=public --add-port=443/tcp

firewall-cmd --permanent --zone=public --add-port=22/tcp

sudo firewall-cmd --zone=public --add-service=http

------------------------------------------------------------

firewall-cmd --zone=public --add-port=80/tcp

firewall-cmd --zone=public --add-port=1510/tcp

firewall-cmd --zone=public --add-port=8080/tcp

firewall-cmd --zone=public --add-port=1539/tcp

firewall-cmd --zone=public --add-port=1510/tcp

Host Entry :

vi /etc/hosts

IP             HOSTNAME.localdomain  hostname
192.168.100.9  ol7-19.localdomain    ol7-19

vi /etc/hostname
ol7-19.localdomain

PreInstall Packages :
---------------------
---------------------

yum install -y oracle-database-preinstall-19c
yum update -y

passwd oracle

vi /etc/selinux/config
SELINUX=permissive

setenforce Permissive
systemctl stop firewalld
systemctl disable firewalld

mkdir -p /u01/app/oracle/product/19.0.0/dbhome_1
mkdir -p /u02/oradata
chown -R oracle:oinstall /u01 /u02
chmod -R 775 /u01 /u02
mkdir /home/oracle/scripts


cat > /home/oracle/scripts/setEnv.sh <<EOF
# Oracle Settings
export TMP=/tmp
export TMPDIR=\$TMP
export ORACLE_HOSTNAME=ol7-19.localdomain
export ORACLE_UNQNAME=orcl
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=\$ORACLE_BASE/product/19.0.0/dbhome_1
export ORA_INVENTORY=/u01/app/oraInventory
export ORACLE_SID=orcl
export PDB_NAME=policypdb1
export DATA_DIR=/u02/oradata
export PATH=/usr/sbin:/usr/local/bin:\$PATH
export PATH=\$ORACLE_HOME/bin:\$PATH
export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:/lib:/usr/lib
export CLASSPATH=\$ORACLE_HOME/jlib:\$ORACLE_HOME/rdbms/jlib
EOF

Add a reference to the "setEnv.sh" file at the end of the "/home/oracle/.bash_profile" file.

echo ". /home/oracle/scripts/setEnv.sh" >> /home/oracle/.bash_profile

DB start and stop :
-------------------
-------------------

Create a "start_all.sh" and "stop_all.sh" script that can be called from a startup/shutdown service. Make sure the ownership and permissions are correct.

cat > /home/oracle/scripts/start_all.sh <<EOF

#!/bin/bash
. /home/oracle/scripts/setEnv.sh
export ORAENV_ASK=NO
. oraenv
export ORAENV_ASK=YES
dbstart \$ORACLE_HOME
EOF

cat > /home/oracle/scripts/stop_all.sh <<EOF
#!/bin/bash
. /home/oracle/scripts/setEnv.sh
export ORAENV_ASK=NO
. oraenv
export ORAENV_ASK=YES
dbshut \$ORACLE_HOME
EOF

chown -R oracle:oinstall /home/oracle/scripts
chmod u+x /home/oracle/scripts/*.sh

Switch to the ORACLE_HOME directory, unzip the software directly into this path and start the Oracle Universal Installer (OUI) by issuing one of the following commands in the ORACLE_HOME directory. The interactive mode will display GUI installer screens to allow user input, while the silent mode will install the software without displaying any screens, as all required options are already specified on the command line.

chown -R oracle:oinstall /u01
chmod -R 775 /u01

Gui mode :
----------
----------

How to Enable GUI in Oracle Linux (inside your Cloud VM). Follow this exactly 

Install GUI Packages

Login as root and run:

yum groupinstall -y "Server with GUI"

This installs:

GNOME desktop
X11 system
GUI tools

Set GUI as Default Boot
-----------------------
-----------------------

systemctl set-default graphical.target

--Start GUI Immediately:
systemctl isolate graphical.target

--Check GUI Status

systemctl get-default

--Should show:

graphical.target

--Use noVNC Link

Now go back to your noVNC browser link.

You should now see:

GNOME login screen OR

Desktop environment


INSTALL :
---------
---------

-- Login to Oracle User.

cd /root

cp LINUX.X64_193000_db_home.zip /u01/app/oracle/product/19.0.0/dbhome_1
cd /u01/app/oracle/product/19.0.0/dbhome_1
unzip -oq /LINUX.X64_193000_db_home.zip

vi ~/.bash_profile

# Oracle 19c Environment
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/19.0.0/dbhome_1
export ORACLE_SID=orcl
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib

source ~/.bash_profile

./runInstaller   --- gui mode install in the proper folder.

export ORACLE_HOME=/u01/app/oracle/product/19.0.0/dbhome_1
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib

cd $ORACLE_HOME/bin

./sqlplus /nolog

Bash Profile :
--------------
--------------

vi ~/.bashrc
and
vi ~/.bash_profile

export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/19.0.0/dbhome_1
export ORACLE_SID=orcl

export PATH=$ORACLE_HOME/bin:$PATH

source ~/.bashrc
source ~/.bash_profile

---------------------------------------

install:

./runInstaller   --- gui mode install in the proper folder.

---------------------------------------

export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib

source ~/.bashrc
source ~/.bash_profile

Oracle DB + Listener auto-start together on OL7.9 using systemd.
----------------------------------------------------------------
----------------------------------------------------------------


We’ll make it clean, reliable, and restart-safe.

1. First confirm /etc/oratab

Open:

sudo vi /etc/oratab
Make sure:
orcl:/u01/app/oracle/product/19.0.0/dbhome_1:Y

The Y is mandatory

2. Create unified start/stop script

We will control both DB + Listener in one script

sudo vi /usr/local/bin/oracle_startup.sh

Paste:

#!/bin/bash
ORACLE_HOME=/u01/app/oracle/product/19.0.0/dbhome_1
ORACLE_SID=orcl
PATH=$ORACLE_HOME/bin:$PATH

case "$1" in
start)
    echo "Starting Oracle Listener..."
    su - oracle -c "lsnrctl start"
    echo "Starting Oracle Database..."
    su - oracle -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME"
    ;;
stop)
    echo "Stopping Oracle Database..."
    su - oracle -c "$ORACLE_HOME/bin/dbshut $ORACLE_HOME"
    echo "Stopping Oracle Listener..."
    su - oracle -c "lsnrctl stop"
    ;;
restart)
    $0 stop
    $0 start
    ;;
*)
    echo "Usage: $0 {start|stop|restart}"
    ;;
esac

-- Make it executable

sudo chmod +x /usr/local/bin/oracle_startup.sh
-- Create systemd service
sudo vi /etc/systemd/system/oracle.service

Paste:

[Unit]

Description=Oracle Database + Listener Service

After=network.target


[Service]
Type=forking
User=oracle
ExecStart=/usr/local/bin/oracle_startup.sh start
ExecStop=/usr/local/bin/oracle_startup.sh stop
Restart=no

[Install]
WantedBy=multi-user.target

-- Enable service at boot

sudo systemctl daemon-reload
sudo systemctl enable oracle

-- Test manually

Start everything:

sudo systemctl start oracle

Stop everything:

sudo systemctl stop oracle

Check status:

sudo systemctl status oracle

What you achieved

Now your server will:

✔ Start Listener automatically
✔ Start Database automatically
✔ Stop both cleanly
✔ Survive reboot safely
✔ Managed via systemctl (production standard)


Important DBA Notes

1. Listener config check

If listener doesn’t start:

lsnrctl status

2. If DB doesn’t auto start

Check:

cat /etc/oratab

Must end with Y

Start / Stop Script :
---------------------
---------------------

Create a "start_all.sh" and "stop_all.sh" script that can be called from a startup/shutdown service. Make sure the ownership and permissions are correct.

cat > /home/oracle/scripts/start_all.sh <<EOF
#!/bin/bash

. /home/oracle/scripts/setEnv.sh
export ORAENV_ASK=NO
. oraenv
export ORAENV_ASK=YES
dbstart \$ORACLE_HOME
EOF

cat > /home/oracle/scripts/stop_all.sh <<EOF
#!/bin/bash
. /home/oracle/scripts/setEnv.sh

export ORAENV_ASK=NO
. oraenv
export ORAENV_ASK=YES

dbshut \$ORACLE_HOME
EOF

chown -R oracle:oinstall /home/oracle/scripts
chmod u+x /home/oracle/scripts/*.sh

Once the installation is complete and you've edited the "/etc/oratab", you should be able to start/stop the database with the following scripts run from the "oracle" user.

~/scripts/start_all.sh
~/scripts/stop_all.sh

---- auto start DB :
--------------------
--------------------

--- In Oracle User :

sudo vi /etc/systemd/system/oracle-db.service
[Unit]
Description=Oracle Database Auto Start/Stop
After=network.target

[Service]
Type=forking
User=oracle
Group=oinstall
ExecStart=/home/oracle/scripts/start_all.sh
ExecStop=/home/oracle/scripts/stop_all.sh
Restart=no

[Install]
WantedBy=multi-user.target

Enable service at boot:
-----------------------
-----------------------

sudo systemctl daemon-reload
sudo systemctl enable oracle-db.service

Test immediately:
-----------------
-----------------

sudo systemctl start oracle-db.service
sudo systemctl daemon-reload
sudo systemctl enable oracle-db.service
sudo systemctl start oracle-db.service

--- AFTER YOU EDIT FILE
-----------------------
-----------------------

Run these:-
-----------

sudo systemctl daemon-reload
sudo systemctl enable oracle-db.service
sudo systemctl start oracle-db.service

Check:

systemctl status oracle-db.service

After reboot check :
--------------------

After reboot:
-------------

ps -ef | grep pmon

You should see:
---------------

ora_pmon_orcl

If yes → DB auto-started successfully.


Reality Check - Auto Start on system reboot.

systemctl status oracle-db.service
systemctl is-enabled oracle-db.service
cat /etc/oratab

Restart VM and check

sqlplus /nolog
CONN / AS SYSDBA
STARTUP




Muhammad Abdullah Al Noor

Muhammad Abdullah Al Noor, An Oracle Apex Consultants and founder of Noors Technology (www.noorstech.com). Core Expertise : Database Administration, Oracle Forms and Reports Development, Oracle Apex Application Designer and Development, Linux Professional etc. Also the owner of TrainerBD Training and OraDemy E-Learning. WhatsApp +8801790721177

Post a Comment

Previous Post Next Post