CentOS 7.8 静默安装 Oracle 11g 流程

一、服务器配置

类型 版本
系统 CentOS
版本 7.8.2003
内核 3.10.0
架构 x86_64
CPU 4线程
内存 8G
硬盘 100G

Oracle 11gR2 配置要求

https://docs.oracle.com/cd/E11882_01/install.112/e47689/pre_install.htm#LADBI1096

类型 配置
内存 2 GB 以上
系统架构 x86_64
操作系统 CentOS 7 以上
内核 3.10.0-54.0.1.el7.x86_64 以上

二、Oracle下载

Oracle11g下载
https://www.oracle.com/cn/database/technologies/oracle-database-software-downloads.html

在这里插入图片描述

三、安装前准备

https://docs.oracle.com/cd/E11882_01/install.112/e47689/toc.htm

关闭防火墙

systemctl stop firewalld && systemctl disable firewalld

关闭SElinux

setenforce 0 && sed -i 's/enforcing/disabled/' /etc/selinux/config

3.1 安装依赖环境

https://docs.oracle.com/cd/E11882_01/install.112/e47689/pre_install.htm#BABCFJFG

yum install -y wget unzip net-tools vim lrzsz psmisc bash-completion \
&& source /usr/share/bash-completion/bash_completion
yum install -y \
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

3.2 设置主机名

https://docs.oracle.com/cd/E11882_01/install.112/e47689/pre_install.htm#LADBI1152

hostnamectl set-hostname oracle11g \
&& echo "127.0.0.1   oracle11g" >>/etc/hosts

3.3 创建组和用户

https://docs.oracle.com/cd/E11882_01/install.112/e47689/pre_install.htm#LADBI1161

groupadd -g 501 oinstall \
&& groupadd -g 502 dba \
&& groupadd -g 503 oper \
&& groupadd -g 506 asmdba \
&& useradd -u 502 -g oinstall -G dba,asmdba,oper oracle \
&& echo 'oracle' | passwd oracle --stdin

查看 oracle 用户信息

[root@oracle11g ~]# id oracle
uid=502(oracle) gid=501(oinstall)=501(oinstall),502(dba),503(oper),506(asmdba)

3.4 配置oracle用户资源限制

https://docs.oracle.com/cd/E11882_01/install.112/e47689/pre_install.htm#LADBI1180

编辑 /etc/security/limits.conf 追加以下内容

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

3.5 配置Linux内核参数

https://docs.oracle.com/cd/E11882_01/install.112/e47689/pre_install.htm#LADBI1188

编辑 /etc/sysctl.conf 追加以下内容

fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 4294967295
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
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 = 1048576

使用命令 sysctl -p 刷新生效

3.6 创建安装目录

https://docs.oracle.com/cd/E11882_01/install.112/e47689/pre_install.htm#LADBI1197

# 切换 oracle 用户
[root@localhost ~]# su - oracle
# 创建 Base 目录
[oracle@oracle11g ~]$ mkdir -p app/oracle
# 创建 Home 目录
[oracle@oracle11g ~]$ mkdir -p app/oracle/product/11.2.0
# 创建 Inventory 目录
[oracle@oracle11g ~]$ mkdir -p app/oraInventory

3.7 配置Oracle用户环境变量

编辑 /home/oracle/.bash_profile 追加以下内容

export ORACLE_HOSTNAME=oracle11g
export ORACLE_BASE=/home/oracle/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/
export PATH=.:$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$ORACLE_HOME/jdk/bin:$PATH
export ORACLE_SID=orcl
export LC_ALL="en_US"
export LANG="en_US"
export NLS_LANG="AMERICAN_AMERICA.ZHS16GBK"
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"

使用命令 source /home/oracle/.bash_profile 刷新生效

四、静默安装

4.1 解压oracle安装包

确保解压出来的 database 目录文件权限组是 oracle:oinstall

[oracle@oracle11g ~]$ pwd
/home/oracle
[oracle@oracle11g ~]$ unzip linux.x64_11gR2_database_1of2.zip
[oracle@oracle11g ~]$ unzip linux.x64_11gR2_database_2of2.zip

4.2 修改安装文件

[oracle@oracle11g ~]$ mkdir etc 
[oracle@oracle11g ~]$ cp database/response/* etc/

编辑 /home/oracle/etc/db_install.rsp 安装文件

oracle.install.option=INSTALL_DB_SWONLY
ORACLE_HOSTNAME=oracle11g
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/home/oracle/app/oraInventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/
ORACLE_BASE=/home/oracle/app/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.isCustomInstall=true
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=oinstall
oracle.install.db.config.starterdb.type=GENERAL_PURPOSE
oracle.install.db.config.starterdb.globalDBName=orcl
oracle.install.db.config.starterdb.SID=orcl
oracle.install.db.config.starterdb.memoryLimit=512
oracle.install.db.config.starterdb.password.ALL=oracle
DECLINE_SECURITY_UPDATES=true

4.3 静默安装

[oracle@oracle11g ~]$ cd database/
./runInstaller -silent -responseFile /home/oracle/etc/db_install.rsp -ignorePrereq

出现红框内提示表示安装完成
在这里插入图片描述
按照提示,进行以下步骤,新开一个终端,使用 root 用户运行这两个脚本

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

Changing groupname of /home/oracle/app/oraInventory to oinstall.
The execution of the script is complete.
[root@oracle11g ~]# /home/oracle/app/oracle/product/11.2.0/root.sh
Check /home/oracle/app/oracle/product/11.2.0/install/root_oracle11g_2020-10-22_16-48-55.log for the output of root script

4.4 配置监听程序

[oracle@oracle11g ~]$ netca /silent /responseFile /home/oracle/etc/netca.rsp 

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

查看监听端口

netstat -tnpl | grep 1521

4.5 静默创建数据库

编辑应答文件 /home/oracle/etc/dbca.rsp

GDBNAME = "orcl11g.oracle11g"
SID = "orcl"
SYSPASSWORD = "sys"
SYSTEMPASSWORD = "system"
DATAFILEDESTINATION = /home/oracle/app/oracle/oradata
RECOVERYAREADESTINATION = /home/oracle/app/oracle/fast_recovery_area
CHARACTERSET = "AL32UTF8"
NATIONALCHARACTERSET= "UTF8"
TOTALMEMORY = "1638"

创建数据库

[oracle@oracle11g ~]$ dbca -silent -responseFile /home/oracle/etc/dbca.rsp

在这里插入图片描述
删除实例命令【非必用,可选】

[oracle@oracle11g ~]$ dbca -silent -deleteDatabase -sourcedb orcl

查看监听状态

[oracle@oracle11g ~]$ lsnrctl status

在这里插入图片描述

4.6 登录数据库

[oracle@oracle11g database]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 23 19:42:45 2020

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

Connected to an idle instance.

# 启动数据库
SQL> startup;
ORACLE instance started.

Total System Global Area 1720328192 bytes
Fixed Size		    2214056 bytes
Variable Size		 1006634840 bytes
Database Buffers	  704643072 bytes
Redo Buffers		    6836224 bytes
ORA-01102: cannot mount database in EXCLUSIVE mode
## 这里的报错解决方案见本文的 6.1 步骤


# 查看数据库版本
SQL> select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE	11.2.0.1.0	Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production

# 查看数据库编码
SQL> select userenv('language') from dual;

USERENV('LANGUAGE')
--------------------------------------------------------------------------------
AMERICAN_AMERICA.US7ASCII

# 解锁Scott用户
SQL> alter user scott account unlock;

User altered.

SQL> alter user scott identified by scott;             

User altered.

五、设置Oracle开机启动

编辑 /etc/oratab 配置文件

# 把 N 改成 Y
orcl:/home/oracle/app/oracle/product/11.2.0:Y 

编辑 $ORACLE_HOME/bin/dbstart 文件

ORACLE_HOME_LISTNER=$ORACLE_HOME

编辑 $ORACLE_HOME/bin/dbshut 文件

ORACLE_HOME_LISTNER=$ORACLE_HOME

新建 /etc/rc.d/init.d/oracle 文件

#! /bin/bash
# oracle: Start/Stop Oracle Database 11g R2
#
# chkconfig: 345 90 10
# description: The Oracle Database is an Object-Relational Database Management System.
#
# processname: oracle
. /etc/rc.d/init.d/functions
LOCKFILE=/var/lock/subsys/oracle
ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/
ORACLE_USER=oracle
case "$1" in
'start')
   if [ -f $LOCKFILE ]; then
      echo $0 already running.
      exit 1
   fi
   echo -n $"Starting Oracle Database:"
   su - $ORACLE_USER -c "$ORACLE_HOME/bin/lsnrctl start"
   su - $ORACLE_USER -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME"
   su - $ORACLE_USER -c "$ORACLE_HOME/bin/emctl start dbconsole"
   touch $LOCKFILE
   ;;
'stop')
   if [ ! -f $LOCKFILE ]; then
      echo $0 already stopping.
      exit 1
   fi
   echo -n $"Stopping Oracle Database:"
   su - $ORACLE_USER -c "$ORACLE_HOME/bin/lsnrctl stop"
   su - $ORACLE_USER -c "$ORACLE_HOME/bin/dbshut"
   su - $ORACLE_USER -c "$ORACLE_HOME/bin/emctl stop dbconsole"
   rm -f $LOCKFILE
   ;;
'restart')
   $0 stop
   $0 start
   ;;
'status')
   if [ -f $LOCKFILE ]; then
      echo $0 started.
      else
      echo $0 stopped.
   fi
   ;;
*)
   echo "Usage: $0 [start|stop|status]"
   exit 1
esac
exit 0

添加可执行权限

chmod +x /etc/rc.d/init.d/oracle

六、报错处理

6.1 ORA-01102: cannot mount database in EXCLUSIVE mode

[oracle@oracle11g ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 23 19:09:09 2020

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

Connected to an idle instance.

SQL> startup;
ORACLE instance started.

Total System Global Area 1720328192 bytes
Fixed Size		    2214056 bytes
Variable Size		 1006634840 bytes
Database Buffers	  704643072 bytes
Redo Buffers		    6836224 bytes
ORA-01102: cannot mount database in EXCLUSIVE mode

解决方案
$ORACLE_HOME/dbs 目录下的 lk<sid> 文件释放掉

# 进入dbs目录
[oracle@oracle11g ~]$ cd $ORACLE_HOME/dbs

# 查看lkORCL11G文件使用情况
[oracle@oracle11g dbs]$ fuser -u lkORCL11G
/home/oracle/app/oracle/product/11.2.0/dbs/lkORCL11G: 14381(oracle) 14387(oracle) 14391(oracle) 14393(oracle) 14397(oracle) 14399(oracle) 14401(oracle) 14403(oracle) 14405(oracle) 14407(oracle) 14409(oracle) 14411(oracle) 14457(oracle) 14459(oracle) 14461(oracle) 14463(oracle) 14477(oracle) 14479(oracle) 14481(oracle)

# 释放该文件
[oracle@oracle11g dbs]$ fuser -k lkORCL11G
/home/oracle/app/oracle/product/11.2.0/dbs/lkORCL11G: 14381 14387 14391 14393 14397 14399 14401 14403 14405 14407 14409 14411 14457 14459 14461 14463 14477 14479 14481

# 再次查看
[oracle@oracle11g dbs]$ fuser -u lkORCL11G

猜你喜欢

转载自blog.csdn.net/qq_39680564/article/details/109113635