安装Oracle一直以来是比较头疼的事情,于是本文以图文并茂的方式进行安装步骤展示,参考知乎一位博主的安装:https://zhuanlan.zhihu.com/p/111710672

本文还额外提供了安装以及最后的一些数据库自启动配置操作。

Oracle软件包地址:https://pan.baidu.com/s/1rQFXCsL44Nl-cXaLWVY9jQ?pwd=d8ns

前置工具安装(安装过可以忽略):

yum -y install vim
yum -y install unzip
yum -y install lrzsz
yum -y update

操作系统:

[root@localhost ~]# cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core)

一、安装Oracle11GR2所需要的依赖包

 一键安装命令:

yum -y install gcc gcc-c++ make binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel elfutils-libelf-devel-static glibc glibc-common glibc-devel ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel numactl-devel sysstat unixODBC unixODBC-devel kernelheaders pdksh pcre-devel readline rlwrap

防止有部分依赖安装失败,这里就一个一个进行安装:

yum -y install gcc

?️Centos7下安装Oracle11GR2_bc

yum -y install gcc-c++

?️Centos7下安装Oracle11GR2_Oracle_02

yum -y install make

?️Centos7下安装Oracle11GR2_bc_03

yum -y install binutils

?️Centos7下安装Oracle11GR2_oracle_04

yum -y install compat-libstdc++-33

?️Centos7下安装Oracle11GR2_bc_05

yum -y install elfutils-libelf

?️Centos7下安装Oracle11GR2_oracle_06

yum -y install elfutils-libelf-devel

?️Centos7下安装Oracle11GR2_Oracle_07

yum -y install elfutils-libelf-devel-static

?️Centos7下安装Oracle11GR2_Oracle_08

yum -y install glibc

?️Centos7下安装Oracle11GR2_vim_09

yum -y install glibc-common

?️Centos7下安装Oracle11GR2_oracle_10

yum -y install glibc-devel

?️Centos7下安装Oracle11GR2_oracle_11

yum -y install ksh

?️Centos7下安装Oracle11GR2_Oracle_12

yum -y install libaio

?️Centos7下安装Oracle11GR2_Oracle_13

yum -y install libaio-devel

?️Centos7下安装Oracle11GR2_vim_14

yum -y install libgcc

?️Centos7下安装Oracle11GR2_Oracle_15

yum -y install libstdc++

?️Centos7下安装Oracle11GR2_Oracle_16

yum -y install libstdc++-devel

?️Centos7下安装Oracle11GR2_Oracle_17

yum -y install sysstat

?️Centos7下安装Oracle11GR2_Oracle_18

yum -y install unixODBC

?️Centos7下安装Oracle11GR2_vim_19

yum -y install unixODBC-devel

?️Centos7下安装Oracle11GR2_oracle_20

yum -y install kernel-headers

?️Centos7下安装Oracle11GR2_bc_21

yum -y install pdksh

?️Centos7下安装Oracle11GR2_vim_22

报错,pdksh是一个老包了,新的oracle都使用ksh包

yum -y install ksh

?️Centos7下安装Oracle11GR2_vim_23

yum -y install pcre-devel

?️Centos7下安装Oracle11GR2_oracle_24

 yum -y install readline*

?️Centos7下安装Oracle11GR2_vim_25

yum -y install rlwrap

 

?️Centos7下安装Oracle11GR2_bc_26

二、创建用户组及文件夹

创建用户组:groupadd oinstall

创建用户组:groupadd dba

创建用户并添加到用户组:useradd -g oinstall -G dba oracle

设置oracle用户密码:echo "123456" | passwd --stdin oracle

创建安装目录及权限:

mkdir -p /data/u01/app/oracle/product/11.2.0/dbhome_1
mkdir /data/u01/app/oracle/{oradata,inventory,fast_recovery_area}
chown -R oracle:oinstall /data/u01/app/oracle
chmod -R 775 /data/u01/app/oracle

三、静默安装Oracle11GR2数据库

上传数据库文件到:/data/u01/software下

mkdir -p /data/u01/software

解压:

cd /data/u01/software
unzip linux.x64_11gR2_database_1of2.zip
unzip linux.x64_11gR2_database_2of2.zip

1、修改内核配置文件

vim /etc/sysctl.conf

在尾部添加下面配置:

fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 1073741824
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

?️Centos7下安装Oracle11GR2_bc_27

使配置文件生效:sysctl -p

?️Centos7下安装Oracle11GR2_vim_28

2、修改用户限制

vim /etc/security/limits.conf

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

?️Centos7下安装Oracle11GR2_vim_29

3、修改/etc/pam.d/login 文件

vim /etc/pam.d/login

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

?️Centos7下安装Oracle11GR2_oracle_30

4、修改环境变量

vim /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

?️Centos7下安装Oracle11GR2_bc_31

5、设置oracle用户环境变量

su - oracle
vim .bash_profile

添加:

export ORACLE_BASE=/data/u01/app/oracle
export ORACLE_HOME=/data/u01/app/oracle/product/11.2.0/dbhome_1
export ORACLE_SID=orcl
export ORACLE_UNQNAME=$ORACLE_SID
export PATH=$ORACLE_HOME/bin:$PATH
export NLS_LANG=american_america.AL32UTF8
alias sqlplus='rlwrap sqlplus'
alias rman='rlwrap rman'

?️Centos7下安装Oracle11GR2_Oracle_32

使配置生效:source .bash_profile

6、修改静默安装响应文件

拷贝一份响应文件:

cp -R /data/u01/software/database/response/ .
cd response/

执行:vim db_install.rsp

修改内容:

oracle.install.option=INSTALL_DB_SWONLY

?️Centos7下安装Oracle11GR2_Oracle_33

ORACLE_HOSTNAME=自己主机名

主机名可通过命令获取:hostname

?️Centos7下安装Oracle11GR2_oracle_34

UNIX_GROUP_NAME=oinstall

INVENTORY_LOCATION=/data/u01/app/oracle/inventory

?️Centos7下安装Oracle11GR2_Oracle_35

SELECTED_LANGUAGES=en,zh_CN

ORACLE_HOME=/data/u01/app/oracle/product/11.2.0/dbhome_1

ORACLE_BASE=/data/u01/app/oracle

oracle.install.db.InstallEdition=EE

?️Centos7下安装Oracle11GR2_Oracle_36

oracle.install.db.DBA_GROUP=dba

oracle.install.db.OPER_GROUP=dba

?️Centos7下安装Oracle11GR2_bc_37

DECLINE_SECURITY_UPDATES=true

?️Centos7下安装Oracle11GR2_vim_38

保存退出

7、执行安装

切换到解压的安装包目录:cd /data/u01/software/database/

执行:./runInstaller -silent -responseFile /home/oracle/response/db_install.rsp -ignorePrereq

此处执行事件需要几分钟,耐心等待下;

?️Centos7下安装Oracle11GR2_oracle_39

安装完成,成功登录

?️Centos7下安装Oracle11GR2_Oracle_40

四、创建数据库实例

修改响应配置文件:vim /home/oracle/response/dbca.rsp

GDBNAME = "orcl"

?️Centos7下安装Oracle11GR2_vim_41

SID= "orcl"

?️Centos7下安装Oracle11GR2_Oracle_42

SYSPASSWORD = "输入密码"

SYSTEMPASSWORD = "输入密码"

SYSMANPASSWORD = "输入密码"

DBSNMPPASSWORD = "输入密码"

?️Centos7下安装Oracle11GR2_vim_43

DATAFILEDESTINATION =/data/u01/app/oracle/oradata

RECOVERYAREADESTINATION=/data/u01/app/oracle/fast_recovery_area

?️Centos7下安装Oracle11GR2_bc_44

CHARACTERSET = "AL32UTF8"

?️Centos7下安装Oracle11GR2_vim_45

TOTALMEMORY = "2048"

?️Centos7下安装Oracle11GR2_vim_46

保存退出。

检查配置:egrep -v "(^#|^$)" /home/oracle/response/dbca.rsp

?️Centos7下安装Oracle11GR2_Oracle_47

安装创建:dbca -silent -responseFile /home/oracle/response/dbca.rsp

?️Centos7下安装Oracle11GR2_bc_48

查看默认实例:env|grep ORACLE_UNQNAME

启动监听:lsnrctl start

重启Oracle步骤

重启Oracle数据库的操作步骤
    1.查看监听器状态:lsnrctl status
    2.停止监听器:lsnrctl stop
    3.连接数据库:sqlplus sys/密码 as sysdba
    4.停止数据库:shutdown immediate
    5.启动数据库:startup
    6.退出数据库:exit
    7.启动监听:lsnrctl start

连接测试: 

?️Centos7下安装Oracle11GR2_oracle_49

五、配置oracle开机自启

root.sh 是一个脚本文件,用于在Oracle数据库安装的过程中完成一些的后续配置和设置操作

root用户执行:sh /data/u01/app/oracle/product/11.2.0/dbhome_1/root.sh

oracle用户执行:vim /etc/oratab,格式为:‘实例名:$ORACLE_HOME:Y’

orcl:/data/u01/app/oracle/product/11.2.0/dbhome_1:Y

?️Centos7下安装Oracle11GR2_oracle_50

root用户添加开机自启策略:

chmod 777 /etc/rc.local
vim /etc/rc.local


# oracle开机自启
su - oracle -c "dbstart"
su - oracle -c "lsnrctl start"
su - oracle -c "lsnrctl start listenerl"

?️Centos7下安装Oracle11GR2_Oracle_51