Centos7 安装Oracle11g 11.2.0.4 ——静默安装

一、准备工作

1、下载CentOS7 自行安装(64位)网络自行配置;
2、下载Oracle安装包(转):
oracle 11.02.0.4 安装介质
linux:https://pan.baidu.com/s/1kGsVfAoMJ_bmAJdhQgs6FA 提取码:ptn4
windows:https://pan.baidu.com/s/10wtQrYpyrhZ2dUyAEgdbFQ 提取码:frbe
参考:https://blog.csdn.net/demonson/article/details/79753766
3、HostName修改:hostnamectl set-hostname oracle
4、配置hostname(本机IP映射)

vi /etc/hosts
192.168.30.11 oracle
# 测试hostname
ping -c 3 oracle

二、优化配置

1、切换国内yum源:

cd /etc
mv yum.repos.d yum.repos.d.bak
mkdir yum.repos.d
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all
yum makecache

2、安装依赖包:

yum -y install binutils \
compat-libstdc++-33 \
elfutils-libelf \
elfutils-libelf-devel \
expat \
gcc \
gcc-c++ \
glibc \
glibc-common \
glibc-devel \
glibc-headers \
libaio \
libaio-devel \
libgcc \
libstdc++ \
libstdc++-devel \
make \
pdksh \
sysstat \
unixODBC \
unixODBC-devel

3、检查依赖是否安装完整:


rpm -q \
binutils \
compat-libstdc++-33 \
elfutils-libelf \
elfutils-libelf-devel \
expat \
gcc \
gcc-c++ \
glibc \
glibc-common \
glibc-devel \
glibc-headers \
libaio \
libaio-devel \
libgcc \
libstdc++ \
libstdc++-devel \
make \
pdksh \
sysstat \
unixODBC \
unixODBC-devel | grep "not installed"

4、优化OS内核参数

vim /etc/sysctl.conf #编辑,在最后添加以下代码
fs.aio-max-nr = 1048576
fs.file-max = 6815744
# shmall、shmmax参数要根据实际内存数进行调整,不然安装会有问题,静态安装很容易忽略
# 图形化安装在检测是将会提示
# 官网建议:
kernel.shmall = 2468829
# 官网建议:以字节为单位的物理内存(RAM)大小的一半
kernel.shmmax = 12640407552
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 = 1048586

#修改完后执行使参数生效。
sysctl -p

5、增加用户和组

groupadd oinstall
groupadd dba
groupadd asmadmin
groupadd asmdba
useradd -g oinstall -G dba,asmdba oracle -d /home/oracle
# 添加完成后
id oracle # 查看oracle用户
passwd oracle # 初始化oracle用户的密码

6、修改limits.conf限制


vi /etc/security/limits.conf #在末尾添加以下代码
#在末尾添加
oracle  soft    nproc   2047
oracle  hard    nproc   16384
oracle  soft    nofile  1024
oracle  hard    nofile  65536
oracle  soft    stack   10240
oracle  hard    stack   10240
 
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
--------------------------------------------------------
使之生效:
source /etc/profile

二、安装过程

1、创建目录

mkdir -p /db/app/oracle/product/11.2.0
mkdir /db/app/oracle/oradata
mkdir /db/app/oracle/oraInventory
mkdir /db/app/oracle/fast_recovery_area
chown -R oracle:oinstall /db/app/oracle
chmod -R 775 /db/app/oracle

2、创建 vi /etc/oraInst.loc:

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

3、授权:

chown oracle:oinstall /etc/oraInst.loc
chmod 664 /etc/oraInst.loc

4、配置oracle用户环境变量(注:切换用户)

su - oracle  ## oracle用户登陆
 
vi .bash_profile
 
export ORACLE_HOSTNAME=oracle
export ORACLE_BASE=/db/app/oracle
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
env

5、解压oracle压缩文件到 /db
Oracle11g 11.2.0.4 各个压缩包备注说明
安装单点的,就1和2一起解压,解压完叫database目录;
安装集群的,就先搞3,装完grid包后,再搞1和2;

1和2是数据库软件;
3是rac软件;
4是client客户端;
5是gateways;
6是example示例;
7是删除介质;

本次选择单点安装,解压

# 上传linux.x64_11gR2_database_*of2.zip文件至/db/目录;
unzip p13390677_112040_Linux-x86-64_1of7.zip
unzip p13390677_112040_Linux-x86-64_2of7.zip 
 
# 解压完成后:
# 登录Root,复制授权
su - root
mkdir /home/oracle/etc/
cp database/response/* /home/oracle/etc/
chmod 777 /home/oracle/etc/*.rsp

# 登录oracle用户:
su – oracle
vi /home/oracle/etc/db_install.rsp
## 信息如下:
oracle.install.option=INSTALL_DB_SWONLY
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/db/app/oracle/oraInventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOSTNAME=oracle
ORACLE_HOME=/db/app/oracle/product/11.2.0/db_1
ORACLE_BASE=/db/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

6、开始安装:

su - oracle
 cd /home/oracle/database/
./runInstaller -silent -force -responseFile /home/oracle/etc/db_install.rsp -ignorePrereq
## 安装期间可以使用tail命令监看oracle的安装日志
tail -f /db/app/oracle/oraInventory/logs/installActions2021-01-16_10-01-29PM.log
[oracle@oracle database]$ ./runInstaller -silent -force -responseFile /home/oracle/etc/db_install.rsp -ignorePrereq
Starting Oracle Universal Installer...

Checking Temp space: must be greater than 120 MB.   Actual 38208 MB    Passed
Checking swap space: must be greater than 150 MB.   Actual 2032 MB    Passed
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2021-01-16_10-01-29PM. Please wait ...[oracle@oracle database]$ You can find the log of this install session at:
 /db/app/oracle/oraInventory/logs/installActions2021-01-16_10-01-29PM.log
The installation of Oracle Database 11g was successful.
Please check '/db/app/oracle/oraInventory/logs/silentInstall2021-01-16_10-01-29PM.log' for more details.

As a root user, execute the following script(s):
    1. /db/app/oracle/product/11.2.0/db_1/root.sh


Successfully Setup Software.

执行 /db/app/oracle/product/11.2.0/db_1/root.sh

[root@oracle etc]# /db/app/oracle/product/11.2.0/db_1/root.sh
Check /db/app/oracle/product/11.2.0/db_1/install/root_oracle_2021-01-16_22-17-55.log for the output of root script
[root@oracle etc]# tail -f /db/app/oracle/product/11.2.0/db_1/install/root_oracle_2021-01-16_22-17-55.log
  Copying coraenv to /usr/local/bin ...


Creating /etc/oratab file...
Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root script.
Now product-specific root actions will be performed.
Finished product-specific root actions.
Finished product-specific root actions.

增加或修改oracle的环境变量:

su  - oracle
 
vi ~/.bash_profile
export ORACLE_HOME=/db/app/oracle/product/11.2.0/db_1
export TNS_ADMIN=$ORACLE_HOME/network/admin
export PATH=.:${PATH}:$HOME/bin:$ORACLE_HOME/bin
export PATH=${PATH}:/usr/bin:/bin:/usr/local/bin
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$ORACLE_HOME/lib
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$ORACLE_HOME/oracm/lib
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/lib:/usr/lib:/usr/local/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 ORACLE_OWNER=oracle
export SPFILE_PATH=$ORACLE_HOME/dbs
export ORA_NLS10=$ORACLE_HOME/nls/data
 
#生效
source ~/.bash_profile

配置监听程序:

cd /db/app/oracle/product/11.2.0/db_1/bin
 ./netca /silent /responseFile /home/oracle/etc/netca.rsp
[oracle@oracle bin]$  ./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: 
      /db/app/oracle/product/11.2.0/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@oracle bin]$ 

启动监听
cd /db/app/oracle/product/11.2.0/db_1/bin/

[oracle@oracle bin]$ lsnrctl start

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 16-JAN-2021 22:32:49

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

TNS-01106: Listener using listener name LISTENER has already been started
[oracle@oracle bin]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 16-JAN-2021 22:33:02

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date                16-JAN-2021 22:28:45
Uptime                    0 days 0 hr. 4 min. 17 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /db/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
Listener Log File         /db/app/oracle/diag/tnslsnr/oracle/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle)(PORT=1521)))
The listener supports no services
The command completed successfully
[oracle@oracle bin]$ 

静默dbca建库
编辑应答文件:

 [oracle@oracle etc]$ vim /home/oracle/etc/dbca.rsp 

GDBNAME="orcl.oracle" 
SID="orcl"
SYSPASSWORD = "oracle" 
SYSTEMPASSWORD = "oracle" 
CHARACTERSET="AL32UTF8" 
NATIONALCHARACTERSET="UTF8"
# 执行:
$ORACLE_HOME/bin/dbca -silent -responseFile /home/oracle/etc/dbca.rsp

建库:

[oracle@oracle bin]$ cd /db/app/oracle/product/11.2.0/db_1/bin
[oracle@oracle bin]$ dbca -silent -responseFile /home/oracle/etc/dbca.rsp
Copying database files
1% complete
3% complete
11% complete
18% complete
26% 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 "/db/app/oracle/cfgtoollogs/dbca/orcl/orcl.log" for further details.
[oracle@oracle bin]$ 

至此完成数据库实例的创建。

  • 如需删除实例:
    [oracle@oracle ~]$ dbca -silent -deleteDatabase -sourcedb orcl

设置Oracle开机启动
一、root编辑 /etc/oratab

orcl:/db/app/oracle/product/11.2.0/db_1:N   
修改为 orcl:/db/app/oracle/product/11.2.0/db_1:Y
注:参数为Y时可通过dbstart启动数据库

二、root编辑 vim /etc/rc.d/rc.local
添加以下内容:

 su oracle -lc "/db/app/oracle/product/11.2.0/db_1/bin/lsnrctl start"
 su oracle -lc "/db/app/oracle/product/11.2.0/db_1/bin/dbstart"

三、 oracle用户编辑dbstart
进入$ORACLE_HOME/bin
ORACLE_HOME_LISTNER=$1 修改为 ORACLE_HOME_LISTNER=$ORACLE_HOME

分别打开两个文件找到:ORACLE_HOME_LISTNER=$1,修改为
ORACLE_HOME_LISTNER=$ORACLE_HOME,命令如下:
[oracle@oracle11g ~]$ vi $ORACLE_HOME/bin/dbstart
[oracle@oracle11g ~]$ vi $ORACLE_HOME/bin/dbshut

临时启动实例

[oracle@oracle bin]$ pwd
/db/app/oracle/product/11.2.0/db_1/bin
# 通过dbstart 启动此实例,监听器
## ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener
## Usage: ./dbstart ORACLE_HOME
[oracle@oracle bin]$ ./dbstart $ORACLE_HOME;
# oracle的进程关闭,监听器也停止;
[oracle@oracle bin]$ ./dbshut $ORACLE_HOME;
# 启动监听
[oracle@oracle bin]$ ./lsnrctl start;
# 查看监听
[oracle@oracle bin]$ ./lsnrctl status;

登录Oracle

[oracle@oracle bin]$ pwd
/db/app/oracle/product/11.2.0/db_1/bin
[oracle@oracle bin]$ ./sqlplus /nolog
# 进入系统管理用户
SQL> conn / as sysdba
Connected to an idle instance.
# 启动oracle实例
SQL> startup;

SQL> startup

# 启动成功
[oracle@oracle ~]$ su - oracle
Password: 
Last login: Tue Jan 19 10:04:44 CST 2021 on pts/0
Last failed login: Tue Jan 19 10:05:49 CST 2021 on pts/0
There was 1 failed login attempt since the last successful login.
[oracle@oracle ~]$ sqlplus /nolog
SQL*Plus: Release 11.2.0.4.0 Production on Tue Jan 19 10:06:12 2021
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
SQL>  conn / as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started.

Total System Global Area  764121088 bytes
Fixed Size          2257152 bytes
Variable Size         499126016 bytes
Database Buffers      255852544 bytes
Redo Buffers            6885376 bytes
Database mounted.
Database opened.
SQL> 

解决sqlplus回退问题
Linux中安装完Oracle后,默认的 sqlplus 上下键是不能用的,安装了 rlwrap 之后就能通过上下键翻回历史命令了

  1. 下载地址
    https://github.com/hanslub42/rlwrap/releases
  2. 安装步骤
  • 安装readline 及 依赖
[root@oracle ~]# yum install readline*
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                                                                                                               | 3.6 kB  00:00:00     
extras                                                                                                                                                                             | 2.9 kB  00:00:00     
updates                                                                                                                                                                            | 2.9 kB  00:00:00     
软件包 readline-6.2-11.el7.x86_64 已安装并且是最新版本
正在解决依赖关系
There are unfinished transactions remaining. You might consider running yum-complete-transaction, or "yum-complete-transaction --cleanup-only" and "yum history redo last", first to finish them. If those don't work you'll have to try removing/installing packages by hand (maybe package-cleanup can help).
--> 正在检查事务
---> 软件包 readline-devel.x86_64.0.6.2-11.el7 将被 安装
--> 正在处理依赖关系 ncurses-devel,它被软件包 readline-devel-6.2-11.el7.x86_64 需要
---> 软件包 readline-static.x86_64.0.6.2-11.el7 将被 安装
--> 正在检查事务
---> 软件包 ncurses-devel.x86_64.0.5.9-14.20130511.el7_4 将被 安装
--> 解决依赖关系完成

依赖关系解决

==========================================================================================================================================================================================================
 Package                                             架构                                       版本                                                       源                                        大小
==========================================================================================================================================================================================================
正在安装:
 readline-devel                                      x86_64                                     6.2-11.el7                                                 base                                     139 k
 readline-static                                     x86_64                                     6.2-11.el7                                                 base                                     118 k
为依赖而安装:
 ncurses-devel                                       x86_64                                     5.9-14.20130511.el7_4                                      base                                     712 k

事务概要
==========================================================================================================================================================================================================
安装  2 软件包 (+1 依赖软件包)

总下载量:969 k
安装大小:2.9 M
Is this ok [y/d/N]: y
Downloading packages:
(1/3): ncurses-devel-5.9-14.20130511.el7_4.x86_64.rpm                                                                                                                              | 712 kB  00:00:00     
(2/3): readline-devel-6.2-11.el7.x86_64.rpm                                                                                                                                        | 139 kB  00:00:00     
(3/3): readline-static-6.2-11.el7.x86_64.rpm                                                                                                                                       | 118 kB  00:00:00     
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计                                                                                                                                                                      575 kB/s | 969 kB  00:00:01     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : ncurses-devel-5.9-14.20130511.el7_4.x86_64                                                                                                                                            1/3 
  正在安装    : readline-devel-6.2-11.el7.x86_64                                                                                                                                                      2/3 
  正在安装    : readline-static-6.2-11.el7.x86_64                                                                                                                                                     3/3 
  验证中      : readline-devel-6.2-11.el7.x86_64                                                                                                                                                      1/3 
  验证中      : readline-static-6.2-11.el7.x86_64                                                                                                                                                     2/3 
  验证中      : ncurses-devel-5.9-14.20130511.el7_4.x86_64                                                                                                                                            3/3 

已安装:
  readline-devel.x86_64 0:6.2-11.el7                                                                  readline-static.x86_64 0:6.2-11.el7                                                                 

作为依赖被安装:
  ncurses-devel.x86_64 0:5.9-14.20130511.el7_4                                                                                                                                                            

完毕!
[root@oracle ~]# 
  • 上传rlwrap-0.43.tar.gz 并安装
[root@oracle ~]# tar -zxvf rlwrap-0.43.tar.gz
[root@oracle ~]# cd rlwrap-0.43
[root@oracle rlwrap-0.43]# ./configure && make && make install
  • 配置shell
Last login: Tue Jan 19 10:20:56 2021 from 192.168.30.129
[root@oracle ~]# su - oracle
上一次登录:二 1月 19 10:08:54 CST 2021pts/1 上
[oracle@oracle ~]$ vim ~/.bash_profile

最后增加以下配置,使oracle相关命令都支持回退和上下键

alias sqlplus='rlwrap sqlplus'
alias rman='rlwrap rman'
alias lsnrctl='rlwrap lsnrctl'

立即生效

[oracle@oracle ~]$ source ~/.bash_profile

常见错误

ORA-00845: MEMORY_TARGET not supported on this system
找到错误原因是MEMORY_MAX_TARGET 的设置不能超过 /dev/shm 的大小,我们来看一下解决步骤:df -h
mount -o remount,size=2G /dev/shm/
df -h | grep shm

你可能感兴趣的:(Centos7 安装Oracle11g 11.2.0.4 ——静默安装)