CentOS 静默(命令行)方式安装Oracle12cr1

前言

网上安装Oracle的教程大多是基于图形界面安装的,给公司的远程服务器装还是命令行方式(又分响应文件方式安装和命令行方式安装)比较方便。其实本质都是一样的。花了很长时间才装上,所以记录下来,防止以后还会碰到。

Oracle官网下载安装包(约2.5G)

  • linuxamd64_12102_database_1of2.zip
  • linuxamd64_12102_database_2of2.zip

修改host文件

/etc/hosts文件追加本机ip地址和hostname

设置内核参数

/etc/sysctl.conf文件追加以下内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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

验证上面的配置的命令: sysctl -p

设置PAM资源限制

/etc/security/limits.conf文件追加以下内容:

1
2
3
4
5
oracle              soft    nproc   2047
oracle hard nproc 16384
oracle soft nofile 4096
oracle hard nofile 65536
oracle soft stack 10240

/etc/pam.d/login文件追加以下内容:

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

下载各种安装包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
yum install binutils -y
yum install compat-libstdc++-33 -y
yum install compat-libstdc++-33.i686 -y
yum install gcc -y
yum install gcc-c++ -y
yum install glibc -y
yum install glibc.i686 -y
yum install glibc-devel -y
yum install glibc-devel.i686 -y
yum install ksh -y
yum install libgcc -y
yum install libgcc.i686 -y
yum install libstdc++ -y
yum install libstdc++.i686 -y
yum install libstdc++-devel -y
yum install libstdc++-devel.i686 -y
yum install libaio -y
yum install libaio.i686 -y
yum install libaio-devel -y
yum install libaio-devel.i686 -y
yum install libXext -y
yum install libXext.i686 -y
yum install libXtst -y
yum install libXtst.i686 -y
yum install libX11 -y
yum install libX11.i686 -y
yum install libXau -y
yum install libXau.i686 -y
yum install libxcb -y
yum install libxcb.i686 -y
yum install libXi -y
yum install libXi.i686 -y
yum install make -y
yum install sysstat -y
yum install unixODBC -y
yum install unixODBC-devel -y
yum install zlib-devel -y
yum install elfutils-libelf-devel -y

创建用户和用户组

1
2
3
4
5
groupadd -g 54321 oinstall
groupadd -g 54322 dba
groupadd -g 54323 oper

useradd -g oinstall -G dba,oper oracle

给oracle用户设置密码:

1
passwd oracle

配置SELINUX

修改/etc/selinux/config文件中的SELINUX值:
SELINUX=permissive

运行下面命令验证:

1
2
$ setenforce Permissive
setenforce: SELinux is disabled

关闭防火墙

1
2
systemctl stop firewalld
systemctl disable firewalld

创建oracle安装目录

1
2
3
mkdir -p /opt/soft/oracle/product/oracle12cr1
chown -R oracle:oinstall /opt/soft/
chmod -R 775 /opt/soft/

修改用户环境变量

/home/oracle/.bash_profile文件追加以下内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Oracle Settings
export TMP=/tmp
export TMPDIR=$TMP
ORACLE_HOSTNAME=... # 用户名
export ORACLE_UNQNAME=orcl
export ORACLE_BASE=/opt/soft/oracle/product # 刚才创建的
export ORACLE_HOME=$ORACLE_BASE/oracle11gr2 # 刚才创建的
export ORACLE_SID=orcl
export ORACLE_TERM=xterm
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/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
#export TNS_ADMIN=$ORACLE_HOME/network/admin
#export ORACLE_OWNER=oracle
#export SPFILE_PATH=$ORACLE_HOME/dbs
#export ORA_NLS10=$ORACLE_HOME/nls/data

source ~/.bash_profile 使之生效

安装包上传到服务器并解压

1
2
unzip linuxamd64_12102_database_1of2.zip
unzip linuxamd64_12102_database_1of2.zip

备份应答文件

1
2
3
cd /home/oracle/database/response
mkdir rsp_bak
cp *.rsp ./rsp_bak/

删除应答文件中的以#开头的注释行和空行

1
sed -i 's/^#.*$//g' *.rsp && sed -i '/^$/d' *.rsp

配置db_install.rsp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
oracle.install.option=INSTALL_DB_SWONLY # 安装类型
ORACLE_HOSTNAME=... # 主机名称(hostname查询,这里要注意,主机名要在 /etc/hosts 文件中配置好ip对应关系,否则安装会报错)
UNIX_GROUP_NAME=oinstall # 安装组
INVENTORY_LOCATION=/opt/soft/oracle/oraInventory # INVENTORY目录位置,需填写成自己创建的目录位置,不要放在oracle_base目录下
SELECTED_LANGUAGES=en # 选择支持语言
ORACLE_HOME=/opt/soft/oracle/product/oracle12cr1 # 数据库目录地址
ORACLE_BASE=/opt/soft/oracle/product # BASE目录地址
oracle.install.db.InstallEdition=EE # 指定oracle版本
oracle.install.db.DBA_GROUP=dba # dba用户组
oracle.install.db.OPER_GROUP=oper # oper用户组
oracle.install.db.BACKUPDBA_GROUP=oinstall
oracle.install.db.DGDBA_GROUP=oinstall
oracle.install.db.KMDBA_GROUP=oinstall
oracle.install.db.config.starterdb.globalDBName=orcl # 这里要和前面配置的host_profile中的sid一致
oracle.install.db.config.starterdb.SID=orcl # 这里要和前面配置的host_profile中的sid一致
oracle.install.db.ConfigureAsContainerDB=true # 是否配置CDB
oracle.install.db.config.PDBName=pdb1 # pdb名称

注意:

  • db_install.rsp文件中INVENTORY_LOCATIONORACLE_BASEORACLE_HOME三个字段应该配置成决定路径,否则安装时会出现[INS-32015]错误
  • 安装时应答文件中不要有中文注释
  • 如果安装失败可能是配置错误导致的,可以简化配置使用默认值

使用响应文件安装Oracle

1
./runInstaller -silent -force -noconfig -responseFile /home/oracle/database/response/db_install.rsp

运行结束后,查看制定的日志,看看是否安装成功

运行orainstRoot.sh和root.sh脚本

1
2
$ /opt/soft/oracle/oraInventory/orainstRoot.sh
$ /opt/soft/oracle/product/oracle12cr1/root.sh

静默配置监听

1
$ $ORACLE_HOME/bin/netca /silent /responseFile /home/oracle/database/response/netca.rsp

修改配置文件 dbca.rsp 并使用 dbca 创建实例

文件:/home/oracle/database/response/dbca.rsp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[GENERAL]
RESPONSEFILE_VERSION = "12.1.0"
OPERATION_TYPE = "createDatabase"
[CREATEDATABASE]
GDBNAME = "orcl"
SID = "orcl"
TEMPLATENAME = "General_Purpose.dbc"
CHARACTERSET="AL32UTF8"
NATIONALCHARACTERSET="UTF8"
SYSPASSWORD="..."
SYSTEMPASSWORD="..."
CREATEASCONTAINERDATABASE = true # 是否配置为CDB
PDBNAME = pdb1 # pdb名称
PDBADMINPASSWORD = "..."
SYSPASSWORD = "..."
SYSTEMPASSWORD = "..."
SERVICEUSERPASSWORD = "..."

使用oracle用户执行:

1
$ $ORACLE_HOME/bin/dbca -silent -responseFile /home/oracle/database/response/dbca.rsp

创建实例会花费较长时间,耐心等待即可。

启动数据库

1
$ sqlplus / as sysdba

监听检查

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# lsnrctl status

LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 15-FEB-2019 17:31:30

Copyright (c) 1991, 2014, Oracle. All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=tjtxvm146-86-6.58os.org)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 12.1.0.2.0 - Production
Start Date 13-FEB-2019 15:27:04
Uptime 2 days 2 hr. 4 min. 26 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /opt/soft/oracle/product/oracle12cr1/network/admin/listener.ora
Listener Log File /opt/soft/oracle/product/diag/tnslsnr/tjtxvm146-86-6/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=tjtxvm146-86-6.58os.org)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "orcl" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
Service "pdb1" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
The command completed successfully

启动监听:lsnrctl start
查看监听:lsnrctl status
停止监听:lsnrctl stop

实例被动态注册到监听程序了. 到此oracle安装建库完毕!


参考: