0%

静默安装ORACLE数据库

OUI的安装方式便捷、直观,但是有时候出于一些原因(PS:网络等原因),无法在服务器上使用OUI的方式,此时就只有用命令行来进行安装了。
本文记录了利用静默方式安装ORACLE数据库软件,再利用dbca命令创建数据库。也可以直接利用静默安装文件同时安装ORACLE数据库软件和创建数据库,但是同时进行的时候容易出错,所以本文将其分为两步进行。

静默安装ORACLE数据库软件

配置内核参数(root用户)

1
vi /etc/sysctl.conf
1
2
3
4
5
6
7
8
9
10
11
kernel.shmmax = 784676864  
kernel.shmall = 153257
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 4194304
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
fs.aio-max-nr = 1048576
fs.file-max = 6815744

修改后使用sysctl -p使配置生效

配置资源限制(root用户)

1
vi /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

创建用户组和用户组(root用户)

1
2
3
groupadd oinstall  
groupadd dba
useradd -m -g oinstall -G dba oracle

创建完成后设置oracle账号口令passwd oracle

####创建目录以及授权(root用户)

1
2
3
4
mkdir -p /home/u01
mkdir -p /u01/app/oracle
chown -R oracle:oinstall /u01/
chmod -R 775 /u01/

创建软链接绑定ln -s /home/u01 /u01

配置环境变量(oracle用户)

su - oracle切换到oracle用户,编辑~/.bash_profile配置环境变量。

1
2
3
4
5
6
7
export ORACLE_BASE=/u01/app  
export ORACLE_HOME=$ORACLE_BASE/oracle
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib:/usr/local/lib:/usr/X11R6/lib
export TNS_ADMIN=$ORACLE_HOME/network/admin
export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
export ORACLE_OWNER=oracle
export PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/usr/sbin:/usr/bin:/root/bin:$ORACLE_HOME/bin:$PATH

编辑完成后执行source ~/.bash_profile使之生效。

配置响应文件

在解压后的oracle安装文件夹database/response目录下有一个响应文件的配置模板db_install.rsp,根据需要自行配置即可。
下面是我的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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#-------------------------------------------------------------------------------  
# Do not change the following system generated value.
#-------------------------------------------------------------------------------
oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v12.1.0

#-------------------------------------------------------------------------------
# Specify the installation option.
# It can be one of the following:
# - INSTALL_DB_SWONLY
# - INSTALL_DB_AND_CONFIG
# - UPGRADE_DB
#-------------------------------------------------------------------------------
oracle.install.option=INSTALL_DB_SWONLY

#-------------------------------------------------------------------------------
# Specify the hostname of the system as set during the install. It can be used
# to force the installation to use an alternative hostname rather than using the
# first hostname found on the system. (e.g., for systems with multiple hostnames
# and network interfaces)
#-------------------------------------------------------------------------------
ORACLE_HOSTNAME=orc1

#-------------------------------------------------------------------------------
# Specify the Unix group to be set for the inventory directory.
#-------------------------------------------------------------------------------
UNIX_GROUP_NAME=dba

#-------------------------------------------------------------------------------
# Specify the location which holds the inventory files.
# This is an optional parameter if installing on
# Windows based Operating System.
#-------------------------------------------------------------------------------
INVENTORY_LOCATION=/u01/app/oraInventory
#-------------------------------------------------------------------------------
# Specify the languages in which the components will be installed.
#
# en : English ja : Japanese
# fr : French ko : Korean
# ar : Arabic es : Latin American Spanish
# bn : Bengali lv : Latvian
# pt_BR: Brazilian Portuguese lt : Lithuanian
# bg : Bulgarian ms : Malay
# fr_CA: Canadian French es_MX: Mexican Spanish
# ca : Catalan no : Norwegian
# hr : Croatian pl : Polish
# cs : Czech pt : Portuguese
# da : Danish ro : Romanian
# nl : Dutch ru : Russian
# ar_EG: Egyptian zh_CN: Simplified Chinese
# en_GB: English (Great Britain) sk : Slovak
# et : Estonian sl : Slovenian
# fi : Finnish es_ES: Spanish
# de : German sv : Swedish
# el : Greek th : Thai
# iw : Hebrew zh_TW: Traditional Chinese
# hu : Hungarian tr : Turkish
# is : Icelandic uk : Ukrainian
# in : Indonesian vi : Vietnamese
# it : Italian
#
# all_langs : All languages
#
# Specify value as the following to select any of the languages.
# Example : SELECTED_LANGUAGES=en,fr,ja
#
# Specify value as the following to select all the languages.
# Example : SELECTED_LANGUAGES=all_langs
#-------------------------------------------------------------------------------
SELECTED_LANGUAGES=en,zh_CN

#-------------------------------------------------------------------------------
# Specify the complete path of the Oracle Home.
#-------------------------------------------------------------------------------
ORACLE_HOME=/u01/app/oracle

#-------------------------------------------------------------------------------
# Specify the complete path of the Oracle Base.
#-------------------------------------------------------------------------------
ORACLE_BASE=/u01/app

#-------------------------------------------------------------------------------
# Specify the installation edition of the component.
#
# The value should contain only one of these choices.
# - EE : Enterprise Edition

#-------------------------------------------------------------------------------
oracle.install.db.InstallEdition=EE

###############################################################################
# #
# PRIVILEGED OPERATING SYSTEM GROUPS #
# ------------------------------------------ #
# Provide values for the OS groups to which OSDBA and OSOPER privileges #
# needs to be granted. If the install is being performed as a member of the #
# group "dba", then that will be used unless specified otherwise below. #
# #
# The value to be specified for OSDBA and OSOPER group is only for UNIX based #
# Operating System. #
# #
###############################################################################

#------------------------------------------------------------------------------
# The DBA_GROUP is the OS group which is to be granted OSDBA privileges.
#-------------------------------------------------------------------------------
oracle.install.db.DBA_GROUP=dba

#------------------------------------------------------------------------------
# The OPER_GROUP is the OS group which is to be granted OSOPER privileges.
# The value to be specified for OSOPER group is optional.
#------------------------------------------------------------------------------
oracle.install.db.OPER_GROUP=dba

#------------------------------------------------------------------------------
# The BACKUPDBA_GROUP is the OS group which is to be granted OSBACKUPDBA privileges.
#------------------------------------------------------------------------------
oracle.install.db.BACKUPDBA_GROUP=dba

#------------------------------------------------------------------------------
# The DGDBA_GROUP is the OS group which is to be granted OSDGDBA privileges.
#------------------------------------------------------------------------------
oracle.install.db.DGDBA_GROUP=dba

#------------------------------------------------------------------------------
# The KMDBA_GROUP is the OS group which is to be granted OSKMDBA privileges.
#------------------------------------------------------------------------------
oracle.install.db.KMDBA_GROUP=dba
#------------------------------------------------------------------------------
# Specify whether user doesn't want to configure Security Updates.
# The value for this variable should be true if you don't want to configure
# Security Updates, false otherwise.
#
# The value can be either true or false. If left blank it will be assumed
# to be false.
#
# Example : DECLINE_SECURITY_UPDATES=false
#------------------------------------------------------------------------------
DECLINE_SECURITY_UPDATES=true

最后运行./runInstaller -silent -responsefile /home/oracle/db_install.rsp安装即可

利用DBCA创建数据库

数据库软件有了之后,建库的方式有很多,例如手工建库,OFM建库以及DBCA静默建库。下面讲一讲相对简单的DBCA静默建库。
通过DBCA -HELP命令查看命令参数

1
2
3
4
5
6
7
[oracle@localhost ~]$ dbca -help  

dbca [-silent | -progressOnly] {<command> <options> } | { [<command> [options] ] -responseFile <response file > } [-continueOnNonFatalErrors <true | false>]

<command> : -createDatabase | -configureDatabase | -createTemplateFromDB | -createCloneTemplate | -generateScripts | -deleteDatabase | -createPluggableDatabase | -unplugDatabase | -deletePluggableDatabase | -configurePluggableDatabase

Enter "dbca -<command> -help" for more option

可以看-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
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
[oracle@localhost ~]$ dbca -createDatabase -help
Create a database by specifying the following parameters:
-createDatabase
-templateName <name of an existing template in default location or the complete template path>
[-cloneTemplate]
-gdbName <global database name>
[-ignorePreReqs] <ignore prerequisite checks for current operation>
[-sid <database system identifier>]
[-createAsContainerDatabase <true|false>]
[-numberOfPDBs <Number of Pluggable databases to be created, default is 0>]
[-pdbName <New Pluggable Database Name>]
[-pdbAdminPassword <PDB Administrator user Password, required only when creating new PDB>]
[-sysPassword <SYS user password>]
[-systemPassword <SYSTEM user password>]
[-emConfiguration <DBEXPRESS|CENTRAL|BOTH|NONE>]
-dbsnmpPassword <DBSNMP user password>
[-omsHost <EM management server host name>
-omsPort <EM management server port number>
-emUser <EM Admin username to add or modify targets>
-emPassword <EM Admin user password>
-emExpressPort <EM Database Express port number>]]
[-dvConfiguration <true | false Specify "true" to configure and enable Database Vault
-dvUserName <Specify Database Vault Owner user name>
-dvUserPassword <Specify Database Vault Owner password>
-dvAccountManagerName <Specify separate Database Vault Account Manager >
-dvAccountManagerPassword <Specify Database Vault Account Manager password>]
[-olsConfiguration <true | false Specify "true" to configure and enable Oracle Label Security >
[-datafileDestination <destination directory for all database files.> |
-datafileNames <a text file containing database objects such as controlfiles, tablespaces, redo log files and spfile to their corresponding raw device file names mappings in name=value format.>]
[-redoLogFileSize <size of each redo log file in megabytes>]
[-recoveryAreaDestination <destination directory for all recovery files. Specify "NONE" for disabling Fast Recovery Area.>]
[-datafileJarLocation <location of the data file jar, used only for clone database creation>]
[-storageType < FS | ASM >
[-asmsnmpPassword <ASMSNMP password for ASM monitoring>]
-diskGroupName <database area disk group name>
-recoveryGroupName <recovery area disk group name>
[-characterSet <character set for the database>]
[-nationalCharacterSet <national character set for the database>]
[-registerWithDirService <true | false>
-dirServiceUserName <user name for directory service>
-dirServicePassword <password for directory service >
-walletPassword <password for database wallet >]
[-listeners <list of listeners to configure the database with>]
[-variablesFile <file name for the variable-value pair for variables in the template>]]
[-variables <comma separated list of name=value pairs>]
[-initParams <comma separated list of name=value pairs>]
[-sampleSchema <true | false> ]
[-memoryPercentage <percentage of physical memory for Oracle>]
[-automaticMemoryManagement <true | false> ]
[-totalMemory <memory allocated for Oracle in MB>]
[-databaseType <MULTIPURPOSE|DATA_WAREHOUSING|OLTP>]]

一大堆参数,global name 、SID、是否创建容器数据库、数据文件地址、字符集等等参数。根据具体需求选择合适的参数执行dbca -silent -createDatabase [database parameters...]命令即可。

1
dbca -silent -createDatabase -templateName $ORACLE_HOME/assistants/dbca/templates/General_Purpose.dbc -gdbName orcogg -sid orcogg -createAsContainerDatabase true -numberOfPDBs 1 -pdbName pdbogg -pdbAdminPassword wonderscd -sysPassword wonderscd -systemPassword wonderscd -datafileDestination /u01/data_files -characterSet GBK16 -automaticMemoryManagement true

最后PS:
(1)依赖包的检测本应该在一开始就检查的,但是我有一个坏毛病每次都是安装时看它提示缺什么包之后再去安装。
(2)各系统需要的package的传送门:http://docs.oracle.com/database/121/LTCQI/toc.htm#CHDJIDDD
(3)安装失败时候主要看看日志中先决条件测试那部分的日志,是否所有先决条件测试都success了