0%

CentOS6.9环境静默安装Oracle11g

系统基础环境

操作系统:CentOS 6.9 x64
Iptables:off
Selinux:disabled

修改主机名

安装oracle后不要修改主机名,会引起故障

1
2
3
vim /etc/sysconfig/network
NETWORKING=yes
HOSTNAME="dbserver"
1
hostname dbserver

添加一条hosts记录,主机名映射

1
127.0.0.1	dbserver

基础软件安装

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
#默认是不安装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-* mksh
#监测一下软件是否安装全
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"

修改PAM配置文件

1
2
3
vim /etc/pam.d/login
session required /lib64/security/pam_limits.so
session required pam_limits.so

修改内核参数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
vim /etc/sysctl.conf
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

修改系统资源限制

1
2
3
4
5
6
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

Oracle相关环境配置

新建用户

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

修改用户配置文件

1
2
3
4
5
6
7
8
9
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

新建目录并设置权限

1
2
3
4
5
mkdir -p /u01/app/oracle/product/11.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用户环境变量

1
2
3
4
5
6
7
8
su - oracle
$ vim ~/.bash_profile
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export ORACLE_SID=sx21
export PATH=$PATH:$ORACLE_HOME/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export NLS_LANG=American_America.ZHS16GBK

检查环境变量是否生效

1
2
3
4
5
source ~/.bash_profile
env |grep ORA
ORACLE_SID=sx21
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1

准备软件安装包

下载地址: http://www.oracle.com/technetwork/database/enterprise-edition/downloads/112010-linx8664soft-100572.html
可以使用cksum校验文件完整性
linux.x64_11gR2_database_1of2.zip (1,239,269,270 bytes) (cksum - 3152418844)
linux.x64_11gR2_database_2of2.zip (1,111,416,131 bytes) (cksum - 3669256139)

解压软件包

1
2
unzip linux.x64_11gR2_database_1of2.zip
unzip linux.x64_11gR2_database_2of2.zip

解压后得到/home/oracle/database/response目录,该目录中有三个rsp文件,用来作为静默安装时的应答文件的模板。
备份三个文件并修改其内容

1
2
3
db_install.rsp	安装应答
netca.rsp 建立监听、本地服务名等网络设置的应答
dbca.rsp 创建数据库应答

静默安装数据库软件

修改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
egrep -v "^#|^$" db_install.rsp
oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0
oracle.install.option=INSTALL_DB_SWONLY
ORACLE_HOSTNAME=dbserver
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/u01/app/oraInventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
ORACLE_BASE=/u01/app/oracle/
oracle.install.db.InstallEdition=EE
oracle.install.db.EEOptionsSelection=false
oracle.install.db.optionalComponents=oracle.rdbms.partitioning:11.2.0.4.0,oracle.oraolap:11.2.0.4.0,oracle.rdbms.dm:11.2.0.4.0,oracle.rdbms.dv:11.2.0.4.0,oracle.rdbms.lbac:11.2.0.4.0,oracle.rdbms.rat:11.2.0.4.0
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=dba
oracle.install.db.CLUSTER_NODES=
oracle.install.db.isRACOneInstall=
oracle.install.db.racOneServiceName=
oracle.install.db.config.starterdb.type=
oracle.install.db.config.starterdb.globalDBName=orcl
oracle.install.db.config.starterdb.SID=orcl
oracle.install.db.config.starterdb.characterSet=ZHS16GBK
oracle.install.db.config.starterdb.memoryOption=true
oracle.install.db.config.starterdb.memoryLimit=81920
oracle.install.db.config.starterdb.installExampleSchemas=false
oracle.install.db.config.starterdb.enableSecuritySettings=true
oracle.install.db.config.starterdb.password.ALL=solution#123$$
oracle.install.db.config.starterdb.password.SYS=
oracle.install.db.config.starterdb.password.SYSTEM=
oracle.install.db.config.starterdb.password.SYSMAN=
oracle.install.db.config.starterdb.password.DBSNMP=
oracle.install.db.config.starterdb.control=DB_CONTROL
oracle.install.db.config.starterdb.gridcontrol.gridControlServiceURL=
oracle.install.db.config.starterdb.automatedBackup.enable=false
oracle.install.db.config.starterdb.automatedBackup.osuid=
oracle.install.db.config.starterdb.automatedBackup.ospwd=
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=
DECLINE_SECURITY_UPDATES=true
PROXY_HOST=
PROXY_PORT=
PROXY_USER=
PROXY_PWD=
PROXY_REALM=
COLLECTOR_SUPPORTHUB_URL=
oracle.installer.autoupdates.option=
oracle.installer.autoupdates.downloadUpdatesLoc=
AUTOUPDATES_MYORACLESUPPORT_USERNAME=
AUTOUPDATES_MYORACLESUPPORT_PASSWORD=

执行静默安装

1
2
3
4
5
6
7
8
9
10
$ pwd
/home/oracle/database
./runInstaller -silent -ignorePrereq -ignoreSysPrereqs -responseFile /home/oracle/database/response/db_install.rsp

Starting Oracle Universal Installer...

Checking Temp space: must be greater than 120 MB. Actual 26363 MB Passed
Checking swap space: must be greater than 150 MB. Actual 4095 MB Passed
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2017-12-27_02-06-55PM. Please wait ...[oracle@dbserver database]$ You can find the log of this install session at:
/u01/app/oraInventory/logs/installActions2017-12-27_02-06-55PM.log

安装过程中可以另开一个窗口跟踪查看日志

1
2
3
4
5
6
7
8
9
10
11
12
tailf /u01/app/oraInventory/logs/installActions2017-12-27_02-06-55PM.log

……

INFO: Completed validating state <finish>
INFO: Terminating all background operations
INFO: Terminated all background operations
INFO: Successfully executed the flow in SILENT mode
INFO: Finding the most appropriate exit status for the current application
INFO: Exit Status is 0
INFO: Shutdown Oracle Database 11g Release 2 Installer
INFO: Unloading Setup Driver
1
2
3
4
5
6
7
8
9
10
11
12
 #!/bin/sh 
#Root scripts to run

/u01/app/oraInventory/orainstRoot.sh
/u01/app/oracle/product/11.2.0/db_1/root.sh
To execute the configuration scripts:
1. Open a terminal window
2. Log in as "root"
3. Run the scripts
4. Return to this window and hit "Enter" key to continue

Successfully Setup Software.

一直到主窗口出现以上提示,以root用户打开一个窗口,一次执行下面操作

1
2
3
4
5
6
7
8
9
[root@dbserver ~]# /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@dbserver ~]# /u01/app/oracle/product/11.2.0/db_1/root.sh
Check /u01/app/oracle/product/11.2.0/db_1/install/root_dbserver_2017-12-27_14-23-43.log for the output of root script

静默安装监听

使用默认配置文件,不用修改

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ORACLE_HOME/bin/netca /silent /responseFile /home/oracle/database/response/netca.rsp


Parsing command line arguments:
Parameter "silent" = true
Parameter "responsefile" = /home/oracle/database/response/netca.rsp
Done parsing command line arguments.
Oracle Net Services Configuration:
Profile configuration complete.
Oracle Net Listener Startup:
Running Listener Control:
/u01/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

默认监听是开启状态

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[oracle@dbserver database]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 27-DEC-2017 14:26:34

Copyright (c) 1991, 2009, 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.1.0 - Production
Start Date 27-DEC-2017 14:25:48
Uptime 0 days 0 hr. 0 min. 50 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/dbserver/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=dbserver)(PORT=1521)))
The listener supports no services
The command completed successfully

静默新建实例

修改dbca.rsp配置

这里只需要修改[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
$ egrep -v "^#|^$" dbca.rsp 
[GENERAL]
RESPONSEFILE_VERSION = "11.2.0"
OPERATION_TYPE = "createDatabase"
[CREATEDATABASE]
GDBNAME = "sx21"
SID = "sx21"
TEMPLATENAME = "General_Purpose.dbc"
SYSPASSWORD = "solution#123"
SYSTEMPASSWORD = "solution#123"
CHARACTERSET = "ZHS16GBK"
NATIONALCHARACTERSET= "AL16UTF16"
[createTemplateFromDB]
SOURCEDB = "myhost:1521:orcl"
SYSDBAUSERNAME = "system"
TEMPLATENAME = "My Copy TEMPLATE"
[createCloneTemplate]
SOURCEDB = "orcl"
TEMPLATENAME = "My Clone TEMPLATE"
[DELETEDATABASE]
SOURCEDB = "orcl"
[generateScripts]
TEMPLATENAME = "New Database"
GDBNAME = "orcl11.us.oracle.com"
[CONFIGUREDATABASE]
[ADDINSTANCE]
DB_UNIQUE_NAME = "orcl11g.us.oracle.com"
NODELIST=
SYSDBAUSERNAME = "sys"
[DELETEINSTANCE]
DB_UNIQUE_NAME = "orcl11g.us.oracle.com"
INSTANCENAME = "orcl11g"
SYSDBAUSERNAME = "sys"

执行静默安装

不清楚是什么原因,我执行静默安装命令,屏幕就一直闪烁,不能输入密码,所以我将密码写到dbca.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
$ORACLE_HOME/bin/dbca -silent -responseFile /home/oracle/database/response/dbca.rsp


Copying database files
1% complete
2% complete
4% complete
37% complete
Creating and starting Oracle instance
38% complete
40% complete
45% complete
50% complete
51% complete
56% complete
57% complete
61% complete
62% complete
Completing Database Creation
66% complete
70% complete
73% complete
74% complete
85% complete
86% complete
98% complete
100% complete
Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/sx21/sx21.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
[oracle@dbserver app]$ ps -ef |grep ora_
oracle 5432 1 0 17:02 ? 00:00:00 ora_pmon_sx21
oracle 5434 1 0 17:02 ? 00:00:00 ora_vktm_sx21
oracle 5438 1 0 17:02 ? 00:00:00 ora_gen0_sx21
oracle 5440 1 0 17:02 ? 00:00:00 ora_diag_sx21
oracle 5442 1 0 17:02 ? 00:00:00 ora_dbrm_sx21
oracle 5444 1 0 17:02 ? 00:00:00 ora_psp0_sx21
oracle 5446 1 0 17:02 ? 00:00:00 ora_dia0_sx21
oracle 5448 1 0 17:02 ? 00:00:01 ora_mman_sx21
oracle 5450 1 0 17:02 ? 00:00:00 ora_dbw0_sx21
oracle 5452 1 0 17:02 ? 00:00:00 ora_lgwr_sx21
oracle 5454 1 0 17:02 ? 00:00:00 ora_ckpt_sx21
oracle 5456 1 0 17:02 ? 00:00:00 ora_smon_sx21
oracle 5458 1 0 17:02 ? 00:00:00 ora_reco_sx21
oracle 5460 1 0 17:02 ? 00:00:00 ora_mmon_sx21
oracle 5462 1 0 17:02 ? 00:00:00 ora_mmnl_sx21
oracle 5464 1 0 17:02 ? 00:00:00 ora_d000_sx21
oracle 5466 1 0 17:02 ? 00:00:00 ora_s000_sx21
oracle 5558 1 0 17:02 ? 00:00:00 ora_qmnc_sx21
oracle 5575 1 0 17:02 ? 00:00:00 ora_cjq0_sx21
oracle 5579 1 0 17:02 ? 00:00:00 ora_q000_sx21
oracle 5581 1 0 17:02 ? 00:00:00 ora_q001_sx21
oracle 5585 1550 0 17:04 pts/0 00:00:00 grep ora_

监听

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
[oracle@dbserver app]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 27-DEC-2017 17:04:44

Copyright (c) 1991, 2009, 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.1.0 - Production
Start Date 27-DEC-2017 16:49:14
Uptime 0 days 0 hr. 15 min. 32 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/dbserver/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=dbserver)(PORT=1521)))
Services Summary...
Service "sx21" has 1 instance(s).
Instance "sx21", status READY, has 1 handler(s) for this service...
Service "sx21XDB" has 1 instance(s).
Instance "sx21", status READY, has 1 handler(s) for this service...
The command completed successfully

连接

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[oracle@dbserver app]$ sqlplus /nolog

SQL*Plus: Release 11.2.0.1.0 Production on Wed Dec 27 17:05:57 2017

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

SQL> conn /as sysdba
Connected.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.

Total System Global Area 3340451840 bytes
Fixed Size 2217952 bytes
Variable Size 1811941408 bytes
Database Buffers 1509949440 bytes
Redo Buffers 16343040 bytes
Database mounted.
Database opened.

静默删除数据库实例

1
dbca -silent -deleteDatabase -sourcedb orcl -sid orcl -sysDBAUserName sys -sysDBAPassword password

扩展配置

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

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

错误解析

[WARNING] - My Oracle Support Username/Email Address Not Specified

DECLINE_SECURITY_UPDATES=true

[FATAL] [INS-10101] The given response file response/db_install.rsp is not found.

响应文件写为绝对路径/usr/local/src/oracle/database/response/db_install.rsp

[FATAL] [INS-00001] Unknown irrecoverable error

设置的密码中不能有%

常用语句

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
--创建表空间
CREATE TABLESPACE TS_TENV datafile '/u01/app/oracle/oradata/monitor/ts_tenv01.dbf' SIZE 200m AUTOEXTEND ON NEXT 32m MAXSIZE 32767M EXTENT MANAGEMENT LOCAL;
CREATE TABLESPACE TS_WEATHER datafile '/u01/app/oracle/oradata/monitor/ts_weather01.dbf' SIZE 200m AUTOEXTEND ON NEXT 32m MAXSIZE 32767M EXTENT MANAGEMENT LOCAL;

--创建临时表空间
CREATE TEMPORARY TABLESPACE TS_TENV_TEMP TEMPFILE '/u01/app/oracle/oradata/monitor/ts_tenv_temp01.dbf' SIZE 200m AUTOEXTEND ON NEXT 32m MAXSIZE 2048m EXTENT MANAGEMENT LOCAL;
CREATE TEMPORARY TABLESPACE TS_WEATHER_TEMP TEMPFILE '/u01/app/oracle/oradata/monitor/ts_weather_temp01.dbf' SIZE 200m AUTOEXTEND ON NEXT 32m MAXSIZE 2048m EXTENT MANAGEMENT LOCAL;

创建用户指定默认表空间
--新建用户
CREATE USER TENV IDENTIFIED BY tenv#123 DEFAULT TABLESPACE TS_TENV TEMPORARY TABLESPACE TS_TENV;
CREATE USER WEATHER IDENTIFIED BY weather#123 DEFAULT TABLESPACE TS_WEATHER TEMPORARY TABLESPACE TS_WEATHER;

--如果先新建用户了,使用以下命令修改默认表空间
alter user TENV default tablespace TS_TENV;
alter user WEATHER default tablespace TS_WEATHER;
--授权连接权限
GRANT CONNECT TO TENV;
GRANT CONNECT TO WEATHER;
--授权表空间
GRANT UNLIMITED TABLESPACE TO TENV;
GRANT UNLIMITED TABLESPACE TO WEATHER;

--修改密码有效期为永久
ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED ;
SELECT * FROM dba_profiles WHERE profile='DEFAULT' AND resource_name='PASSWORD_LIFE_TIME';
--解锁账号
alter user 用户名 identified by 原密码;
alter user db_user account unlock;
--查看每个用户连接数
select username,count(username) from v$session where username is not null group by username;
--修改最大连接数
1. 查看最大连接数
show parameter processes
2. 修改最大连接数
alter system set processes = 1500 scope = spfile;
3. 重启数据库
shutdown immediate;  
startup;

参考文档:
https://www.jianshu.com/p/b4200e721bfd
http://blog.51cto.com/wzlinux/1710941