1.安装依赖环境

yum -y install binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ glibc glibc-devel ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel libXi libXtst make sysstat unixODBC unixODBC-devel

2.创建所需的操作系统组和用户

Oracle inventory组(通常为 oinstall)
OSDBA组 (通常为 dba)
OSOPER组 (通常为 oper)
Oracle软件所有者(通常为 oracle)

groupadd oinstall
groupadd dba
groupadd oper
useradd -g oinstall -G dba oracle
echo 1 | password --stdin oracle
id oracle

3.配置内核参数和资源限制

vim /etc/sysctl.conf

在/etc/sysctl.conf添加如下参数,如果系统中某个参数高于下面的参数的值 ,保留较大的值,下面的数值只是官方要求的最小值,可以根据系统调整数值,以优化系统性能

net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
fs.file-max = 6815744
fs.aio-max-nr = 1048576
kernel.shmall = 2097152
kernel.shmmax = 2147483648
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= 1048576

使内核参数生效

sysctl -p

在/etc/security/limits.conf中添加如下参数(直接cv在后面就行)

vim /etc/security/limits.conf
oracle              soft    nproc   2047
oracle              hard    nproc   16384
oracle              soft    nofile  1024
oracle              hard    nofile  65536
vim /etc/pam.d/login

在/etc/pam.d/login文件中,添加下面内容

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

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

source /etc/profile

4.创建oracle安装目录

mkdir -p /data/app/
chown -R oracle:oinstall /data/app/
chmod -R 775 /data/app/

5.配置oracle用户环境变量

vim /home/oracle/.bash_profile

umask 022
export ORACLE_HOSTNAME=oracledb
export ORACLE_BASE=/data/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/
export ORACLE_SID=orcl
export PATH=.:$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$ORACLE_HOME/jdk/bin:$PATH
export LC_ALL="en_US"
export LANG="en_US"
export NLS_LANG="AMERICAN_AMERICA.ZHS16GBK"
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"

source /home/oracle/.bash_profile
重载文件

vim /etc/hosts

IP			主机名

禁用使用Transparent HugePages(启用Transparent HugePages,可能会导致造成内存在运行时的延迟分配,Oracle官方建议使用标准的HugePages)

cat /sys/kernel/mm/transparent_hugepage/enabled

这样就说明没有禁用THP
vim /etc/rc.d/rc.local
保存退出,然后赋予rc.local文件执行权限:

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

最后重启系统,以后再检查THP应该就是被禁用了
vim /etc/sysconfig/selinux

将SELINUX=enforcing 改为 SELINUX=disabled重启系统SELINUX就会被永久关闭
reboot				#重启

说明THP已经禁用了

/usr/sbin/sestatus -v

说明SELINUX已经关闭了

yum -y install lrzsz unzip zip

7.上传、解压

unzip linux.x64_11gR2_database_1of2.zip -d /data			#解压包1到data
unzip linux.x64_11gR2_database_2of2.zip -d /data			#解压包1到data

在/data/etc/db_install.rsp修改以下变量的值
vim /data/etc/db_install.rsp

oracle.install.option=INSTALL_DB_SWONLY
UNIX_GROUP_NAME=oinstall
ORACLE_HOSTNAME=lhk_oracle
INVENTORY_LOCATION=/data/app/oracle/inventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOME=/data/app/oracle/product/11.2.0
ORACLE_BASE=/data/app/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.isCustomInstall=true
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=dba
DECLINE_SECURITY_UPDATES=true

8.安装

用oracle用户装oracle

su - oracle
cd /data/database
./runInstaller -silent -responseFile /data/etc/db_install.rsp -ignorePrereq

运行./runInstaller -silent -responseFile /data/etc/db_install.rsp -ignorePrereq指令后会出项一条
/data/app/oracle/inventory/logs/installActions2019-11-15_05-37-19PM.log

这样的提示,安装期间可以使用tail命令监看oracle的安装日志,来观察安装的过程(日志路径和名字就是那条提示)

#日志文件名称根据自己的实际执行时间变更
tail -f /data/app/oracle/inventory/logs/installActions2019-11-15_05-37-19PM.log

安装完成后有如下提示,如果有类似如下提示,说明安装完成

The following configuration scripts need to be executed as the "root" user. 
#!/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.

但是我不知道我哪步错了,显示的这个
索性死马当成活马医进行下一步(Ctrl+c退出tail命令)

9.使用root用户执行脚本

su - root				#换root用户
sh /data/app/oracle/inventory/orainstRoot.sh
sh /data/app/oracle/product/11.2.0/root.sh

10.配置监听程序

su - oracle				#换oracle用户
netca /silent /responsefile /data/etc/netca.rsp
#输出结果
[oracle@oracledb ~]$ netca /silent /responsefile /data/etc/netca.rsp
 
Parsing command line arguments:
    Parameter "silent" = true
    Parameter "responsefile" = /data/etc/netca.rsp
Done parsing command line arguments.
Oracle Net Services Configuration:
Profile configuration complete.
Oracle Net Listener Startup:
    Running Listener Control:
      /data/app/oracle/product/11.2.0/bin/lsnrctl start LISTENER
    Listener Control complete.
    Listener started successfully.
Listener configuration complete.
Oracle Net Services configuration successful. The exit code is 0

如果运行netca /silent /responsefile /data/etc/netca.rsp不是向上面这样的成功,注意看/home/hosts文件中是否加了你的主机名(详情在第5步),还有上面oracle配置文件中的主机名是否改成了你自己的主机名
查看监听端口

su root#切换到root用户安装依赖
yum -y install net-tools#安装依赖
su oracle#切换到oracle用户
netstat -tnpl | grep 1521#用安装的命令查端口号

11.静默创建数据库

编辑应答文件/data/etc/dbca.rsp

su - root						#切换到root用户
vi /data/etc/dbca.rsp

挨个找然后修改,别直接在后面加,有默认值直接加要出错

[GENERAL]
RESPONSEFILE_VERSION = "11.2.0"
OPERATION_TYPE = "createDatabase"
[CREATEDATABASE]
GDBNAME = "orcl"
SID = "orcl"
SYSPASSWORD = "oracle"
SYSTEMPASSWORD = "oracle"
SYSMANPASSWORD = "oracle"
DBSNMPPASSWORD = "oracle"
DATAFILEDESTINATION =/data/app/oracle/oradata
RECOVERYAREADESTINATION=/data/app/oracle/fast_recovery_area
CHARACTERSET = "AL32UTF8"
TOTALMEMORY = "1638"

执行静默建库

su - oracle
dbca -silent -responseFile /data/etc/dbca.rsp

执行过程如下

[oracle@lhk_oracle database]$ dbca -silent -responseFile /data/etc/dbca.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 "/data/app/oracle/cfgtoollogs/dbca/orcl/orcl.log" for further details.

查看进程

ps -ef | grep ora_ | grep -v grep
[oracle@lhk_oracle database]$ ps -ef | grep ora_ | grep -v grep
oracle    17496      1  0 18:48 ?        00:00:00 ora_pmon_orcl
oracle    17498      1  0 18:48 ?        00:00:00 ora_vktm_orcl
oracle    17502      1  0 18:48 ?        00:00:00 ora_gen0_orcl
oracle    17504      1  0 18:48 ?        00:00:00 ora_diag_orcl
oracle    17506      1  0 18:48 ?        00:00:00 ora_dbrm_orcl
oracle    17508      1  0 18:48 ?        00:00:00 ora_psp0_orcl
oracle    17510      1  0 18:48 ?        00:00:00 ora_dia0_orcl
oracle    17512      1  0 18:48 ?        00:00:00 ora_mman_orcl
oracle    17514      1  0 18:48 ?        00:00:00 ora_dbw0_orcl
oracle    17516      1  0 18:48 ?        00:00:00 ora_lgwr_orcl
oracle    17518      1  0 18:48 ?        00:00:00 ora_ckpt_orcl
oracle    17520      1  0 18:48 ?        00:00:00 ora_smon_orcl
oracle    17522      1  0 18:48 ?        00:00:00 ora_reco_orcl
oracle    17524      1  0 18:48 ?        00:00:00 ora_mmon_orcl
oracle    17526      1  0 18:48 ?        00:00:00 ora_mmnl_orcl
oracle    17528      1  0 18:48 ?        00:00:00 ora_d000_orcl
oracle    17530      1  0 18:48 ?        00:00:00 ora_s000_orcl
oracle    17541      1  0 18:48 ?        00:00:00 ora_qmnc_orcl
oracle    17557      1  0 18:48 ?        00:00:00 ora_cjq0_orcl
oracle    17566      1  0 18:48 ?        00:00:00 ora_q000_orcl
oracle    17568      1  0 18:48 ?        00:00:00 ora_q001_orcl

查看监听状态

lsnrctl status
[oracle@lhk_oracle database]$ lsnrctl status
 
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 15-MAR-2019 18:50:22
 
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                15-MAR-2019 17:55:11
Uptime                    0 days 0 hr. 55 min. 10 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /data/app/oracle/product/11.2.0/network/admin/listener.ora
Listener Log File         /data/app/oracle/diag/tnslsnr/lhk_oracle/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(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

12.至此数据库就安装成功了,下面我们登录下数据库

su - oracle							#切换到oracle用户
sqlplus / as sysdba					#进入数据库
select status from v$instance;		#查数据库状态

执行select时,全出现以下情况

SQL> select status from v$instance;
select status from v$instance
*
ERROR at line 1:
ORA-01034: ORACLE not available
Process ID: 0
Session ID: 0 Serial number: 0

解决方式:

startup

输入startup后出现以下结果

SQL> startup
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/data/app/oracle/product/11.2.0/dbs/initORCL.ora'
exit						#退出数据库

**根据提示,将ORACLEBASE/admin/数据库名称/pfile目录下的init.ora.xxx形式的文件copy到ORACLE_HOME/dbs目录下initOracle.ora(根据startup提示)即可
**
首先先查看装数据库时生成的文件(根据你的安装目录来)

[oracle@lhk_oracle ~]$ cd /data/app/oracle/admin/orcl/pfile/
[oracle@lhk_oracle pfile]$ ls
init.ora.21520112123232

然后把这个文件copy到startup指令提示的位置

su - root					#先切换到root用户,怕oracle用户没权限
cp /data/app/oracle/admin/orcl/pfile/init.ora.2152019184812 /data/app/oracle/product/11.2.0/dbs/initORCL.ora

最后再次startup

su - oracle
sqlplus / as sysdba
startup

如果还是上面的错误,看看/home/oracle/.bash_profile里的ORACLE_SID、和你刚刚cp到/data/app/oracle/product/11.2.0/dbs/initORCL.ora里的db_name是不是一样(其实我也不太懂),总之把ORACLE_SID的值改成db_name的值就行了(注意大小写)

su - root#切换到root用户
cat /home/oracle/.bash_profile
cat /data/app/oracle/product/11.2.0/dbs/initORCL.ora

然后重载/home/oracle/.bash_profile文件

source /home/oracle/.bash_profile

再次startup,出现

SQL> startup
ORACLE instance started.
 
Total System Global Area 1286066176 bytes
Fixed Size		    2213016 bytes
Variable Size		  352324456 bytes
Database Buffers	  922746880 bytes
Redo Buffers		    8781824 bytes
ORA-01102: cannot mount database in EXCLUSIVE mode
su - root
yum -y install psmisc#安装依赖

** 查看在占用lk开头文件的程序的进程**

fuser -u /data/app/oracle/product/11.2.0/dbs/lkORCL
#(如果没有,就到目录下找名叫lkXXX的文件,这是根据你们的配置生成的)
[root@lhk_oracle dbs]# fuser -u /data/app/oracle/product/11.2.0/dbs/lkORCL
/data/app/oracle/product/11.2.0/dbs/lkORCL: 17496(oracle) 17502(oracle) 17506(oracle) 17508(oracle) 17512(oracle) 17514(oracle) 17516(oracle) 17518(oracle) 17520(oracle) 17522(oracle) 17524(oracle) 17526(oracle) 17541(oracle) 17557(oracle) 17566(oracle) 17568(oracle) 18059(oracle) 20754(oracle)

果然有一大堆,然后kill掉这些进程

fuser -k /data/app/oracle/product/11.2.0/dbs/lkORCL

再次startup

su oracle
sqlplus / as sysdba
SQL> startup
ORACLE instance started.
 
Total System Global Area 1286066176 bytes
Fixed Size		    2213016 bytes
Variable Size		  352324456 bytes
Database Buffers	  922746880 bytes
Redo Buffers		    8781824 bytes
Database mounted.
Database opened.

启动数据库成功

其他报错如下:

https://www.jb51.net/article/98191.htm

https://www.vpsv.cn/article/123.html



http://blog.itpub.net/12272958/viewspace-716020

http://blog.sina.com.cn/s/blog_4b5bc0110101d310.html