一、安装依赖包及新建用户与目录
1、首先安装需求相关的环境
[root@oracle ~]#yum -y update && init 6
[root@oracle ~]#hostnamectl set-hostname oracle
[root@oracle ~]#yum -y install gcc gcc-c++ make binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel elfutils-libelf-devel-static glibc glibc-common glibc-devel ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel numactl-devel sysstat unixODBC unixODBC-devel kernel-headers pdksh pcre-devel readline* rlwrap
2、查询相关的包安装完整性
[root@oracle ~]#rpm -q 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
无提示:not install为好
2、建立相关的用户与组
[root@oracle ~]#groupadd oinstall
[root@oracle ~]#groupadd dba
[root@oracle ~]#useradd -g oinstall -G dba oracle
设置密码:
[root@oracle ~]#echo “oracle” | passwd --stdin oracle
验证:
[root@oracle ~]#id oracle
3、创建安装目录及权限
[root@oracle ~]#mkdir -p /data/u01/app/oracle/product/11.2.0/dbhome_1
[root@oracle ~]#mkdir /data/u01/app/oracle/{oradata,inventory,fast_recovery_area}
[root@oracle ~]#chown -R oracle:oinstall /data/u01/app/oracle
[root@oracle ~]#chmod -R 775 /data/u01/app/oracle
二、上传并解压安装包
[root@oracle ~]#yum -y install zip unzip
[root@oracle ~]#mkdir -p /data/u01/software && cd /data/u01/software/
上传数据库安装包到服务器
[root@oracle software]# ll /data/u01/software/
total 2295592
-rw-r--r-- 1 root root 1239269270 Feb 18 15:55 linux.x64_11gR2_database_1of2.zip
-rw-r--r-- 1 root root 1111416131 Feb 18 15:55 linux.x64_11gR2_database_2of2.zip
解压数据库安装包
[root@oracle software]#unzip linux.x64_11gR2_database_1of2.zip
[root@oracle software]#unzip linux.x64_11gR2_database_2of2.zip
[root@oracle software]# ll /data/u01/software/
total 2295592
-rw-r--r-- 1 root root 1239269270 Feb 18 15:55 linux.x64_11gR2_database_1of2.zip
-rw-r--r-- 1 root root 1111416131 Feb 18 15:55 linux.x64_11gR2_database_2of2.zip
drwxr-xr-x 8 root root 120 Aug 21 2009 database
三、修改配置文件
3.1修改/etc/hosts文件
[root@oracle software]#vim /etc/hosts
添加本机Ip地址与主机名称的对应关系
127.0.0.1 oracle localhost localhost.localdomain localhost4 localhost4.localdomain4
192.168.26.71 oracle
3.2修改/etc/sysctl.conf配置文件
[root@oracle software]#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@oracle software]#sysctl -p
3.3修改/etc/security/limits.conf配置文件达到修改用户限制
[root@oracle software]#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
3.4修改/etc/pam.d/login配置
[root@oracle software]#vim /etc/pam.d/login
在第八行下面添加如下内容后保存退出:
session required /lib64/security/pam_limits.so
session required pam_limits.so
3.5修改/etc/profile配置文件
[root@oracle software]#vim /etc/profile
在此文件23行下面增加如下内容:
if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi
使之生效:
[root@oracle software]#source /etc/profile
3.5配置oracle用户的环境变量
[root@oracle software]#su - oracle
[oracle@oracle ~]$vim ./.bash_profile
在PATH=$PATH:$HOME/.local/bin:$HOME/bin这行下面增加如下内容后保存退出:
export ORACLE_BASE=/data/u01/app/oracle
export ORACLE_HOME=/data/u01/app/oracle/product/11.2.0/dbhome_1
export ORACLE_SID=orcl
export ORACLE_UNQNAME=$ORACLE_SID
export PATH=$ORACLE_HOME/bin:$PATH
export NLS_LANG=american_america.AL32UTF8
alias sqlplus='rlwrap sqlplus'
alias rman='rlwrap rman'
[oracle@oracle ~]$source ./.bash_profile
3.6配置oracle安装应答文件
[oracle@oracle ~]$cp -R /data/u01/software/database/response/ .
[oracle@oracle ~]$cd response/
[oracle@oracle response]$ ll
total 76
-rw-r--r-- 1 oracle oinstall 44986 Feb 18 16:53 dbca.rsp
-rw-r--r-- 1 oracle oinstall 22708 Feb 18 16:03 db_install.rsp
-rwxr-xr-x 1 oracle oinstall 5740 Feb 18 15:58 netca.rsp
[oracle@oracle response]$vim db_install.rsp
以下只列出修改的内容
oracle.install.option=INSTALL_DB_SWONLY
ORACLE_HOSTNAME=oracle ##自己的主机名
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/data/u01/app/oracle/inventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOME=/data/u01/app/oracle/product/11.2.0/dbhome_1
ORACLE_BASE=/data/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.install.db.config.starterdb.password.ALL=oracle
修改完成按 esc 键退出编辑模式;输入 “:wq”退出并保存;
四、执行安装
4.1开始安装
[oracle@oracle response]$cd /data/u01/software/database/
[oracle@oracledatabase]$./runInstaller -silent -responseFile /home/oracle/response/db_install.rsp -ignorePrereq
最后出现success就说明安装成功
成功后千万不要着急,还在另一终端下以root身份即行两个脚本
[root@oracle ~]#/data/u01/app/oracle/inventory/orainstRoot.sh
[root@oracle ~]#/data/u01/app/oracle/product/11.2.0/dbhome_1/root.sh
然后再回车退出此时
[oracle@oracle database]$ sqlplus / as sysdba
SQLPLUS 链接成功;
五、静默创建实例
退出sqlplus登录后
[oracle@oracle database]$ vim /home/oracle/response/dbca.rsp
以下只列出修改的内容
GDBNAME = "orcl"
SID = "orcl"
SYSPASSWORD = "password" ##前面的 # 要删除,对应用户设置密码
SYSTEMPASSWORD = "password" ##前面的 # 要删除,对应用户设置密码
SYSMANPASSWORD = "password" ##前面的 # 要删除,对应用户设置密码
DBSNMPPASSWORD = "password" ##前面的 # 要删除,对应用户设置密码
DATAFILEDESTINATION =/data/u01/app/oracle/oradata
RECOVERYAREADESTINATION=/data/u01/app/oracle/fast_recovery_area
CHARACTERSET = "AL32UTF8" ##设置字符集
TOTALMEMORY = "8096"
[oracle@oracle ~]$ egrep -v "(^#|^$)" /home/oracle/response/dbca.rsp
[GENERAL]
RESPONSEFILE_VERSION = "11.2.0"
OPERATION_TYPE = "createDatabase"
[CREATEDATABASE]
GDBNAME = "orcl"
SID = "orcl"
TEMPLATENAME = "General_Purpose.dbc"
SYSPASSWORD = "password"
SYSTEMPASSWORD = "password"
SYSMANPASSWORD = "password"
DBSNMPPASSWORD = "password"
DATAFILEDESTINATION = "/data/u01/app/oracle/oradata"
RECOVERYAREADESTINATION = "/data/u01/app/oracle/fast_recover
y_area"CHARACTERSET = "AL32UTF8"
TOTALMEMORY = "8096"
[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"
[oracle@oracle database]$dbca -silent -responseFile /home/oracle/response/dbca.rsp
达到百分之百后就说明成功了,用下面的命令验证一下就可以:
[oracle@oracle database]$ env |grep ORACLE_UNQNAME
ORACLE_UNQNAME=orcl
登录查看实例状态:
[oracle@oracle ~]$ sqlplus / as sysdba
SQL> select status from v$instance;
STATUS
OPEN
六、设置oracle数据库随系统开机自启动
6.1修改/data/u01/app/oracle/product/11.2.0/dbhome_1/bin/dbstart
[oracle@oracle ~]$ vim /data/u01/app/oracle/product/11.2.0/dbhome_1/bin/dbstart
将ORACLE_HOME_LISTNER=$1修改为ORACLE_HOME_LISTNER=$ORACLE_HOME
6.2修改/data/u01/app/oracle/product/11.2.0/dbhome_1/bin/dbshut
[oracle@oracle ~]$vim /data/u01/app/oracle/product/11.2.0/dbhome_1/bin/dbshut
将ORACLE_HOME_LISTNER=$1修改为ORACLE_HOME_LISTNER=$ORACLE_HOME
6.3修改/etc/oratab文件
[oracle@oracle ~]$vim /etc/oratab
将orcl:/data/u01/app/oracle/product/11.2.0/dbhome_1:N中最后的N改为Y,成为orcl:/data/u01/app/oracle/product/11.2.0/dbhome_1:Y
6.4输入命令dbshut和dbstart测试
[oracle@oracle ~]$dbshut
Oracle监听停止,进程消失。
[oracle@oracle ~]$dbstart
Oracle监听启动,进程启动。
6.5.oracle服务重启后自启动
[root@oracle ~]#vim /etc/rc.d/rc.local
加入如下配置:
su oracle -lc "/data/u01/app/oracle/product/11.2.0/dbhome_1/bin/lsnrctl start"
su oracle -lc “/data/u01/app/oracle/product/11.2.0/dbhome_1/bin/dbstart”
保存退出
[root@oracle ~]#chmod +x /etc/rc.d/rc.local
重启系统,再次连接数据库,将正常连接上。
本文是学习了孙忠老师的《linux centos7下命令行静默安装oracle11GR2视频课程》后自己做的笔记,链接:https://edu.51cto.com/course/15530.html 受益非浅,在此表示感谢,执弟子礼!对照此文可以完成安装、配置、自启动等操作