Section 27 Linux Installation of Oracle Database

Table of Contents

1. Deploy user groups depending on the environment

2.Install oracle

2.1. Path description

2.2. Create a new directory under root

2.3. Upload the oracle installation package

2.4. Modify host

2.5. Install necessary dependency packages

2.6. Modify kernel parameters (modify as needed)

2.7. Modify configuration

2.7.1. Configure user resource limits

2.7.2. Edit login file

2.7.3. Edit profile file

2.7.4. Create database directory

2.7.5. Configure Oracle user

2.7.5.1 Configure Oracle environment variables

2.7.5.2.sqlplus improvements

2.8. Start installation

2.8.1. Unzip the installation package

2.8.2. Create a new etc directory

2.8.3. Configure environment variables

2.8.4. Edit file content

2.8.4.1. File upload method to replace configuration file

2.8.5.Installation

3. Configure monitoring

4. Create table spaces and users

4.1. Modify the library building file

4.2.Building database

4.3. Log in to the database to open the instance

4.3.1. Create temporary table space

4.3.2. Create table space

4.3.3. Create user and specify table space

5.Auto-start configuration

5.1. Edit under oracle user

5.2. Edit under root

6.Recover dmp files

7. Regular backup and recovery

7.1. Method 1: Directly upload the edited .sh file

7.2. Method 2: Create dbbak.sh file


1. Depend on environment deployment user group

Execute the oinstall command to create a user group:

groupadd oinstall

Execute the create user group dba command:

groupadd dba

Execute the command to create user Oracle and add the Oracle user to the oinstall and dba user groups:

useradd -g oinstall -G dba oracle

Set the password for the Oracle user and enter the password twice as prompted:

passwd oracle

View the creation result command:

id oracle

2.Install oracle

2.1. Path description

oracle installation directory:/app/database/oracle

Oracle installation file directory:/app/tools/database

Copy the three decompressed file storage paths: /app/oracle/etc

2.2. Create a new directory under root

The purpose is to upload the installation files here and assign the newly created directory to the oracle user under the oinstall group. and authorize

Create the directory folder /app/tools/database:

mkdir -p /app/tools/database

Authorize the /app/tools/database folder:

chown -R oracle:oinstall /app/tools/database/ 

Authorize the /app/tools/database folder to modify the access permissions of files or directories:

chmod -R 775 /app/tools/database/

2.3. Upload the oracle installation package

(1) Upload the oracle installation program compressed package under the oracle user. When uploading files, use the oracle user to upload

(2) Turn off the firewall

Execute the shutdown firewall command:

systemctl stop firewalld.service

Execute the command to disable the firewall from starting:

systemctl disable firewalld.service

(3) Close selinux

Excuting an order:

/usr/sbin/sestatus -v 

If the SELinux status parameter is enabled, it means it is in the open state. You do not need to perform the following operations. If not, you need to execute the following commands.

Execute the command to temporarily shut down selinux (without restarting the machine):

setenforce 0

Shut down selinux permanently:

Execute the edit config configuration file command:

vim /etc/selinux/config

Set SELINUX=disabled in the file

2.4.Modify host

Execute editing command:

vim /etc/hosts

Add the mapping relationship between IP address and domain name, enter the hosts file, and add the actual IP of the machine and the host user name at the end of the file

ip oracle

View hostname command:

hostname

Modify host name

vim /etc/hostname

Set the static hostname command:

Syntax: hostnamectl set-hostname hostname

Example:

hostnamectl set-hostname oracle

2.5. Install necessary dependency packages

Check if installed command:

rpm -q binutils compat-libcap1 compat-libstdc + + -33 gcc gcc-c + + glibc glibc-devel ksh libaio libaio-devel libgcc libstdc + + libstdc + + -devel libXi libXtst make sysstat unixODBC unixODBC-devel< /pre>
<p>Execute the installation command (if an error occurs, execute it a few more times):</p>
<pre>yum -y install binutils compat-libcap1 compat-libstdc + + -33 compat-libstdc + + -33*i686 compat-libstdc + + -33*.devel compat-libstdc + + -33 compat-libstdc + + - 33*.devel gcc gcc-c + + glibc glibc*.i686 glibc-devel glibc-devel*.i686 ksh libaio libaio*.i686 libaio-devel libaio-devel*.devel libgcc libgcc*.i686 libstdc + + libstdc + + *.i686 libstdc + + -devel libstdc + + -devel*.devel libXi libXi*.i686 libXtst libXtst*.i686 make sysstat unixODBC unixODBC*.i686 unixODBC-devel unixODBC-devel*.i686

View after installation

2.6. Modify kernel parameters (modify as needed)

(1) Execute and edit the sysctl.conf command:

vim /etc/sysctl.conf

(2) Add the following content to the sysctl.conf file:

fs.aio-max-nr=1048576
fs.file-max=6815744
kernel.shmall=524288
kernel.shmmax=2147483647
kernel.sem=250 32000 100 128
kernel.shmmni=4096
kernel.panic_on_oops=1
net.core.rmem_default=262144
net.core.rmem_max=4194304
net.core.wmem_default=262144
net.core.wmem_max=1048576
net.ipv4.conf.all.rp_filter=2
net.ipv4.conf.default.rp_filter=2
net.ipv4.ip_local_port_range=9000 65500

(3) The parameters added above are repeated, so you need to annotate the repeated parameters in the file.

(4) To make the configuration file take effect, execute the following command:

sysctl -p

2.7. Modify configuration

2.7.1. Configure user resource limits

(1) Edit the limits.conf file command:

vim /etc/security/limits.conf

(2) Add the following content at the end of the file:

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

2.7.2.Edit login file

(1) Execute the edit login file command:

vim /etc/pam.d/login

(2) Add the following content to the end of the file:

session required pam_limits.so

2.7.3.Edit profile file

(1) Open and edit the file /etc/profile command:

vim /etc/profile

(2) Add the following content at the end of the file:

if [ $USER = "oracle" ]; then
    if [ $SHELL = "/bin/ksh" ]; then
        ulimit -p 16384 ulimit -n 65536
    else
        ulimit -u 16384 -n 65536
    fi
fi

(3) Make the configuration file effective

source /etc/profile

2.7.4. Create database directory

Created under the root user because the oracle user does not have permission to create folders

Create folder:

mkdir -p /app/database/oracle 

Grant permissions to the folder:

chown -R oracle:oinstall /app/database/oracle/

Grant 775 permissions to the folder:

chmod -R 775 /app/database/oracle/

2.7.5. Configure Oracle user

Switch to the oracle user:

su - oracle

The default password used by oracle is orcl123456

2.7.5.1 Configure Oracle environment variables

(1) Edit the .bash_profile file

Open and edit the environment variable file and configure the oracle user environment variables

vim ~/.bash_profile

(2) Add the following content at the end:

export ORACLE_BASE=/data/server/oracle
export ORACLE_SID=orcl

Note:

orcl: database instance name, specified when creating the database

(3) Make the configuration effective

source ~/.bash_profile
2.7.5.2.sqlplus improvement

During the use of the default sqlplus, I found that it is difficult to use. The best example is that the backspace key cannot be used and the up and down keys that drop out of historical commands are introduced here. The improvement of the backspace key is introduced here.

(1) Switch to oracle user:

su - oracle

(2) Open and edit the user environment variable configuration file:

vim ~/.bash_profile

(3) Add the following content at the end of the file and save and exit

stty erase ^h

(4) Make the configuration file effective

source ~/.bash_profile

Use the echo command to view individual environment variables

echo $PATH 

2.8. Start installation

2.8.1. Unzip the installation package

Enter the directory where the compressed package is stored:

cd /app/tools/database

unzip files:

unzip linuxx64_12201_database.zip

2.8.2. Create a new etc directory

(1) Switch to the root user:

su

(2) Create a new etc folder

mkdir etc

You can use the installation and deployment backup file to upload, and the parameters inside have been changed.

The following copy process is applicable to the first installation and deployment implementation

(3) Copy the three files under /app/tools/database/database/response/* after decompression to the etc directory

cp /app/tools/database/database/response/* /app/etc/

(4) Set permissions

Authorize folders and files:

chown -R oracle /app/etc
chmod 775 -R /app/etc/*.rsp

(5) View file permissions

ls -la etc/

2.8.3. Configure environment variables

(1) Switch to oracle user:

su - oracle

(2) Configure environment variables:

vim ~/.bash_profile

(3) Add the following content to the end of the file

export ROACLE_PID=oral12
#export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
export ORACLE_HOME=$ORACLE_BASE/product
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib
export PATH=$PATH:$ORACLE_HOME/bin
export LANG="zh_CN.UTF-8"
export NLS_LANG="SIMPLIFIED CHINESE_CHINA.AL32UTF8"
export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'

(4) Make the configuration effective

source ~/.bash_profile

2.8.4. Edit file content

(1) Modify the db_install.rsp file

vim /app/etc db_install.rsp

(2) Add the following parameters below

oracle.install.option=INSTALL_DB_SWONLY //Installation type
UNIX_GROUP_NAME=oinstall // Installation group
INVENTORY_LOCATION=/app/database/oracle/oraInventory //INVENTORY directory (if not filled in, it is the default value)
ORACLE_HOME=/app/database/oracle/product //Home directory
ORACLE_BASE=/app/database/oracle //base directory
oracle.install.db.InstallEdition=EE      //Enterprise edition
oracle.install.db.OSDBA_GROUP=dba
oracle.install.db.OSOPER_GROUP=oinstall
oracle.install.db.OSBACKUPDBA_GROUP=oinstall
oracle.install.db.OSDGDBA_GROUP=oinstall
oracle.install.db.OSKMDBA_GROUP=oinstall
oracle.install.db.OSRACDBA_GROUP=oinstall
oracle.install.db.config.starterdb.type=GENERAL_PURPOSE //Database type
oracle.install.db.config.starterdb.globalDBName=orcl //Specify the global database name of the starter database
oracle.install.db.config.starterdb.SID=orcl
oracle.install.db.config.starterdb.characterSet = AL32UTF8 //Specify the starter database character set
oracle.install.db.config.starterdb.memoryLimit=81920 //Automatically manage memory memory (M)
#oracle.install.db.config.starterdb.password.ALL=oracle//Set all database users to use the same password
SECURITY_UPDATES_VIA_MYORACLESUPPORT=false //Whether users are allowed to set passwords
DECLINE_SECURITY_UPDATES=true
2.8.4.1. File upload method replaces configuration file

(1) Delete the source file

rm -f db_install.rsp

(2) Upload the db_install.rsp file

rz

(3) Due to deletion, permissions need to be granted to the file again before uploading.

chmod 775 -R /app/etc/*.rsp

2.8.5.Installation

(1) Enter the oracle decompression directory:

cd /app/tools/database/database

(2) Execute the installation command:

./runInstaller -ignoreSysPrereqs -ignorePrereq -waitforcompletion -showProgress -silent -responseFile /app/etc/db_install.rsp

(3) After the above results appear, execute these two files as root according to the operation.

/app/database/oracle/oraInventory/orainstRoot.sh
/app/database/oracle/product/root.sh

(4) Installation completed

3. Configure monitoring

(1) Switch to the oracle user:

su oracle

(2) Execute the configuration monitoring command:

netca -silent -responseFile /app/etc/netca.rsp

(3) Check the status, opening and closing of the monitoring service

View listening status command:

/app/database/oracle/product/bin/lsnrctl status

Start listening command:

/app/database/oracle/product/bin/lsnrctl start

Turn off listening command:

/app/database/oracle/product/bin/lsnrctl stop

(4) Check the status. If it is started, the following picture will be displayed:

The listener does not support the service

You need to add code to the listening file listener.ora

Execute the command to edit the listener.ora file:

vim /app/database/oracle/product/network/admin/listener.ora

Add the following content to the listener.ora file:

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = orcl)
      (ORACLE_HOME = /app/database/oracle/product)
      (SID_NAME = orcl)
    )
  )

(5) If there is no problem with the above configuration, turn off the monitoring and restart it

Turn off listening command:

/app/database/oracle/product/bin/lsnrctl stop

Start listening command:

/app/database/oracle/product/bin/lsnrctl start

4. Create table space and user

Specifies whether the database is configured as a container database

oracle.install.db.ConfigureAsContainerDB = true

Specify the name of the pluggable database in the Container database

oracle.install.db.config.PDBName = pdborcl

If the above two configurations are added to the installation file, an additional set of table spaces and temporary table spaces need to be created when creating the table space.

4.1. Modify the library building file

(1) Enter and edit the dbca.rsp file:

vim /app/etc/dbca.rsp

(2) Add the following content:

responseFileVersion=/oracle/assistants/rspfmt_dbca_response_schema_v12.2.0
gdbName=orcl #Specify the global database name
sid=orcl #Database instance name
databaseConfigType=SI
createAsContainerDatabase=true #If it is used as a container database, this item needs to be set to true
numberOfPDBs=1 #Specify the number of pdbs to be created {This parameter affects the creation of table spaces}
pdbName=orclpdb
templateName=/app/database/oracle/product/assistants/dbca/templates/General_Purpose.dbc #Use the template file General_Purpose.dbc to create a database
emExpressPort=5500 //Enterprise Manager configuration type
omsPort=0 //EM manager port number
characterSet=AL32UTF8 #Specify the character set of the database
listeners=LISTENER #Specify the listener list to register the database. Multiple lists separated by commas
memoryPercentage=40 #Percentage of physical memory used for Oracle
automaticMemoryManagement=false #Specify the use of automatic memory management
totalMemory=0 #The total amount of memory allocated to Oracle (in MB)

4.2. Database creation

Excuting an order:

dbca -silent -createDatabase -responseFile /app/etc/dbca.rsp

Set password (123456)

4.3. Log in to the database to open the instance

Log in:

sqlplus / as sysdba

Start the instance:

startup

Started

Query temporary table space file sql:

select name from v$tempfile;

Query user table space file sql:

select name from v$datafile;

View the tablespace sql in the current database:

select TABLESPACE_NAME from dba_tablespaces;

Because oracle12c involves cdb and pdb, you must pay attention to the current container when creating table spaces and temporary table spaces. The default entry is cdb. After executing the two creation statements of cdb, switch to the pdb container and execute the pdb creation statement again.

Convert container to CDB:

alter session set container=CDB$ROOT; 

Convert container to PDB:

alter session set container=ORCLPDB;

View the current container:

show con_name

4.3.1. Create temporary table space

CREATE TEMPORARY TABLESPACE C##AK_DQH_COLLEGETEMP
TEMPFILE '/app/database/oracle/oradata/orcl/ak_dqh_collegetemp.dbf'
SIZE 132M REUSE
AUTOEXTEND ON
NEXT 32M MAXSIZE unlimited
EXTENT MANAGEMENT LOCAL;

4.3.2. Create table space

CREATE TABLESPACE C##AK_DQH_COLLEGE
DATAFILE '/app/database/oracle/oradata/orcl/ak_dqh_college.dbf'
SIZE 132M REUSE
AUTOEXTEND ON
NEXT 32M MAXSIZE unlimited
EXTENT MANAGEMENT LOCAL;

Convert container to PDB

alter session set container=ORCLPDB;

Execute after switching users

CREATE TEMPORARY TABLESPACE C##AK_DQH_COLLEGETEMP
TEMPFILE '/app/database/oracle/oradata/orcl/orclpdb/ak_dqh_collegetemp.dbf'
SIZE 132M REUSE
AUTOEXTEND ON
NEXT 32M MAXSIZE unlimited
EXTENT MANAGEMENT LOCAL;

Execute after switching users

CREATE TABLESPACE C##AK_DQH_COLLEGE
DATAFILE '/app/database/oracle/oradata/orcl/orclpdb/ak_dqh_college.dbf'
SIZE 132M REUSE
AUTOEXTEND ON
NEXT 32M MAXSIZE unlimited
EXTENT MANAGEMENT LOCAL;

To use a pluggable database, first check the currently available relational databases.

show pdbs; 

View the currently connected database name

show con_name;

4.3.3. Create a user and specify the table space

must

Convert container to CDB

alter session set container=CDB$ROOT;

Create user and specify table space

CREATE USER c##ak_dqh_college IDENTIFIED BY ak_dqh_college
DEFAULT TABLESPACE C##AK_DQH_COLLEGE
TEMPORARY TABLESPACE C##AK_DQH_COLLEGETEMP; 

User empowerment

grant connect,resource,dba to c##ak_dqh_college; 

Change user password

alter user C##AK_DQH_COLLEGE identified by 123456;

Delete user (no need to execute)

drop user C##AK_DQH_COLLEGE cascade;
select * from all_users;

5. Self-starting configuration

5.1. Edit under the oracle user

(1) Open the file and edit dbstart

vim /app/database/oracle/product/bin/dbstart

(2) Change ORACLE_HOME_LISTNER=$1 to ORACLE_HOME_LISTNER=$ORACLE_HOME

vim /app/database/oracle/product/bin/dbshut #Edit monitoring, automatically start monitoring path

(3) Change ORACLE_HOME_LISTNER=$1 to ORACLE_HOME_LISTNER=$ORACLE_HOM

(4) Edit oratab file

vim /etc/oratab

(5) Find this line in the file (orcl:/opt/oracle/app/product/12.1.0/dbhome_1:N) and replace N with Y

5.2. Edit under root

(1) Edit the rc.local file

vim /etc/rc.d/rc.local

Add the following content to the end of the rc.local file. Note that there can be no spaces in front of each line. Pay attention to the path location.

su oracle -lc "/app/database/oracle/product/bin/lsnrctl start"
su oracle -lc /app/database/oracle/product/bin/dbstart

(Note that the path must not be written as an environment variable. Note: the first command has spaces, so it must be quoted)

6. Recover dmp files

Execute under Oracle user

Enter the directory where the backup files are stored

cd /app/database/oracle/

Create folder

mkdir dbbak

Go to folder

cd dbbak/

Create folder

mkdir data

Go to folder

cd data

Upload dmp file

rz

Import dmp file

imp c##ak_dqh_college/123456@localhost/ORCL file=/app/database/oracle/dbbak/data/orcl20200909210001.dmp ignore=y full=y ; 

Note:

c##ak_dqh_colleg: username
123456: Password
Localhost:ip
ORCL: database instance name
/app/database/oracle/dbbak/data/orcl20200909210001.dmp: file path
ignore=y: ignore error messages
full=y: import all

7. Scheduled backup and recovery

Execute under oracle user

7.1. Method 1: Directly upload the edited .sh file

(1) File upload, upload the dbbak.sh you edited directly

Go to backup folder

cd dbbak

Create folder

mkdir shell 

Create folder

mkdir log 
cd shell

Upload the dbbak.sh file (written backup script)

rz

Authorize dbbak.sh

chmod 775 -R dbbak.sh 

7.2. Method 2: Create dbbak.sh file

(1) Create a new dbbak.sh file

vim dbbak.sh

(2) The following is the file content:

#[plain]view plaincopy
#!/bin/sh
export ORACLE_BASE=/app/database/oracle
export ORACLE_HOME=$ORACLE_BASE/product
export ORACLE_SID=orcl
export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
export DATA_DIR=/app/database/oracle/dbbak/data
export LOGS_DIR=/app/database/oracle/dbbak/log
export DELTIME=`date -d "7 days ago" + %Y%m%d`
export BAKUPTIME=`date + %Y%m%d%H%M%S`
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
mkdir -p $DATA_DIR
mkdir -p $LOGS_DIR
echo "Starting bakup..."
echo "Bakup filepath$DATA_DIR/$BAKUPTIME.dmp"
exp c##ak_dqh_college/123456@orcl file=$DATA_DIR/orcl$BAKUPTIME.dmp log=$LOGS_DIR/orcl$BAKUPTIME.log
echo "Delete the file bakup before 30days...filepath: $DATA_DIR/orcl$DELTIME*.dmp "
rm -rf $DATA_DIR/orcl$DELTIME*.dmp
rm -rf $LOGS_DIR/orcl$DELTIME*.log
echo "Delete the file bakup successfully."
echo "Bakup completed."

(3) Edit timing files

cd to the shell directory and run ls to see the dbbak and sh files

Execute the command to edit the scheduled task file:

 crontab -e 

Set synchronized system time:

*/1 * * * * /sbin/nepdate -u cn.pool.ntp.org
*/1 * * * * /app/database/oracle/dbbak/shell/dbbak.sh 

Regular backup

Set up backup every night at 9pm:

0 21 * * * /app/database/oracle/dbbak/shell/dbbak.sh