0%

Centos7.x静默安装Oracle 12.2.0.1.0

今天项目上让安装一台12c的数据库,和之前的11g静默安装过程大致差不多,在此记录一下,方便日后查看。

关闭selinux和firewalld

关闭selinux

1
2
3
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
grep SELINUX=disabled /etc/selinux/config
setenforce 0

关闭firewalld

1
2
systemctl stop firewalld.service
systemctl disable firewalld.service

系统基础信息配置

基础软件安装

1
2
3
4
5
#默认是不安装32位软件包的,添加此选项
echo 'multilib_policy=all' >> /etc/yum.conf
yum -y install binutils-* compat-libstdc++-* elfutils-libelf-* elfutils-libelf-devel-* gcc-* gcc-c++-* glibc-* glibc-common-* glibc-devel-* glibc-headers-* ksh-* libaio-* libaio-devel-* libgcc-* libstdc++* libstdc++-devel* make-* sysstat-* unixODBC-* unixODBC-devel-* compat-libcap1* mksh
# 非必须要安装的包,个人习惯
yum -y install vim unzip lrzsz
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#监测一下软件是否安装全
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 \
compat-libcap1 | grep "not installed"

配置主机名

1
hostnamectl set-hostname db-server

添加hosts记录

vim /etc/hosts

1
2
3
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1 db-server

修改PAM配置文件

vim /etc/pam.d/login

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

修改内核参数

vim /etc/sysctl.conf

1
2
3
4
5
6
7
8
9
fs.aio-max-nr = 1048576 
fs.file-max = 6815744
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

修改系统资源限制

vim /etc/security/limits.conf

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

Oracle相关环境配置

新建用户

1
2
3
4
5
groupadd -g 1000 oinstall
groupadd -g 1001 dba
useradd -u 1000 -g oinstall -G dba oracle
#设置oracle用户密码为oracle#123
echo "oracle:oracle#123" | chpasswd

修改用户配置文件

vim /etc/profile

1
2
3
4
5
6
7
8
9
10
#添加到文件末尾即可

if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi

新建目录并设置权限

1
2
3
4
5
mkdir -p /u01/app/oracle/product/12.2.0/db_1
mkdir -p /u01/app/oraInventory
chown -R oracle.oinstall /u01/app/oracle
chown -R oracle.oinstall /u01/app/oraInventory
chmod -R 775 /u01/app

设置oracle用户环境变量

su - oracle
vim ~/.bash_profile

1
2
3
4
5
6
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/12.2.0/db_1
export ORACLE_SID=orcl
export PATH=$PATH:$ORACLE_HOME/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export NLS_LANG=American_America.ZHS16GBK

检查环境变量是否生效

source ~/.bash_profile
env |grep ORA

1
2
3
ORACLE_SID=orcl
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=/u01/app/oracle/product/12.2.0/db_1

安装Oracle数据库

下载地址:https://www.oracle.com/database/technologies/oracle-database-software-downloads.html

12.2.0.1.0只有一个软件包,(3,453,696,911 bytes) (cksum - 4170261901),将linuxx64_12201_database.zip传到服务器/usr/local/src/ 目录下并解压。

1
2
3
4
[root@db-server src]# pwd
/usr/local/src
[root@db-server src]# unzip linuxx64_12201_database.zip
……

安装Oracle数据库软件

解压后在/usr/local/src/database/response/ 目录下有三个rsp文件,用来作为静默安装时的应答文件的模板。

1
2
3
db_install.rsp	安装应答
netca.rsp 建立监听、本地服务名等网络设置的应答
dbca.rsp 创建数据库应答
1
2
3
--备份以下两个响应文件
cp db_install.rsp db_install.bak
cp dbca.rsp dbca.bak

修改db_install.rsp 文件

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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
[root@db-server response]# egrep -v "^#|^$" db_install.rsp 

oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v12.2.0
oracle.install.option=INSTALL_DB_SWONLY
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/u01/app/oraInventory
ORACLE_HOME=/u01/app/oracle/product/12.2.0/db_1
ORACLE_BASE=/u01/app/oracle


oracle.install.db.InstallEdition=EE
oracle.install.db.OSDBA_GROUP=dba
oracle.install.db.OSOPER_GROUP=
oracle.install.db.OSBACKUPDBA_GROUP=dba
oracle.install.db.OSDGDBA_GROUP=dba
oracle.install.db.OSKMDBA_GROUP=dba
oracle.install.db.OSRACDBA_GROUP=dba
oracle.install.db.rac.configurationType=
oracle.install.db.CLUSTER_NODES=
oracle.install.db.isRACOneInstall=false
oracle.install.db.racOneServiceName=
oracle.install.db.rac.serverpoolName=
oracle.install.db.rac.serverpoolCardinality=0
oracle.install.db.config.starterdb.type=GENERAL_PURPOSE
oracle.install.db.config.starterdb.globalDBName=
oracle.install.db.config.starterdb.SID=
oracle.install.db.ConfigureAsContainerDB=false
oracle.install.db.config.PDBName=
oracle.install.db.config.starterdb.characterSet=ZHS16GBK
oracle.install.db.config.starterdb.memoryOption=false
oracle.install.db.config.starterdb.memoryLimit=
oracle.install.db.config.starterdb.installExampleSchemas=false
oracle.install.db.config.starterdb.password.ALL=
oracle.install.db.config.starterdb.password.SYS=
oracle.install.db.config.starterdb.password.SYSTEM=
oracle.install.db.config.starterdb.password.DBSNMP=
oracle.install.db.config.starterdb.password.PDBADMIN=
oracle.install.db.config.starterdb.managementOption=DEFAULT
oracle.install.db.config.starterdb.omsHost=
oracle.install.db.config.starterdb.omsPort=0
oracle.install.db.config.starterdb.emAdminUser=
oracle.install.db.config.starterdb.emAdminPassword=
oracle.install.db.config.starterdb.enableRecovery=false
oracle.install.db.config.starterdb.storageType=
oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=
oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=
oracle.install.db.config.asm.diskGroup=
oracle.install.db.config.asm.ASMSNMPPassword=
MYORACLESUPPORT_USERNAME=
MYORACLESUPPORT_PASSWORD=
SECURITY_UPDATES_VIA_MYORACLESUPPORT=false
DECLINE_SECURITY_UPDATES=true
PROXY_HOST=
PROXY_PORT=
PROXY_USER=
PROXY_PWD=
COLLECTOR_SUPPORTHUB_URL=

执行静默安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[oracle@db-server database]$ pwd
/usr/local/src/database
[oracle@db-server database]$ ./runInstaller -silent -ignorePrereq -ignoreSysPrereqs -responseFile /usr/local/src/database/response/db_install.rsp
Starting Oracle Universal Installer...

Checking Temp space: must be greater than 500 MB. Actual 29865 MB Passed
Checking swap space: must be greater than 150 MB. Actual 2047 MB Passed
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2020-06-18_03-36-22AM. Please wait ...[oracle@db-server database]$ You can find the log of this install session at:
/u01/app/oraInventory/logs/installActions2020-06-18_03-36-22AM.log
The installation of Oracle Database 12c was successful.
Please check '/u01/app/oraInventory/logs/silentInstall2020-06-18_03-36-22AM.log' for more details.

As a root user, execute the following script(s):
1. /u01/app/oraInventory/orainstRoot.sh
2. /u01/app/oracle/product/12.2.0/db_1/root.sh



Successfully Setup Software.

安装过程中,我们可以另开一个终端查看安装日志

tail -f /u01/app/oraInventory/logs/silentInstall2020-06-18_03-36-22AM.log

以root身份执行以下脚本,然后在刚才的安装界面敲回车,完成安装

1
2
3
4
5
6
7
8
9
[root@db-server response]# /u01/app/oraInventory/orainstRoot.sh
Changing permissions of /u01/app/oraInventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.

Changing groupname of /u01/app/oraInventory to oinstall.
The execution of the script is complete.
[root@db-server response]# /u01/app/oracle/product/12.2.0/db_1/root.sh
Check /u01/app/oracle/product/12.2.0/db_1/install/root_db-server_2020-06-18_03-46-08-638987704.log for the output of root script

静默安装监听

安装监听

静默安装使用默认的监听响应文件即可,不用修改。

1
2
3
4
5
6
7
8
9
10
11
12
13
[oracle@db-server ~]$ $ORACLE_HOME/bin/netca /silent /responseFile /usr/local/src/database/response/netca.rsp 

Parsing command line arguments:
Parameter "silent" = true
Parameter "responsefile" = /usr/local/src/database/response/netca.rsp
Done parsing command line arguments.
Oracle Net Services Configuration:
Profile configuration complete.
Oracle Net Listener Startup:
The information provided for this listener is currently in use by other software on this computer.
Listener start failed.
Check the trace file for details: /u01/app/oracle/cfgtoollogs/netca/trace_OraDB12Home1-2006183AM4751.log
Oracle Net Services configuration failed. The exit code is 1

启动监听

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
[oracle@db-server ~]$ lsnrctl start

LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 18-JUN-2020 03:48:13

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

Starting /u01/app/oracle/product/12.2.0/db_1/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 12.2.0.1.0 - Production
System parameter file is /u01/app/oracle/product/12.2.0/db_1/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/db-server/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=db-server)(PORT=1539)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1539)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 12.2.0.1.0 - Production
Start Date 18-JUN-2020 03:48:14
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/12.2.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/db-server/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=db-server)(PORT=1539)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
The listener supports no services
The command completed successfully

ps:细心的朋友应该发现了,我这里有点问题,启动的是1539端口,不是响应文件里定义的1521端口,暂时还没找到原因,先手动修改了。

静默安装数据库

修改安装数据库响应文件

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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
[root@db-server ~]# egrep -v "^#|^$" /usr/local/src/database/response/dbca.rsp
responseFileVersion=/oracle/assistants/rspfmt_dbca_response_schema_v12.2.0
gdbName=orcl
sid=orcl
databaseConfigType=SI
RACOneNodeServiceName=
policyManaged=false
createServerPool=false
serverPoolName=
cardinality=
force=false
pqPoolName=
pqCardinality=
createAsContainerDatabase=false
numberOfPDBs=0
pdbName=
useLocalUndoForPDBs=true
pdbAdminPassword=
nodelist=
templateName=/u01/app/oracle/product/12.2.0/db_1/assistants/dbca/templates/General_Purpose.dbc
sysPassword=Ths#123%
systemPassword=Ths#123%
serviceUserPassword=
emConfiguration=
emExpressPort=0
runCVUChecks=false
dbsnmpPassword=
omsHost=
omsPort=0
emUser=
emPassword=
dvConfiguration=false
dvUserName=
dvUserPassword=
dvAccountManagerName=
dvAccountManagerPassword=
olsConfiguration=false
datafileJarLocation={ORACLE_HOME}/assistants/dbca/templates/
datafileDestination={ORACLE_BASE}/oradata/{DB_UNIQUE_NAME}/
recoveryAreaDestination={ORACLE_BASE}/fast_recovery_area/{DB_UNIQUE_NAME}
storageType=FS
diskGroupName=
asmsnmpPassword=
recoveryGroupName=
characterSet=ZHS16GBK
nationalCharacterSet=
registerWithDirService=false
dirServiceUserName=
dirServicePassword=
walletPassword=
listeners=
variablesFile=
variables=DB_UNIQUE_NAME=orcl,ORACLE_BASE=/u01/app/oracle,PDB_NAME=,DB_NAME=orcl,ORACLE_HOME=/u01/app/oracle/product/12.2.0/db_1,SID=orcl
initParams=undo_tablespace=UNDOTBS1,memory_target=1577MB,processes=320,db_recovery_file_dest_size=8016MB,dispatchers=(PROTOCOL=TCP) (SERVICE={SID}XDB),db_recovery_file_dest={ORACLE_BASE}/fast_recovery_area/{DB_UNIQUE_NAME},db_block_size=8KB,diagnostic_dest={ORACLE_BASE},audit_file_dest={ORACLE_BASE}/admin/{DB_UNIQUE_NAME}/adump,db_create_file_dest={ORACLE_BASE}/oradata/{DB_UNIQUE_NAME}/,compatible=12.2.0,db_name=orcl,audit_trail=db,remote_login_passwordfile=EXCLUSIVE,open_cursors=300
sampleSchema=false
memoryPercentage=40
databaseType=MULTIPURPOSE
automaticMemoryManagement=true
totalMemory=0

执行静默建库

12c和11不同的地方就是在这里要加一个-createDatabase的参数。

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

[oracle@db-server ~]$ $ORACLE_HOME/bin/dbca -silent -createDatabase -responseFile /home/oracle/dbca.rsp
Copying database files
1% complete
2% complete
18% complete
33% complete
Creating and starting Oracle instance
35% complete
40% complete
44% complete
49% complete
50% complete
53% complete
55% complete
Completing Database Creation
56% complete
57% complete
58% complete
62% complete
65% complete
66% complete
Executing Post Configuration Actions
100% complete
Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/orcl/orcl.log" for further details.
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
[oracle@db-server ~]$ lsnrctl status

LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 17-JUN-2020 19:09:02

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 12.2.0.1.0 - Production
Start Date 17-JUN-2020 19:08:16
Uptime 0 days 0 hr. 0 min. 46 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/12.2.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/db-server/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=db-server)(PORT=1521)))
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...
The command completed successfully

配置开机启动

修改oratab

vim /etc/oratab

1
orcl:/u01/app/oracle/product/12.2.0/db_1:Y

修改dbstart文件

vim /u01/app/oracle/product/12.2.0/db_1/bin/dbstart

修改第80行: ORACLE_HOME_LISTNER=$1为ORACLE_HOME_LISTNER=$ORACLE_HOME

修改dbshut文件

vim /u01/app/oracle/product/12.2.0/db_1/bin/dbshut

修改第50行: ORACLE_HOME_LISTNER=$1为ORACLE_HOME_LISTNER=$ORACLE_HOME

修改开机启动文件

vim /etc/rc.d/rc.local

1
2
su - oracle -lc "/u01/app/oracle/product/12.2.0/db_1/bin/lsnrctl start"
su - oracle -lc "/u01/app/oracle/product/12.2.0/db_1/bin/dbstart"

添加可执行权限

chmod +x /etc/rc.d/rc.local

关闭审计日志

1
2
3
4
5
6
7
由于默认审计日志默认是开启状态,长时间使用后会早上SYSTEM表空间撑爆,磁盘占用率高,建议关闭
sqlplus / as sysdba

SQL> show parameter audit_trail
SQL> alter system set audit_trail=none scope=spfile;
SQL> shutdown immediate;
SQL> startup

使SqlPlus工具支持上下左右键

安装rlwrap: http://islocal.cc/arlo/d9547628/