CentOS7 安装 Oracle 12c

环境

CentOS7.5 最小安装
数据库软件
linuxx64_12201_database.zip

操作系统配置

关闭 SELinux

1
sed -i '/^SELINUX=/cSELINUX=disabled' /etc/selinux/config

配置防火墙

1
2
3
4
systemctl enable firewalld
systemctl restart firewalld
firewall-cmd --zone=public --add-port=1521/tcp --add-port=5500/tcp --permanent
firewall-cmd --reload

重启操作系统

1
reboot

安装依赖

安装可能用到的工具

1
2
3
4
yum install epel-release
yum clean all
yum makecache fast
yum install vim unzip rlwrap

安装 oracle 需要的包

1
2
3
4
5
6
yum install binutils compat-libcap1 compat-libstdc++-33 \
compat-libstdc++-33*i686 gcc gcc-c++ glibc glibc*.i686 \
glibc-devel glibc-devel*.i686 ksh libaio libaio*.i686 libaio-devel \
libgcc libgcc*.i686 libstdc++ libstdc++*.i686 libstdc++-devel \
libXi libXi*.i686 libXtst libXtst*.i686 make sysstat unixODBC \
unixODBC*.i686 unixODBC-devel unixODBC-devel*.i686

配置安装环境

创建 oracle 用户

1
2
3
4
groupadd oinstall
groupadd dba
groupadd oper
useradd -g oinstall -G dba,oper oracle

创建 oracle 安装目录

1
2
3
4
5
mkdir -p /opt/oracle/app/product/12.2.0
mkdir -p /opt/oracle/app/oradata
mkdir -p /opt/oracle/app/fast_recovery_area
chown -R oracle:oinstall /opt/oracle
chmod -R 775 /opt/oracle

修改 sysctl.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
cat << EOF >> /etc/sysctl.conf
fs.aio-max-nr = 1048576
fs.file-max = 6815744
#物理内存一半和4G中的较大者,当前服务器16G
kernel.shmmax = 8589934592
#shmmax / 4k (getconf PAGESIZE)
kernel.shmall = 2097152
kernel.shmmni = 4096
kernel.sem = 250 32000 200 200
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.wmem_default = 262144
net.core.wmem_max = 1048586
net.core.rmem_max = 4194304
EOF
sysctl -p

修改 limits.conf

1
2
3
4
5
6
7
cat << EOF >> /etc/security/limits.conf
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
EOF

修改 login

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
cat << EOF >> /etc/pam.d/login
session required /lib64/security/pam_limits.so
session required pam_limits.so
EOF
修改 profile
cat << EOF >> /etc/profile
if [ \$USER = "oracle" ] ; then
if [ \$SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
umask 022
fi
EOF

修改 oracle 用户的 .bash_profile

1
2
3
4
5
6
7
8
cat << EOF >> /home/oracle/.bash_profile
export ORACLE_BASE=/opt/oracle/app
export ORACLE_HOME=\$ORACLE_BASE/product/12.2.0
export ORACLE_SID=orcl
export PATH=\$PATH:\$ORACLE_HOME/bin
#export NLS_LANG="SIMPLIFIED CHINESE_CHINA.AL32UTF8"
#export NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK"
EOF

安装数据库

上传数据库软件到 /root 下,解压

1
2
unzip linuxx64_12201_database.zip -d /home/oracle/
chown -R oracle.oinstall /home/oracle/database

切换到 oracle 用户,后续操作都在该 oracle 用户下执行

1
su - oracle

创建 response 文件

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

修改 db_install.rsp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
sed -i \
-e '/^oracle\.install\.option=/s#=.*$#=INSTALL_DB_SWONLY#' \
-e '/^UNIX_GROUP_NAME=/s#=.*$#=oinstall#' \
-e '/^INVENTORY_LOCATION=/s#=.*$#=/opt/oracle/oraInventory#' \
-e '/^ORACLE_HOME=/s#=.*$#=/opt/oracle/app/product/12.2.0#' \
-e '/^ORACLE_BASE=/s#=.*$#=/opt/oracle/app#' \
-e '/^oracle\.install\.db\.InstallEdition=/s#=.*$#=EE#' \
-e '/^oracle\.install\.db\.OSDBA_GROUP=/s#=.*$#=dba#' \
-e '/^oracle\.install\.db\.OSOPER_GROUP=/s#=.*$#=oper#' \
-e '/^oracle\.install\.db\.OSBACKUPDBA_GROUP=/s#=.*$#=dba#' \
-e '/^oracle\.install\.db\.OSDGDBA_GROUP=/s#=.*$#=dba#' \
-e '/^oracle\.install\.db\.OSKMDBA_GROUP=/s#=.*$#=dba#' \
-e '/^oracle\.install\.db\.OSRACDBA_GROUP=/s#=.*$#=dba#' \
-e '/^oracle.install.db.config.starterdb.type=/s#=.*$#=GENERAL_PURPOSE#' \
-e '/^oracle\.install\.db\.config\.starterdb\.characterSet=/s#=.*$#=ZHS16GBK#' \
-e '/^DECLINE_SECURITY_UPDATES=/s#=.*$#=true#' \
/home/oracle/db_install.rsp

无需修改 netca.rsp
修改 dbca.rsp

1
2
3
4
5
6
7
8
9
10
11
sed -i \
-e '/^gdbName=/s#=.*$#=orcl#' \
-e '/^sid=/s#=.*$#=orcl#' \
-e '/^createAsContainerDatabase=/s#=.*$#=true#' \
-e '/^numberOfPDBs=/s#=.*$#=1#' \
-e '/^pdbName=/s#=.*$#=pdborcl#' \
-e '/^templateName=/s#=.*$#=General_Purpose.dbc#' \
-e '/^pdbAdminPassword=/s#=.*$#=P@sswo2d#' \
-e '/^sysPassword=/s#=.*$#=P@sswo2d#' \
-e '/^systemPassword=/s#=.*$#=P@sswo2d#' \
/home/oracle/dbca.rsp

安装 oracle 软件

1
2
cd /home/oracle/database
./runInstaller -silent -responseFile /home/oracle/db_install.rsp -ignorePrereq

安装成功后,系统提示需要在 root 下执行两个脚本

1
2
/opt/oracle/oraInventory/orainstRoot.sh
/opt/oracle/app/product/12.2.0/root.sh

配置监听

1
netca /silent /responseFile /home/oracle/netca.rsp

配置成功后,监听启动,查看监听状态

1
lsnrctl status

创建数据库

1
dbca -silent -createDatabase -responseFile /home/oracle/dbca.rsp

查看屏幕输出的创建进度
简单使用
登陆数据库,切换到 pdb 数据库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[oracle@oracle ~]$ rlwrap sqlplus / as sysdba
SQL*Plus: Release 12.2.0.1.0 Production on 星期一 6月 25 14:41:16 2018
Copyright (c) 1982, 2016, Oracle. All rights reserved.
连接到:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
SQL> show con_name
CON_NAME
------------------------------
CDB$ROOT
SQL> alter session set container=pdborcl;
会话已更改。
SQL> show con_name
CON_NAME
------------------------------
PDBORCL
SQL> select file_name from dba_data_files;
FILE_NAME
--------------------------------------------------------------------------------
/opt/oracle/app/oradata/orcl/pdborcl/system01.dbf
/opt/oracle/app/oradata/orcl/pdborcl/sysaux01.dbf
/opt/oracle/app/oradata/orcl/pdborcl/undotbs01.dbf
/opt/oracle/app/oradata/orcl/pdborcl/users01.dbf
SQL>

最后,将localhost替换为0.0.0.0。

1
2
3
4
5
6
7
8
9
10
11
12
vim $ORACLE_HOME/network/admin/listener.ora

# listener.ora Network Configuration File: /opt/oracle/app/product/12.2.0/network/admin/listener.ora
# Generated by Oracle configuration tools.

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)

配置Oracle开机自启

添加启动脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[oracle@oracle ~]$ vim /etc/systemd/system/oracle-rdbms.service
# /etc/systemd/system/oracle-rdbms.service
# Invoking Oracle scripts to start/shutdown Instances defined in /etc/oratab
# and starts Listener

[Unit]
Description=Oracle Database(s) and Listener
Requires=network.target

[Service]
Type=forking
Restart=no
ExecStart=/opt/oracle/app/product/12.2.0/bin/dbstart /opt/oracle/app/product/12.2.0
ExecStop=/opt/oracle/app/product/12.2.0/bin/dbshut /opt/oracle/app/product/12.2.0
User=oracle

[Install]
WantedBy=multi-user.target

修改 /etc/oratab 文件最后一行的N改成Y。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[oracle@oracle ~]$ vim /etc/oratab
#



# This file is used by ORACLE utilities. It is created by root.sh
# and updated by either Database Configuration Assistant while creating
# a database or ASM Configuration Assistant while creating ASM instance.

# A colon, ':', is used as the field terminator. A new line terminates
# the entry. Lines beginning with a pound sign, '#', are comments.
#
# Entries are of the form:
# $ORACLE_SID:$ORACLE_HOME:<N|Y>:
#
# The first and second fields are the system identifier and home
# directory of the database respectively. The third field indicates
# to the dbstart utility that the database should , "Y", or should not,
# "N", be brought up at system boot time.
#
# Multiple entries with the same $ORACLE_SID are not allowed.
#
#
orcl:/opt/oracle/app/product/12.2.0:Y

开启关闭em

开启em

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[oracle@oracle ~]$ rlwrap sqlplus / as sysdba

SQL*Plus: Release 12.2.0.1.0 Production on Sat Dec 15 09:09:47 2018

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


Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SP2-0136: DEFINE requires an equal sign (=)
SQL> exec DBMS_XDB_CONFIG.SETHTTPPORT(5500);

PL/SQL procedure successfully completed.

SQL>

关闭em

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[oracle@oracle ~]$ rlwrap sqlplus / as sysdba

SQL*Plus: Release 12.2.0.1.0 Production on Sat Dec 15 09:11:28 2018

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


Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SP2-0136: DEFINE requires an equal sign (=)
SQL> exec DBMS_XDB_CONFIG.SETHTTPPORT(0);

PL/SQL procedure successfully completed.

SQL>