静默安装oralce数据库

Posted by Derrick on March 19, 2022

linux环境下静默安装oralce数据库

装前检查

准备好两个安装包

linux.x64_11gR2_database_1of2.zip
linux.x64_11gR2_database_2of2.zip


依赖包检查

yum install -y gcc make binutils gcc-c++ compat-libstdc++-33elfutils-libelf-devel elfutils-libelf-devel-static ksh libaio libaio-develnumactl-devel sysstat unixODBC unixODBC-devel pcre-devel



创建组和用户

[root@ORATEST]# groupadd oinstall
[root@ORATEST]# groupadd dba
[root@ORATEST]# useradd -g oinstall -G dba oracle
[root@ORATEST]# passwd oracle
Changing password for user oracle.
New password: 
BAD PASSWORD: it is based on a dictionary word
BAD PASSWORD: is too simple
Retype new password:      #此处密码输入oracle,BAD PASSWORD提示不用管
passwd: all authentication tokens updated successfully.

修改内核参数

# vim /etc/sysctl.conf

kernel.sem = 250 32000 100 128
fs.file-max = 6815744
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
fs.aio-max-nr = 1048576

使设置生效

#sysctl -p

检查设置是否成功

[root@ORATEST ~]# sysctl kernel.sem fs.file-max net.ipv4.ip_local_port_range net.core.rmem_default net.core.rmem_max net.core.wmem_default net.core.wmem_max fs.aio-max-nr
kernel.sem = 250        32000   100     128
fs.file-max = 6815744
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
fs.aio-max-nr = 1048576



修改用户限制

# vi /etc/security/limits.conf

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

vi /etc/pam.d/login

session    required    /lib64/security/pam_limits.so
session    required    pam_limits.so

# vi /etc/profile

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



关闭SELinux及防火墙

[root@ORATEST ~]#sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
[root@ORATEST ~]#setenforce 0
[root@ORATEST ~]#systemctl disable firewalld && systemctl stop firewalld



创建安装目录

[root@ORATEST ~]# mkdir -p /u01/app/
[root@ORATEST ~]# chown -R oracle:oinstall /u01/app/
[root@ORATEST ~]# chmod -R 775 /u01/app/



设置环境变量

[root@ORATEST ~]# su - oracle
[oracle@ORATEST ~]$ vi /home/oracle/.bash_profile vi /home/oracle/.bash_profile
ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
ORACLE_SID=oral; export ORACLE_SID
export ORACLE_OWNER=oracle
export PATH=$PATH:$ORACLE_HOME/bin:/bin:/usr/local/bin:/usr/sbin:/usr/bin
export TNS_ADMIN=$ORACLE_HOME/network/admin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/oracm/lib:/lib:/usr/lib:/usr/local/lib
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export CLASSPATH=${CLASSPATH}:$ORACLE_HOME/JRE
export CLASSPATH=${CLASSPATH}:$ORACLE_HOME/JRE/lib
export CLASSPATH=${CLASSPATH}:$ORACLE_HOME/jlib
export CLASSPATH=${CLASSPATH}:$ORACLE_HOME/rdbms/jlib
export CLASSPATH=${CLASSPATH}:$ORACLE_HOME/network/jlib
export LIBPATH=${CLASSPATH}:$ORACLE_HOME/lib:$ORACLE_HOME/ctx/lib
export SPFILE_PATH=$ORACLE_HOME/dbs
export ORA_NLS10=$ORACLE_HOME/nls/data
umask 022

新开个会话,以Oracle账号登陆,检查环境是否生效

[oracle@ORATEST ~]$ env | more
[oracle@ORATEST ~]$ umask

以root账号,新建oraInst.loc,执行

# vi /etc/oraInst.loc


inventory_loc=/u01/app/oracle/oraInventory
inst_group=oinstall

[root@ORATEST ~]# chown oracle:oinstall /etc/oraInst.loc
[root@ORATEST ~]# chmod 664 /etc/oraInst.loc



执行runInstaller安装Oracle

修改host文件 [root@ORATEST ~]# echo “127.0.0.1 ORATEST “ » /etc/hosts

将两个安装包上传到/u01/app,确保安装包属于oracle用户

[root@ORATEST app]# chown -R oracle:oinstall *.zip
[root@ORATEST app]# ll
total 2295600
-rw-r--r--. 1 oracle oinstall 1239269270 Jan 22 14:29 linux.x64_11gR2_database_1of2.zip
-rw-r--r--. 1 oracle oinstall 1111416131 Jan 22 14:29 linux.x64_11gR2_database_2of2.zip

在oracle账号下,按顺序解压

[oracle@ORATEST app]$unzip linux.x64_11gR2_database_1of2.zip  
[oracle@ORATEST app]$unzip linux.x64_11gR2_database_2of2.zip  

解压后文件都在database目录里

[oracle@ORATEST app]$ ll
total 2295604
drwxr-xr-x. 8 oracle oinstall       4096 Aug 21  2009 database
-rw-r--r--. 1 oracle oinstall 1239269270 Jan 22 14:29 linux.x64_11gR2_database_1of2.zip
-rw-r--r--. 1 oracle oinstall 1111416131 Jan 22 14:29 linux.x64_11gR2_database_2of2.zip

拷贝安装配置模板文件到当前目录(/u01/app)下

[oracle@ORATEST app]$ cp database/response/db_install.rsp  .

创建三个目录,oracle是安装目录,oradata是数据文件目录,oradatabackup,是数据文件备份目录

[oracle@ORATEST app]$ mkdir oracle oradata oradatabackup

编辑db_install.rsp,编辑后和原始文件差异如下

[oracle@ORATEST app]$ diff db_install.rsp database/response/db_install.rsp
29c29
< oracle.install.option=INSTALL_DB_AND_CONFIG
---
> oracle.install.option=
37c37
< ORACLE_HOSTNAME=localhost
---
> ORACLE_HOSTNAME=
42c42
< UNIX_GROUP_NAME=oinstall
---
> UNIX_GROUP_NAME=
47c47
< INVENTORY_LOCATION=/u01/app
---
> INVENTORY_LOCATION=
78c78
< SELECTED_LANGUAGES=en,zh_CN
---
> SELECTED_LANGUAGES=
83c83
< ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
---
> ORACLE_HOME=
88c88
< ORACLE_BASE=/u01/app/oracle
---
> ORACLE_BASE=
99c99
< oracle.install.db.InstallEdition=EE
---
> oracle.install.db.InstallEdition=
142c142
< oracle.install.db.DBA_GROUP=dba
---
> oracle.install.db.DBA_GROUP=
147c147
< oracle.install.db.OPER_GROUP=dba
---
> oracle.install.db.OPER_GROUP=
160c160
< oracle.install.db.config.starterdb.type=GENERAL_PURPOSE
---
> oracle.install.db.config.starterdb.type=
165c165
< oracle.install.db.config.starterdb.globalDBName=orcl
---
> oracle.install.db.config.starterdb.globalDBName=
170c170
< oracle.install.db.config.starterdb.SID=orcl
---
> oracle.install.db.config.starterdb.SID=
184c184
< oracle.install.db.config.starterdb.characterSet=ZHS16GBK
---
> oracle.install.db.config.starterdb.characterSet=AL32UTF8
200c200
< oracle.install.db.config.starterdb.memoryLimit=1024
---
> oracle.install.db.config.starterdb.memoryLimit=
233c233
< oracle.install.db.config.starterdb.password.ALL=oracle
---
> oracle.install.db.config.starterdb.password.ALL=
278,279c278
< oracle.install.db.config.starterdb.dbcontrol.emailAddress=test@qq.com
< 
---
> oracle.install.db.config.starterdb.dbcontrol.emailAddress=
325c324
< oracle.install.db.config.starterdb.storageType=FILE_SYSTEM_STORAGE
---
> oracle.install.db.config.starterdb.storageType=
333c332
< oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=/u01/app/oradata
---
> oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=
340c339
< oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=/u01/app/oradatabackup
---
> oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=
386c385
< DECLINE_SECURITY_UPDATES=true
---
> DECLINE_SECURITY_UPDATES=

这些配置项也可以在安装命令参数里写,本文选择编辑db_install.rsp达到效果。 安装前文件和环境如下

[oracle@ORATEST app]$ ll
total 2295640
drwxr-xr-x. 8 oracle oinstall       4096 Aug 21  2009 database
-rw-r--r--. 1 oracle oinstall      22770 Jan 22 15:15 db_install.rsp
-rw-r--r--. 1 oracle oinstall 1239269270 Jan 22 14:29 linux.x64_11gR2_database_1of2.zip
-rw-r--r--. 1 oracle oinstall 1111416131 Jan 22 14:29 linux.x64_11gR2_database_2of2.zip
drwxr-xr-x. 2 oracle oinstall       4096 Jan 22 14:56 oracle
drwxr-xr-x. 2 oracle oinstall       4096 Jan 22 15:12 oradata
drwxr-xr-x. 2 oracle oinstall       4096 Jan 22 15:12 oradatabackup
[oracle@ORATEST app]$ env | grep ORA
ORACLE_OWNER=oracle
ORA_NLS10=/u01/app/oracle/product/11.2.0/db_1/nls/data
ORACLE_SID=oral
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1

执行安装命令

[oracle@ORATEST database]$ ./runInstaller -silent -force -noconfig -ignorePrereq -responseFile /u01/app/db_install.rsp
Starting Oracle Universal Installer...
Checking Temp space: must be greater than 120 MB.   Actual 1628 MB    Passed
Checking swap space: must be greater than 150 MB.   Actual 65535 MB    Passed
Preparing ...
   CAUSE: ...
   ACTION: ....
[WARNING] [INS-30011] ...
The following configuration scripts need to be executed as the "root" user. 
 #!/bin/sh 
 #Root scripts to run
/u01/app/oracle/product/11.2.0/db_1/root.sh
To execute the configuration scripts:
         1. Open a terminal window 
         2. Log in as "root" 
         3. Run the scripts 
         4. Return to this window and hit "Enter" key to continue 
Configuration assistants have not been run. This can happen for following reasons - either root.sh is to be run before config or Oracle Universal Installer was invoked with the -noConfig option.
"/u01/app/oracle/product/11.2.0/db_1/cfgtoollogs/configToolAllCommands" script contains all commands to be executed by the configuration assistants. This file may be used to run the configuration assistants outside of OUI. Note that you may have to update this script with passwords (if any) before executing the same.
Successfully Setup Software.

输出Successfully Setup Software表示安装成功。同时提示以root账号执行/u01/app/oracle/product/11.2.0/db_1/root.sh脚本。

[root@ORATEST ~]# /u01/app/oracle/product/11.2.0/db_1/root.sh
Check /u01/app/oracle/product/11.2.0/db_1/install/root_ORATEST_2021-01-25_08-19-46.log for the output of root script

执行完Oracle软件安装完成。



执行dbca建立数据库

oracle账号执行,拷贝建立数据库的配置文件dbca.rsp到app目录下

[oracle@ORATEST app]$ cp /u01/app/oracle/product/11.2.0/db_1/assistants/dbca/dbca.rsp .

编辑dbca.rsp,编写完各项目如下

[oracle@ORATEST app]$ cat dbca.rsp | grep -v ^# | grep -v ^$
[GENERAL]
RESPONSEFILE_VERSION = "11.2.0"
OPERATION_TYPE = "createDatabase"
[CREATEDATABASE]
GDBNAME = "ORCL"
SID = "orcl"
TEMPLATENAME = "General_Purpose.dbc"
SYSPASSWORD = "oracle"
SYSTEMPASSWORD = "oracle"
DATAFILEDESTINATION =/u01/app/oradata
CHARACTERSET = "ZHS16GBK"
TOTALMEMORY = "8000"
[createTemplateFromDB]
SOURCEDB = "myhost:1521:orcl"
SYSDBAUSERNAME = "system"
TEMPLATENAME = "My Copy TEMPLATE"
[createCloneTemplate]
SOURCEDB = "orcl"
TEMPLATENAME = "My Clone TEMPLATE"
[DELETEDATABASE]
SOURCEDB = "orcl"
[generateScripts]
TEMPLATENAME = "New Database"
GDBNAME = "orcl11.us.oracle.com"
[CONFIGUREDATABASE]
[ADDINSTANCE]
DB_UNIQUE_NAME = "orcl11g.us.oracle.com"
NODELIST=
SYSDBAUSERNAME = "sys"
[DELETEINSTANCE]
DB_UNIQUE_NAME = "orcl11g.us.oracle.com"
INSTANCENAME = "orcl11g"
SYSDBAUSERNAME = "sys"

同样这个文件的内容也可以在执行dbca命令时以参数形式输入,本文选择编辑dbca.rsp的方式。app目录下执行命令建立数据库

[oracle@ORATEST app]$ dbca -silent -responseFile ./dbca.rsp 
Copying database files
1% complete
3% complete
37% complete
Creating and starting Oracle instance
40% complete
45% complete
50% complete
55% complete
56% complete
60% complete
62% complete
Completing Database Creation
66% complete
70% complete
73% complete
85% complete
96% complete
100% complete
Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/ORCL/ORCL.log" for further details.

此时数据库已经启动,可以访问了。下面指令测试是否成功

[oracle@ORATEST ~]$ sqlplus / as sysdba
...
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup;
ORACLE instance started.

Total System Global Area 8351150080 bytes
Fixed Size                  2214936 bytes
Variable Size            5100274664 bytes
Database Buffers         3221225472 bytes
Redo Buffers               27435008 bytes
Database mounted.
Database opened.
SQL> 

shutdown和startup都成功执行,说明数据库正常启动了。/u01/app/oradata/ORCL目录下是刚建立数据库ORCL的数据文件

[oracle@ORATEST oradata]$ cd ORCL/
[oracle@ORATEST ORCL]$ ll
total 1433964
-rw-r----- 1 oracle oinstall   9748480 Jan 25 15:42 control01.ctl
-rw-r----- 1 oracle oinstall  52429312 Jan 25 15:23 redo01.log
-rw-r----- 1 oracle oinstall  52429312 Jan 25 15:41 redo02.log
-rw-r----- 1 oracle oinstall  52429312 Jan 25 15:23 redo03.log
-rw-r----- 1 oracle oinstall 513810432 Jan 25 15:38 sysaux01.dbf
-rw-r----- 1 oracle oinstall 702554112 Jan 25 15:36 system01.dbf
-rw-r----- 1 oracle oinstall  30416896 Jan 25 11:41 temp01.dbf
-rw-r----- 1 oracle oinstall  78651392 Jan 25 15:36 undotbs01.dbf
-rw-r----- 1 oracle oinstall   5251072 Jan 25 15:23 users01.dbf



配置tnsnames.ora

network/admin下新建ora文件

[oracle@ORATEST ~]$ vi /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora

webdb =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = '自己的IP地址')(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )

远程客户端的tnsnames.ora写上相同的配置。如果远程在PC上,ora文件放在TNS_ADMIN环境变量对应的目录下

执行lsnrctl启动监听,PLSQL连接

监听的配置文件不用编写,采用默认配置。检查webdb能否解析

[oracle@ORATEST ~]$ tnsping webdb
...
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = '自己的IP地址')(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl)))
TNS-12541: TNS:no listener

可以解析出地址和端口号,否则会报Failed to resolve name。no listerer提示监听程序没有启动,启动监听

[oracle@ORATEST ~]$ lsnrctl start
...
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ORATEST)(PORT=1521)))

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date                31-JAN-2021 13:55:20
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Log File         /u01/app/oracle/diag/tnslsnr/ORATEST/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ORATEST)(PORT=1521)))
The listener supports no services
The command completed successfully

启动成功。PLSQL连接,用户system,密码oracle,数据库下拉选择webdb,可以成功登陆