# CentOS6静默安装oracle11gR2详细步骤
### 更改主机名为oracle
``` shell
vim /etc/hosts
#最后一行添加,更改之后最好重启一下机器好生效。
oracle 192.168.60.135
```
### 检查和安装所依赖的安装包
``` shell
##检查是否安装所依赖的安装包
rpm -q binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel gcc gcc-c++ glibc glibc-common glibc-devel glibc-headers ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel make numactl-devel sysstat unixODBC unixODBC-devel
##安装所需要的安装包
yum -y install binutils compat-libstdc++-33 compat-libstdc++-33.i686 elfutils-libelf elfutils-libelf-devel gcc gcc-c++ glibc glibc.i686 glibc-common glibc-devel glibc-devel.i686 glibc-headers ksh libaio libaio.i686 libaio-devel libaio-devel.i686 libgcc libgcc.i686 libstdc++ libstdc++.i686 libstdc++-devel make sysstat ld-linux.so.2 unixODBC unixODBC-devel
yum install libXp libXp.i686
```
[下载地址pdksh](http://vault.centos.org/5.11/os/SRPMS/pdksh-5.2.14-37.el5_8.1.src.rpm)强制安装pdksh
rpm -ivh pdksh-5.2.14-37.el5_8.1.src.rpm --force --nodeps
### 检查swap是否有16G
``` shell
grep SwapTotal /proc/meminfo //若小于16G,执行下面
如果不是服务器的话应该都没有16g,可以忽略下面的操作。
dd if=/dev/zero of=/data/swap bs=1G count=9
mkswap /data/swap && swapon /data/swap
vim /etc/fstab (add)
/data/swap swap swap defaults 0 0
mount -a
```
### 添加用户和组
``` shell
groupadd oinstall
groupadd dba
useradd -g oinstall -G dba oracle
passwd oracle ##为oracle账户设置密码。
```
### 配置内核参数
vim /etc/sysctl.conf
``` shell
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 536870912
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
```shell
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
```
### 修改用户验证选项
vim /etc/pam.d/login
``` shell
session required /lib64/security/pam_limits.so
session required pam_limits.so
```
### 修改用户配置文件
vim /etc/profile
``` shell
if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi
```
### 修改用户
vim /home/oracle/.bash_profile
vim /etc/profile
``` shell
export ORACLE_BASE=/usr/local/oracle
#oracle数据库安装目录
export ORACLE_HOME=/usr/local/oracle/product/11.2.0/dbhome_1/ #oracle数据库路径
export ORACLE_SID=orcl
#启动数据库实例名
#export ORACLE_TERM=xterm
#xterm窗口模式安装
export PATH=$ORACLE_HOME/bin:/usr/sbin:$PATH
#添加系统环境变量
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
#添加系统环境变量
export LANG=C
#防止安装过程出现乱码
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
source ~/.bash_profile
#source文件使之生效
source /etc/profile
#source文件使之生效
```
### oracle用户登录,并测试环境变量是否成功
su - oracle
env | grep ORA //检查环境变量是否设置生效
### 解压安装包
下载安装包到/usr/local/中
``` shell
unzip p13390677_112040_Linux-x86-64_1of7.zip
unzip p13390677_112040_Linux-x86-64_2of7.zip
```
### 配置默认安装的文件
cd /usr/local/database/response/
cp db_install.rsp my_db_install.rsp
采用是我自己写的模板。
``` shell
oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0 ##该选项为必选项并不可以改变。
oracle.install.option=INSTALL_DB_SWONLY
##只安装数据库软件(SoftWare_ONLY)
ORACLE_HOSTNAME=oracle
##设置oracle主机名
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/usr/local/oracle//product/11.2.0/dbhome_1/oraInventory ##该目录为oraclehome下的地址+oraInventory
SELECTED_LANGUAGES=en
ORACLE_HOME=/usr/local/oracle/product/11.2.0/dbhome_1
ORACLE_BASE=/usr/local/oracle
##为/etc/profile中配置的oracle_base变量信息
oracle.install.db.InstallEdition=EE
##EE : Enterprise Edition企业版
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
##如果上面选true,这些就是手动指定的组件
oracle.install.db.DBA_GROUP=dba
##指定拥有DBA用户组,通常会是dba组
oracle.install.db.OPER_GROUP=oinstall
##指定oper用户组
#oracle.install.db.CLUSTER_NODES=
##RAC相关
#oracle.install.db.isRACOneInstall=
##RAC相关
oracle.install.db.config.starterdb.type=GENERAL_PURPOSE##数据库用途,一般事务,数据仓库
oracle.install.db.config.starterdb.characterSet=AL32UTF8
oracle.install.db.config.starterdb.memoryOption=true##//11g的新特性自动内存管理,也就是SGA_TARGET和PAG_AGGREGATE_TARGET都,不用设置了,Oracle会自动调配两部分大小
oracle.install.db.config.starterdb.memoryLimit=
##指定Oracle自动管理内存的大小,总内存的百分之70%
oracle.install.db.config.starterdb.password.ALL=oracle##所有用户名的密码
DECLINE_SECURITY_UPDATES=true
##是否设置安全更新,
```
切换到oracle用户安装oracle(变更文件全是用root账户)
``` shell
su - oracle
/usr/local/database/runInstaller -silent -force -noconfig -responseFile /usr/local/database/db_swonly.rsp
```
``` shell
[root@oracle database]# su - oracle
[oracle@oracle ~]$ cd /usr/local/database/
[oracle@oracle database]$ ./runInstaller -silent -force -noconfig -responseFile /usr/local/database/response/db_install.rsp
Starting Oracle Universal Installer...
Checking Temp space: must be greater than 120 MB. Actual 22798 MB Passed
Checking swap space: must be greater than 150 MB. Actual 1983 MB Passed
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2018-06-25_09-33-26PM. Please wait ...[oracle@oracle database]$ [WARNING] [INS-32055] The Central Inventory is located in the Oracle base.
CAUSE: The Central Inventory is located in the Oracle base.
ACTION: Oracle recommends placing this Central Inventory in a location outside the Oracle base directory.
[WARNING] [INS-13014] Target environment do not meet some optional requirements.
CAUSE: Some of the optional prerequisites are not met. See logs for details. /tmp/OraInstall2018-06-25_09-33-26PM/installActions2018-06-25_09-33-26PM.log
ACTION: Identify the list of failed prerequisite checks from the log: /tmp/OraInstall2018-06-25_09-33-26PM/installActions2018-06-25_09-33-26PM.log. Then either from the log file or from installation manual find the appropriate configuration to meet the prerequisites and fix it manually.
You can find the log of this install session at:
/usr/local/oracle//product/11.2.0/dbhome_1/oraInventory/logs/installActions2018-06-25_09-33-26PM.log
The installation of Oracle Database 11g was successful.
Please check '/usr/local/oracle//product/11.2.0/dbhome_1/oraInventory/logs/silentInstall2018-06-25_09-33-26PM.log' for more details.
As a root user, execute the following script(s):
1. /usr/local/oracle//product/11.2.0/dbhome_1/oraInventory/orainstRoot.sh
2. /usr/local/oracle/product/11.2.0/dbhome_1/root.sh
Successfully Setup Software.
[oracle@oracle database]$ ps -ef |grep mysql
oracle 5766 1513 0 22:06 pts/0 00:00:00 grep mysql
[oracle@oracle database]$ ps -ef |grep oracle
root 1117 1 0 21:06 ? 00:00:00 /sbin/dhclient -H oracle -1 -q -lf /var/lib/dhclient/dhclient-eth0.leases -pf /var/run/dhclient-eth0.pid eth0
```
根据提示使用root用户执行输出的两个脚本:
```she
[root@oracle ~]# /usr/local/oracle//product/11.2.0/dbhome_1/oraInventory/orainstRoot.sh
Changing permissions of /usr/local/oracle//product/11.2.0/dbhome_1/oraInventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.
Changing groupname of /usr/local/oracle//product/11.2.0/dbhome_1/oraInventory to oinstall.
The execution of the script is complete.
[root@oracle ~]# /usr/local/oracle/product/11.2.0/dbhome_1/root.sh
Check /usr/local/oracle/product/11.2.0/dbhome_1/install/root_oracle_2018-06-25_22-04-52.log for the output of root script
```
### 安装监听程序(配置文件不需要做更改)
$ORACLE_HOME/bin -silent -responsefile /usr/local/database/response/netca.rsp
```shel
Parsing command line arguments:
Parameter "silent" = true
Parameter "responsefile" = /usr/local/database/response/netca.rsp
Done parsing command line arguments.
Oracle Net Services Configuration:
Profile configuration complete.
Oracle Net Listener Startup:
Running Listener Control:
/usr/local/oracle/product/11.2.0/dbhome_1/bin/lsnrctl start LISTENER
Listener Control complete.
Listener started successfully.
Listener configuration complete.
Oracle Net Services configuration successful. The exit code is 0
```
---
#### 这处查看监听的时候出现了一个错误:
```shell
[oracle@oracle admin]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 25-JUN-2018 22:15:30
Copyright (c) 1991, 2013, Oracle. All rights reserved.
Message 1053 not found; No message file for product=network, facility=TNSMessage 1020 not found; No message file for product=network, facility=TNSMessage 1021 not found; No message file for product=network, facility=TNSMessage 1022 not found; No message file for product=network, facility=TNSMessage 1023 not found; No message file for product=network, facility=TNSMessage 1026 not found; No message file for product=network, facility=TNSMessage 1034 not found; No message file for product=network, facility=TNSMessage 1024 not found; No message file for product=network, facility=TNSMessage 1025 not found; No message file for product=network, facility=TNSMessage 1040 not found; No message file for product=network, facility=TNSMessage 1033 not found; No message file for product=network, facility=TNSMessage 1028 not found; No message file for product=network, facility=TNSMessage 1415 not found; No message file for product=network, facility=TNS Message 1050 not found; No message file for product=network, facility=TNS
Message 1050 not found; No message file for product=network, facility=TNS
Message 1030 not found; No message file for product=network, facility=TNSMessage 1052 not found; No message file for product=network, facility=TNS[oracle@oracle admin]$ lsnrctl start
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 25-JUN-2018 22:15:39
Copyright (c) 1991, 2013, Oracle. All rights reserved.
TNS-01106: Message 1106 not found; No message file for product=network, facility=TNS
[LISTENER]
```
原因是没有设置ORACLE_HOME的原因,后来检查profile文件并重新设置好后监听可以正常使用。
相关连接:https://blog.csdn.net/zdwzzu2006/article/details/8852857
正常输出状态:
```shell
[oracle@oracle bin]$ ./lsnrctl status
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 25-JUN-2018 22:20:54
Copyright (c) 1991, 2013, 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.4.0 - Production
Start Date 25-JUN-2018 22:13:33
Uptime 0 days 0 hr. 7 min. 22 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /usr/local/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Listener Log File /usr/local/oracle/diag/tnslsnr/oracle/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle)(PORT=1521)))
The listener supports no service
The command completed successfully
```
### 安装数据库
```shell
[root@oracle ~]#vim /usr/local/database/response/create_orcl.rsp
[GENERAL]
RESPONSEFILE_VERSION = "11.2.0"
OPERATION_TYPE = "createDatabase"
[CREATEDATABASE]
GDBNAME = "orcl.com"
SID = "orcl"
DATAFILEDESTINATION = $ORACLE_BASE/oradata
RECOVERYAREADESTINATION = $ORACLE_BASE/flash_recovery_area
TEMPLATENAME = "General_Purpose.dbc"
CHARACTERSET = "AL32UTF8"
NATIONALCHARACTERSET= "UTF8"
TOTALMEMORY = "400"
AUTOMATICMEMORYMANAGEMENT = "TRUE"
SYSPASSWORD = "oracle"
SYSTEMPASSWORD = "oracle"
LISTENERS = LISTENER
```
#### 安装命令:
```shell
[oracle@oracle bin]$$ORACLE_HOME/bin/dbca -silent -responseFile /usr/local/database/response/create_orcl.rsp
Copying database files
1% complete
3% complete
11% complete
18% complete
26% complete
37% complete
Creating and starting Oracle instance
40% complete
45% complete
50% complete
55% complete
56% complete
60% complete
62% complete
Completing Database Creation
66% complete
70% complete
73% complete
85% complete
96% complete
100% complete
Look at the log file "/usr/local/oracle/cfgtoollogs/dbca/oral/oral.log" for further details.
```
#### 查看相关状态:
```shel
[oracle@oracle bin]$ ps -ef |grep oracle
root 1117 1 0 21:06 ? 00:00:00 /sbin/dhclient -H oracle -1 -q -lf /var/lib/dhclient/dhclient-eth0.leases -pf /var/run/dhclient-eth0.pid eth0
root 1512 1388 0 21:33 pts/0 00:00:00 su - oracle
oracle 1513 1512 0 21:33 pts/0 00:00:00 -bash
oracle 5838 1 0 22:13 ? 00:00:00 /usr/local/oracle/product/11.2.0/dbhome_1/bin/tnslsnr LISTENER -inherit
root 5960 5945 0 22:24 pts/2 00:00:00 su - oracle
oracle 5961 5960 0 22:24 pts/2 00:00:00 -bash
oracle 6359 1 0 22:58 ? 00:00:00 ora_pmon_orcl
oracle 6361 1 0 22:58 ? 00:00:00 ora_psp0_orcl
oracle 6363 1 1 22:58 ? 00:00:00 ora_vktm_orcl
oracle 6367 1 0 22:58 ? 00:00:00 ora_gen0_orcl
oracle 6369 1 0 22:58 ? 00:00:00 ora_diag_orcl
oracle 6371 1 0 22:58 ? 00:00:00 ora_dbrm_orcl
oracle 6373 1 0 22:58 ? 00:00:00 ora_dia0_orcl
oracle 6375 1 0 22:58 ? 00:00:00 ora_mman_orcl
oracle 6377 1 0 22:58 ? 00:00:00 ora_dbw0_orcl
oracle 6379 1 0 22:58 ? 00:00:00 ora_lgwr_orcl
oracle 6381 1 0 22:58 ? 00:00:00 ora_ckpt_orcl
oracle 6383 1 0 22:58 ? 00:00:00 ora_smon_orcl
oracle 6385 1 0 22:58 ? 00:00:00 ora_reco_orcl
oracle 6387 1 2 22:58 ? 00:00:00 ora_mmon_orcl
oracle 6389 1 0 22:58 ? 00:00:00 ora_mmnl_orcl
oracle 6391 1 0 22:58 ? 00:00:00 ora_d000_orcl
oracle 6393 1 0 22:58 ? 00:00:00 ora_s000_orcl
oracle 6401 1 0 22:58 ? 00:00:00 ora_qmnc_orcl
oracle 6415 1 0 22:58 ? 00:00:00 ora_cjq0_orcl
oracle 6419 1 0 22:58 ? 00:00:00 ora_q000_orcl
oracle 6421 1 0 22:58 ? 00:00:00 ora_q001_orcl
oracle 6422 1513 3 22:58 pts/0 00:00:00 ps -ef
oracle 6423 1513 0 22:58 pts/0 00:00:00 grep oracle
[oracle@oracle bin]$ echo $ORACLE_SID
orcl
[oracle@oracle bin]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Mon Jun 25 22:58:56 2018
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select instance_name,status from v$instance;
INSTANCE_NAME
STATUS
-------------------------------- ------------------------
orcl
OPEN
SQL> exit
```