# Oracle 11g 基于CentOS7静默安装教程(无图形界面,远程安装)
## 一、安装前环境准备
#### 1、VMware Workstation 11 搭建 CentOS7虚拟机,CentOS7操作系统最小化安装,2G内存,20G磁盘空间,1核CPU,已配置好网络IP:192.168.206.135

#### 2、已下载Oracle 11g Linux安装文件:linux.x64\_11gR2\_database\_1of2.zip和linux.x64\_11gR2\_database\_2of2.zip

#### 3、通过Xmanager Xftp上传到虚拟机/tmp目录中。

## 二、操作系统准备工作
#### 1、使用root用户登录操作系统
#### 2、yum 安装 unzip 软件,用来解压上传的Oracle安装文件。
> [root@CentOS \~\]\# **yum install unzip –y**
#### 3、解压Oracle 安装程序
> [root@CentOS \~\]\# **cd /tmp**
\[root@CentOS tmp\]\# **unzip linux.x64\_11gR2\_database\_1of2.zip && unzip linux.x64\_11gR2\_database\_2of2.zip**
等待解压完成后,会在/tmp目录下生产一个database文件夹,里面就Oracle 11g安装文件。

#### 4、Yum 安装vim软件,用于编辑配置文件(个人习惯,不安装vim,使用vi也可以)。
> [root@CentOS tmp\]\# **yum install vim -y**
#### 5、在/etc/hosts文件中添加主机名
> [root@CentOS tmp\]\# **vim /etc/hosts**
添加192.168.206.135 CentOS

#### 6、关闭selinux
> [root@CentOS tmp\]\# **vim /etc/selinux/config**
设置SELINUX=disabled

> [root@CentOS tmp\]\# **setenforce 0**
#### 7、关闭防火墙
> [root@CentOS tmp\]\# **service iptables stop**
\[root@CentOS \~\]\# **systemctl stop firewalld**
\[root@CentOS \~\]\# **systemctl disable firewalld**
#### 8、安装Oracle 11g依赖包
\[root@CentOS tmp\]\# **yum install yum install gcc make binutils gcc-c++ compat-libstdc++-33 elfutils-libelf-devel elfutils-libelf-devel-static ksh libaio libaio-devel numactl-devel sysstat unixODBC unixODBC-devel pcre-devel –y**
#### 9、添加安装用户和用户组
> [root@CentOS tmp]# groupadd oinstall
[root@CentOS tmp]# groupadd dba
[root@CentOS tmp]# useradd -g oinstall -G dba oracle
[root@CentOS tmp]# passwd oracle
[root@CentOS tmp]# id oracle
uid=1001(oracle) gid=1001(oinstall) 组=1001(oinstall),1002(dba)
#### 10、修改内核参数配置文件
> [root@CentOS ~]# vim /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
[root@CentOS ~]# sysctl –p
其中kernel.shmmax = 1073741824为本机物理内存(2G)的一半,单位为byte。
```
#### 11、修改用户的限制文件
>[root@CentOS ~]# 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
```
修改/etc/pam.d/login文件:
> [root@CentOS \~\]\# **vim /etc/pam.d/login**
添加以下内容:
```
session required /lib64/security/pam\_limits.so
session required pam\_limits.so
```
修改/etc/profile文件:
> [root@CentOS ~]# 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
```
#### 12、创建安装目录和设置文件权限
```
[root@CentOS ~]# mkdir -p /u01/app/oracle/product/11.2.0**
[root@CentOS ~]# mkdir u01/app/oracle/oradata**
[root@CentOS ~]# mkdir u01/app/oracle/inventory**
[root@CentOS ~]# mkdir u01/app/oracle/fast_recovery_area**
[root@CentOS ~]# chown -R oracle:oinstall /u01/app/oracle**
[root@CentOS ~]# chmod -R 775 /u01/app/oracle**
```
#### 13、设置oracle用户环境变量
```
[root@CentOS ~]# su - oracle
[oracle@CentOS ~]$ vim .bash_profile
```
添加如下内容:
```
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=$ORACLE_BASE/product/11.2.0
ORACLE_SID=orcl
PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_BASE ORACLE_HOME ORACLE_SID PATH
```
#### 14、编辑静默安装响应文件
> [oracle@CentOS \~\]\$ **cp -R /tmp/database/response/ .**
[oracle@CentOS \~\]\$ **cd response/**
[oracle@CentOS response\]\$ **vim db\_install.rsp**
需要设置的选项如下:
```
oracle.install.option=INSTALL\_DB\_SWONLY
ORACLE_HOSTNAME=CentOS
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/u01/app/oracle/inventory
SELECTED_LANGUAGES=en,zh\_CN
ORACLE_HOME=/u01/app/oracle/product/11.2.0
ORACLE_BASE=[[]{#OLE_LINK2 .anchor}]{#OLE_LINK1.anchor}/u01/app/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.DBA\_GROUP=dba
oracle.install.db.OPER\_GROUP=dba
DECLINE\_SECURITY\_UPDATES=true
```
## 三、根据响应文件静默安装Oracle 11g
> [oracle@CentOS response\]\$ **cd /tmp/database/**
\[oracle@CentOS database\]\$ **./runInstaller -silent –responseFile /home/oracle/response/db\_install.rsp –ignorePrereq**

开始Oracle在后台静默安装。安装过程中,如果提示\[WARNING\]不必理会,此时安装程序仍在后台进行,如果出现\[FATAL\],则安装程序已经停止了。
可以在以下位置找到本次安装会话的日志:
> /u01/app/oracle/inventory/logs/installActions2015-06-08\_04-00-25PM.log
可以切换终端执行top命令查看后台进程一直是在安装的,/u01目录也在不断增大,
当出现以下提示时,代表安装成功:

按照要求执行脚本。
打开终端,以root身份登录,执行脚本:
> [root@CentOS \~\]\# **sh /u01/app/oracle/inventory/orainstRoot.sh**
\[root@CentOS \~\]\# **sh /u01/app/oracle/product/11.2.0/root.sh**

## 四、以静默方式配置监听
重新使用oracle用户登录
> [oracle@CentOS \~\]\$ **netca /silent /responsefile /home/oracle/response/netca.rsp**

成功运行后,在/u01/app/oracle/product/11.2.0/network/admin/中生成listener.ora和sqlnet.ora
通过netstat命令可以查看1521端口正在监听。
Yum安装netstat软件,软件包是在net-tools中。
\[root@CentOS \~\]\# **yum install net-tools**
\[root@CentOS \~\]\# **netstat -tnulp | grep 1521**

## 五、以静默方式建立新库,同时也建立一个对应的实例。
\[oracle@CentOS \~\]\$ **vim /home/oracle/response/dbca.rsp**
设置以下参数:
```
GDBNAME = "orcl"
SID = "orcl"
SYSPASSWORD = "oracle"
SYSTEMPASSWORD = "oracle"
SYSMANPASSWORD = "oracle"
DBSNMPPASSWORD = "oracle"
DATAFILEDESTINATION =/u01/app/oracle/oradata
RECOVERYAREADESTINATION=/u01/app/oracle/fast_recovery_area
CHARACTERSET = "ZHS16GBK"
TOTALMEMORY = "1638"
其中TOTALMEMORY = "1638" 为1638MB,物理内存2G\*80%。
```
进行静默配置:
> [oracle@CentOS \~\]\$ **dbca -silent -responseFile /home/oracle/response/dbca.rsp**

建库后进行实例进程检查:
> [oracle@CentOS \~\]\$ **ps -ef | grep ora\_ | grep -v grep**

查看监听状态:
> [oracle@CentOS \~\]\$ **lsnrctl status**

登录查看实例状态:
> [oracle@CentOS \~\]\$ **sqlplus / as sysdba**
**SQL> select status from v\$instance;

## 六、Oracle开机自启动设置
#### 1、修改/u01/app/oracle/product/11.2.0/bin/dbstart
> [oracle@CentOS \~\]\$ **vim /u01/app/oracle/product/11.2.0/bin/dbstart**
将ORACLE\_HOME\_LISTNER=\$1修改为ORACLE\_HOME\_LISTNER=\$ORACLE\_HOME
#### 2、修改/u01/app/oracle/product/11.2.0/bin/dbshut
> [oracle@CentOS \~\]\$ **vim /u01/app/oracle/product/11.2.0/bin/dbshut**
将ORACLE\_HOME\_LISTNER=\$1修改为ORACLE\_HOME\_LISTNER=\$ORACLE\_HOME
#### 3、修改/etc/oratab文件
> [oracle@CentOS \~\]\$ **vim /etc/oratab**
将orcl:/u01/app/oracle/product/11.2.0:N中最后的N改为Y,成为orcl:/u01/app/oracle/product/11.2.0:Y
#### 4、输入命令dbshut和dbstart测试
> [oracle@CentOS \~\]\$ **dbshut**

Oracle监听停止,进程消失。
> [oracle@CentOS \~\]\$ **dbstart**

Oracle监听启动,进程启动。
#### 5、切换到root账户建立自启动脚本
> [oracle@CentOS \~\]\$ **su - root**
> [root@CentOS \~\]\# **vim /etc/rc.d/init.d/oracle**
添加以下内容(有些值如ORACLE\_HOME和ORACLE\_USER等根据实际情况可以修改):
```
#!/bin/bash
# oracle: Start/Stop Oracle Database 11g R2
# chkconfig: 345 90 10
# description: The Oracle Database is an Object-Relational Database Management System.
#
. /etc/rc.d/init.d/functions
LOCKFILE=/var/lock/subsys/oracle
ORACLE_HOME=/u01/app/oracle/product/11.2.0
ORACLE_USER=oracle
case "$1" in
'start')
echo \$0 already running.
exit 1
fi
echo -n $"Starting Oracle Database:"
su - $ORACLE\_USER -c "$ORACLE_HOME/bin/lsnrctl start"
su - $ORACLE\_USER -c "$ORACLE_HOME/bin/dbstart$ORACLE_HOME"
su - $ORACLE\_USER -c "$ORACLE_HOME/bin/emctl start dbconsole"
touch $LOCKFILE
;;
'stop')
if [ ! -f $LOCKFILE ]; then
echo $0 already stopping.
exit 1
fi
echo -n $"Stopping Oracle Database:"
su - $ORACLE_USER -c "$ORACLE_HOME/bin/lsnrctl stop"
su - $ORACLE_USER -c "$ORACLE_HOME/bin/dbshut"
su - $ORACLE_USER -c "$ORACLE_HOME/bin/emctl stop dbconsole"
rm -rf $LOCKFILE
;;
'restart')
$0 stop
$0 start
;;
'status')
if [ -f $LOCKFILE ]; then
echo $0 started.
else
echo $0 stopped.
fi
;;
*)
echo "Usage: $0 [start|stop|status]"
exit 1
esac
exit 0
```
#### 6、修改/etc/init.d/oracle服务文件权限
> [root@CentOS init.d\]\# **chmod 755 /etc/init.d/oracle**
#### 7、设置为开机启动
> [root@CentOS \~\]\# **chkconfig oracle on**

#### 8、进行service oracle start/stop/restart测试

#### 9、Reboot重启查看Oracle监听和实例进程均能自动启动。

Oracle 11g基于CentOS7静默安装教程(无图形界面、远程安装)