LINUX 环境下使用脚本自动安装ORACLE12C数据库的简单实现

一.系统环境:

OS:Red Hat Enterprise Linux Server release 7.6 

DB:Oracle Database 12c Enterprise Edition Release 12.2.0.1.0

关闭防火墙,SELINUX,/etc/hosts 文件IP对应好主机名称

执行的内容不详细解释,仅供部署时方便参考

 

二.root用户运行的内容

这是root执行的脚本

[root@r100 ~]# cat rootexec.sh 
#!/bin/bash
yum install -y binutils compat-libcap1 compat-libstdc++-33 compat-libstdc++-33.i686 glibc glibc.i686 glibc-devel glibc-devel.i686 ksh libaio libaio.i686 libaio-devel libaio-devel.i686 libX11 libX11.i686 libXau libXau.i686 libXi libXi.i686 libXtst libXtst.i686 libgcc libgcc.i686 libstdc++ libstdc++.i686 libstdc++-devel libstdc++-devel.i686 libxcb libxcb.i686 make nfs-utils net-tools smartmontools sysstat unixODBC unixODBC-devel gcc gcc-c++ libXext libXext.i686 zlib-devel zlib-devel.i686

cp /etc/sysctl.conf /etc/sysctl.conf.bak`date +"%Y-%m-%d-%H-%M-%S"`
(
cat <<EOF
fs.file-max = 6815744
kernel.sem = 250 32000 100 128
kernel.shmmni = 4096
kernel.shmall = 1073741824
kernel.shmmax = 4398046511104
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
fs.aio-max-nr = 1048576
net.ipv4.ip_local_port_range = 9000 65500
EOF
)>>/etc/sysctl.conf
/sbin/sysctl -p

cp /etc/security/limits.conf /etc/security/limits.conf.bak`date +"%Y-%m-%d-%H-%M-%S"`
(
cat <<EOF
oracle   soft   nofile    1024
oracle   hard   nofile    65536
oracle   soft   nproc    16384
oracle   hard   nproc    16384
oracle   soft   stack    10240
oracle   hard   stack    32768
oracle   hard   memlock    134217728
oracle   soft   memlock    134217728
EOF
)>>/etc/security/limits.conf

groupadd oinstall
groupadd dba
useradd -g oinstall -G dba oracle
orapwd='oraclepwd'
echo $orapwd | passwd oracle --stdin > /dev/null 2>&1
mkdir -p /u01/app/oracle/oradata 
mkdir -p /u01/app/oracle/oradata_back

mv /linuxx64_12201_database.zip /u01

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

 

执行效果:

LINUX 环境下使用脚本自动安装ORACLE12C数据库的简单实现

 

三.oracle用户运行的内容

su - oracle 再执行脚本

[oracle@r100 ~]$ cat oracleexec.sh 
#!/bin/bash
(
cat <<\EOF
export ORACLE_HOSTNAME=r100
export ORACLE_UNQNAME=orcl12.r100.db
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/12.2.0.1/db_1
export ORACLE_SID=orcl12
export PATH=/usr/sbin:$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
export PATH=/usr/sbin:$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
)>>/home/oracle/.bash_profile

cd /u01 && unzip linuxx64_12201_database.zip

cp /u01/database/response/db_install.rsp /u01/database/response/db_install.rsp.bak.`date +"%Y-%m-%d-%H-%M-%S"`
cp /u01/database/response/dbca.rsp /u01/database/response/dbca.rsp.bak.`date +"%Y-%m-%d-%H-%M-%S"`
cp /u01/database/response/netca.rsp /u01/database/response/netca.rsp.bak.`date +"%Y-%m-%d-%H-%M-%S"`

sed -i 's/oracle.install.option=/oracle.install.option=INSTALL_DB_SWONLY/g' /u01/database/response/db_install.rsp
sed -i 's/UNIX_GROUP_NAME=/UNIX_GROUP_NAME=oinstall/g' /u01/database/response/db_install.rsp
sed -i 's/INVENTORY_LOCATION=/INVENTORY_LOCATION=\/u01\/app\/oracle\/oraInventory/g' /u01/database/response/db_install.rsp
sed -i 's/ORACLE_HOME=/ORACLE_HOME=\/u01\/app\/oracle\/product\/12.2.0.1\/db_1/g' /u01/database/response/db_install.rsp
sed -i 's/ORACLE_BASE=/ORACLE_BASE=\/u01\/app\/oracle/g' /u01/database/response/db_install.rsp
sed -i 's/oracle.install.db.InstallEdition=/oracle.install.db.InstallEdition=EE/g' /u01/database/response/db_install.rsp
sed -i 's/oracle.install.db.OSDBA_GROUP=/oracle.install.db.OSDBA_GROUP=dba/g' /u01/database/response/db_install.rsp
sed -i 's/oracle.install.db.OSBACKUPDBA_GROUP=/oracle.install.db.OSBACKUPDBA_GROUP=dba/g' /u01/database/response/db_install.rsp
sed -i 's/oracle.install.db.OSDGDBA_GROUP=/oracle.install.db.OSDGDBA_GROUP=dba/g' /u01/database/response/db_install.rsp
sed -i 's/oracle.install.db.OSKMDBA_GROUP=/oracle.install.db.OSKMDBA_GROUP=dba/g' /u01/database/response/db_install.rsp
sed -i 's/oracle.install.db.OSRACDBA_GROUP=/oracle.install.db.OSRACDBA_GROUP=dba/g' /u01/database/response/db_install.rsp
sed -i 's/oracle.install.db.config.starterdb.globalDBName=/oracle.install.db.config.starterdb.globalDBName=orcl12.r100.db/g' /u01/database/response/db_install.rsp
sed -i 's/oracle.install.db.config.starterdb.SID=/oracle.install.db.config.starterdb.SID=orcl12/g' /u01/database/response/db_install.rsp
sed -i 's/oracle.install.db.config.starterdb.characterSet=/oracle.install.db.config.starterdb.characterSet=ZHS16GBK/g' /u01/database/response/db_install.rsp
sed -i 's/SECURITY_UPDATES_VIA_MYORACLESUPPORT=/SECURITY_UPDATES_VIA_MYORACLESUPPORT=false/g' /u01/database/response/db_install.rsp
sed -i 's/DECLINE_SECURITY_UPDATES=/DECLINE_SECURITY_UPDATES=true/g' /u01/database/response/db_install.rsp

 

执行效果:

LINUX 环境下使用脚本自动安装ORACLE12C数据库的简单实现

 

 

四.开始安装数据库软件

[oracle@r100 ~]$ source ~/.bash_profile 
[oracle@r100 ~]$ echo $ORACLE_SID
orcl12
[oracle@r100 ~]$ cd /u01/database/
[oracle@r100 database]$ ls
install  response  rpm  runInstaller  sshsetup  stage  welcome.html
[oracle@r100 database]$ ./runInstaller -force -silent -noconfig -responseFile /u01/database/response/db_install.rsp
Starting Oracle Universal Installer...

Checking Temp space: must be greater than 500 MB.   Actual 17844 MB    Passed
Checking swap space: must be greater than 150 MB.   Actual 3071 MB    Passed
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2021-05-27_06-14-06AM. Please wait ...[oracle@r100 database]$ [WARNING] [INS-32055] The Central Inventory is located in the Oracle base.
   ACTION: Oracle recommends placing this Central Inventory in a location outside the Oracle base directory.
[WARNING] [INS-13014] Target environment does not meet some optional requirements.
   CAUSE: Some of the optional prerequisites are not met. See logs for details. installActions2021-05-27_06-14-06AM.log
   ACTION: Identify the list of failed prerequisite checks from the log: installActions2021-05-27_06-14-06AM.log. Then either from the log file or from installation manual find the appropriate configuration to meet the prerequisites and fix it manually.
You can find the log of this install session at:
 /u01/app/oracle/oraInventory/logs/installActions2021-05-27_06-14-06AM.log
The installation of Oracle Database 12c was successful.
Please check '/u01/app/oracle/oraInventory/logs/silentInstall2021-05-27_06-14-06AM.log' for more details.

As a root user, execute the following script(s):
        1. /u01/app/oracle/oraInventory/orainstRoot.sh
        2. /u01/app/oracle/product/12.2.0.1/db_1/root.sh



Successfully Setup Software.

安装过程中切换至root用户执行两个脚本

[root@r100 ~]# /u01/app/oracle/oraInventory/orainstRoot.sh
Changing permissions of /u01/app/oracle/oraInventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.

Changing groupname of /u01/app/oracle/oraInventory to oinstall.
The execution of the script is complete.
[root@r100 ~]# /u01/app/oracle/product/12.2.0.1/db_1/root.sh
Check /u01/app/oracle/product/12.2.0.1/db_1/install/root_r100_2021-05-27_06-21-29-398109441.log for the output of root script

 

五.配置数据库监听

[oracle@r100 database]$ netca -silent -responsefile /u01/database/response/netca.rsp

Parsing command line arguments:
    Parameter "silent" = true
    Parameter "responsefile" = /u01/database/response/netca.rsp
Done parsing command line arguments.
Oracle Net Services Configuration:
Profile configuration complete.
Oracle Net Listener Startup:
    Running Listener Control: 
      /u01/app/oracle/product/12.2.0.1/db_1/bin/lsnrctl start LISTENER
    Listener Control complete.
    Listener started successfully.
Listener configuration complete.
Oracle Net Services configuration successful. The exit code is 0

 

六.使用脚本自动用静默的方式建库

[oracle@r100 ~]$ cat oracledbca.sh 
#!/bin/bash
dbca -silent -createDatabase \
-templateName /u01/app/oracle/product/12.2.0.1/db_1/assistants/dbca/templates/General_Purpose.dbc \
-gdbname orcl12.r100.db -sid orcl12 -responseFile /u01/database/response/dbca.rsp \
-characterSet ZHS16GBK \
-sysPassword Yourtestpwd1* \   #测试密码
-systemPassword Yourtestpwd1* \
-createAsContainerDatabase true \
-numberOfPDBs 1 \
-pdbName orcl12pdb1 \
-pdbAdminPassword Yourtestpwd1* \
-automaticMemoryManagement false \
-ignorePreReqs

 

执行建库的过程

LINUX 环境下使用脚本自动安装ORACLE12C数据库的简单实现

 

 

七.连接测试

sqlplus命令行连接

[oracle@r100 ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.2.0.1.0 Production on Thu May 27 07:41:47 2021

Copyright (c) 1982, 2016, Oracle.  All rights reserved.


Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL> exit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
[oracle@r100 ~]$ 
[oracle@r100 ~]$ sqlplus system/密码@192.168.252.100/orcl12.r100.db

SQL*Plus: Release 12.2.0.1.0 Production on Thu May 27 07:43:20 2021

Copyright (c) 1982, 2016, Oracle.  All rights reserved.

Last Successful login time: Thu May 27 2021 07:37:40 -07:00

Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL> 

 

使用Navicat连接

LINUX 环境下使用脚本自动安装ORACLE12C数据库的简单实现

LINUX 环境下使用脚本自动安装ORACLE12C数据库的简单实现

 

LINUX 环境下使用脚本自动安装ORACLE12C数据库的简单实现

 

上一篇:网页HTML代码:滚动文字的制作


下一篇:WSL下安装Maude与运行