[root@oracle ~]# cat /etc/hosts
127.0.0.1 oracle.osp.cloud localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 oracle.osp.cloud localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.0.220 oracle

关闭selinux
#vi /etc/selinux/config
设置
SELINUX=disabled
#setenforce 0

关闭防火墙(或开放端口)
#serviceiptables stop
#systemctl stop firewalld
#systemctl disable firewalld

安装Oracle 11g依赖包
#yum install epel-release.noarch
#yum install gcc make binutilsgcc-c++ compat-libstdc++-33 elfutils-libelf-develelfutils-libelf-devel-static ksh libaio libaio-devel numactl-devel sysstat unixODBC unixODBC-devel pcre-devel –y

添加安装用户和用户组
#groupadd oinstall
#groupadd dba
#useradd -g oinstall -G dba oracle
#passwd oracle
#id oracle
如显示类似以下信息则表示添加用户和用户组成功
uid=1001(oracle) gid=1001(oinstall) 组=1001(oinstall),1002(dba)

修改内核参数
#vi /etc/sysctl.conf
添加以下内容
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 1073741824
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
其中shmmax是单个共享内存段的最大值,一般设置为本机物理内存的一半,单位为byte,可根据自己的实际情况做相应调整
使新内核参数生效
#sysctl -p
修改用户的限制文件
#vi /etc/security/limits.conf
添加以下内容
oracle soft nproc 65535
oracle hard nproc 65535
oracle soft nofile 65535
oracle hard nofile 65535

修改/etc/pam.d/login文件
#vi /etc/pam.d/login
添加以下内容
session required /lib64/security/pam_limits.so
session required pam_limits.so

修改/etc/profile文件
#vi /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

创建安装目录和设置文件权限(根据服务器硬盘空间,自己选择安装目录)
[root@localhost ~]# mkdir -p /home/oracle/product/11gR2
[root@localhost ~]# chown -R oracle:oinstall /home/oracle
[root@localhost ~]# mkdir /home/oraInventory
[root@localhost ~]# chown -R oracle:oinstall /home/oraInventory

设置oracle用户环境变量
#su - oracle
此处注意,切换用户时切记要加"-",加-会拥有目标用户的环境变量,不加"-"则没有,详细的可自行网上搜索找解答
$vi .bash_profile
添加如下内容
export ORACLE_BASE=/home/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11gR2
export ORACLE_SID=orcl
export PATH=$ORACLE_HOME/bin:/usr/sbin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export LANG=AMERICAN_AMERICA.ZHS16GBK

使配置生效
$source .bash_profile

$hostnamectl set-hostname oracle

#解压Oracle数据库(/home/oracle/路径下)
$unzip linux.x64_11gR2_database_1of2.zip
$unzip linux.x64_11gR2_database_2of2.zip
[oracle@oracle ~]$ ls -lrt
total 4
drwxr-xr-x 8 oracle oinstall 4096 Aug 21 2009 database
-rw-r--r-- 1 oracle oinstall 1239269270 Aug 21 2009 linux.x64_11gR2_database_1of2.zip
-rw-r--r-- 1 oracle oinstall 1111416131 Aug 21 2009 linux.x64_11gR2_database_2of2.zip
drwxr-xr-x 3 oracle oinstall 4096 Jan 8 13:35 oracle

编辑静默安装响应文件
$cp -R /home/oracle/database/response /home/oracle
$cd /home/oracle/response
$vi db_install.rsp
需要设置的选项如下
oracle.install.option=INSTALL_DB_SWONLY
ORACLE_HOSTNAME=oracle
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/home/oraInventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOME=/home/oracle/product/11gR2
ORACLE_BASE=/home/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=oinstall
DECLINE_SECURITY_UPDATES=true

安装数据库软件
$cd /home/oracle/database
$./runInstaller -silent -force -ignorePrereq -responseFile /home/oracle/response/db_install.rsp

.....
The following configuration scripts need to be executed as the "root" user.
#!/bin/sh
#Root scripts to run

/home/oraInventory/orainstRoot.sh
/home/oracle/product/11gR2/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.
Oracle开始在后台静默安装,如果提示Successfully则表示安装成功

按照要求执行脚本,打开终端,以root用户登录,执行脚本
/home/oraInventory/orainstRoot.sh
/home/oracle/product/11gR2/root.sh

以oracle用户登录,执行
$netca /silent /responsefile /home/oracle/response/netca.rsp

通过netstat命令查看1521端口是否在监听中
$netstat -tnulp | grep 1521

vi /home/oracle/response/dbca.rsp
设置以下参数(参数有多个,只修改第一处,密码为oracle用户密码)
GDBNAME = "orcl"
SID = "orcl"
SYSPASSWORD = "oracle"
SYSTEMPASSWORD = "oracle"
SYSMANPASSWORD = "oracle"
DBSNMPPASSWORD = "oracle"
DATAFILEDESTINATION =/home/oracle/oradata
RECOVERYAREADESTINATION=/home/oracle/fast_recovery_area
CHARACTERSET = "ZHS16GBK"
TOTALMEMORY = "28000"
其中TOTALMEMORY = "6400"为6400MB,一般设置为物理内存的80%

进行静默配置
$ $ORACLE_HOME/bin/dbca -silent -responseFile /home/oracle/response/dbca.rsp
注意,如果直接进行上面命令的执行会报如下错误:The file "/home/oracle/oradata/Seed_Database.dfb" containing the datafiles information is not found. Please specify a valid file.
所以需要拷贝Seed_Database.dfb文件到/home/oracle/oradata/路径下
[oracle@oracle ~]$ find -name Seed_Database.dfb
./product/11gR2/assistants/dbca/templates/Seed_Database.dfb
./database/stage/Components/oracle.rdbms.install.seeddb/11.2.0.1.0/1/DataFiles/Expanded/filegroup1/Seed_Database.dfb
[oracle@oracle ~]$ cp ./product/11gR2/assistants/dbca/templates/Seed_Database.dfb oradata/orcl/
然后再执行$ $ORACLE_HOME/bin/dbca -silent -responseFile /home/oracle/response/dbca.rsp命令
Enter SYS user password:

Enter SYSTEM user password:

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 "/u01/oracle/cfgtoollogs/dbca/orcl/orcl.log" for further details.

建库后进行实例进程检查
$ps -ef | grep ora_ | grep -v grep

查看监听状态
$lsnrctl status

登录查看实例状态
$sqlplus / as sysdba
SQL> select status from v$instance;
如显示
STATUS
------------
OPEN
则表示实例是启动状态

查看数据库编码
SQL> select userenv('language') from dual;
查看数据库版本
SQL> select * from v$version;


sqlplus / as sysdba
startup
shutdown immediate

lsnrctl status
lsnrctl start
lsnrctl stop