邹洪

【工作】Centos下静默(命令行)方式安装Oracle 11g
【准备环境】一般来说,对于生成环境运行的linux系统,都不会安装图形界面,所以如果想要在没有图形界面的Linux...
扫描右侧二维码阅读全文
17
2019/06

【工作】Centos下静默(命令行)方式安装Oracle 11g

【准备环境】

一般来说,对于生成环境运行的linux系统,都不会安装图形界面,所以如果想要在没有图形界面的Linux上面安装Oracle,我们需要使用Linux的静默安装方式,以下为所需资源:

硬件需求:
物理内存不少于1G
硬盘空间不少于5G
swap分区空间不少于2G

软件需求:
OS:CentOS release 6.8
Oracle:11gR2

【安装步骤】

--------------------------------------以下命令使用root用户操作--------------------------------------

1. 下载地址:

# wget http://v.yingsun.net/cobra/download/linux.x64_11gR2_database_1of2.zip
# wget http://v.yingsun.net/cobra/download/linux.x64_11gR2_database_2of2.zip

注意: root用户无法用来安装oracle,需要用root用户创建一个新的用户要安装oracle。

2.在安装Oracle之前,用命令检查必需的RPM软件包有没有安装,检查的命令如下:

# rpm -q binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel gcc gcc-c++ glibc glibc-common glibc-devel glibc-headers kernel-headers ksh libaio libaio-devel libgcc libgomp libstdc++ libstdc++-devel make numactl-devel sysstat unixODBC unixODBC-devel

上面哪个包显示XXX is not installed,就使用下面的命令安装必要的RPM包:
#  yum install -y XXX

或者你如果嫌麻烦,可以直接执行如下命令:

#  yum install -y binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel gcc gcc-c++ glibc glibc-common glibc-devel glibc-headers kernel-headers ksh libaio libaio-devel libgcc libgomp libstdc++ libstdc++-devel make numactl-devel sysstat unixODBC unixODBC-devel

3、创建用户组及用户,设置oracle密码

# groupadd oinstall && groupadd dba
# useradd -g oinstall -G dba oracle

4.修改hosts文件

# vi /etc/hosts
在 127.0.0.1 行后面 添加你的主机名称(例如我的主机名为oracle)
在 ::1 行后面 添加你的主机名称(例如我的主机名为oracle)

5.设置内核参数

# vim /etc/sysctl.conf

在打开的文件底部添加下面内容

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

6.设置PAM资源限制

# vim /etc/security/limits.conf

在打开的文件底部添加下面内容

oracle soft nproc 10240
oracle hard nproc 65535
oracle soft nofile 10240
oracle hard nofile 65536
oracle soft stack 10240

7.创建oracle11g安装目录

# mkdir -p /home/oracle/oracle_11g/app/oracle/product/11.2.0/dbhome_1/
# chown -R oracle:oinstall /home/oracle/oracle_11g/app/
# chmod -R 775 /home/oracle/oracle_11g/app/
# mkdir -p /home/oracle/oracle_11g/oraInventory/
# chown -R oracle:oinstall /home/oracle/oracle_11g/oraInventory/
# chmod -R 775 /home/oracle/oracle_11g/oraInventory/

8.修改用户环境变量

# vim /home/oracle/.bash_profile

在打开的文件中添加下面内容

umask 022
export ORACLE_BASE=/home/oracle/oracle_11g/app
export ORACLE_HOME=$ORACLE_BASE/oracle/product/11.2.0/dbhome_1
export ORACLE_SID=orcl
export PATH=$PATH:HOME/bin:$ORACLE_HOME/bin
export ORACLE_HOME_LISTENER
export ORACLE_UNQNAME=$ORACLE_SID

注意:ORACLE_SID=orcl 这里是用户自己定义的数据库名称,后面配置需要用到,设置后就不能再改。

# source /home/oracle/.bash_profile

# vim /etc/pam.d/login

在打开的文件中添加下面内容(root用户)

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

9.解压oracle软件

# cd /home/oracle/oracle_11g/app
# unzip linux.x64_11gR2_database_1of2.zip linux.x64_11gR2_database_2of2.zip
# chown -R oracle:oinstall /home/oracle/oracle_11g/app/database

--------------------------------------以下命令使用oracle用户操作--------------------------------------

10.备份应答文件

# su - oracle
$ cd /home/oracle/oracle_11g/app/database/response
$ mkdir rsp_bak
$ ls
dbca.rsp db_install.rsp netca.rsp rsp_bak
$ cp *.rsp ./rsp_bak/

11.删除应答文件中的以#开头的注释行和空行

$ sed -i 's/^#.*$//g' *.rsp && sed -i '/^$/d' *.rsp

12.配置db_install.rsp

# echo > db_install.rsp

将以下配置添加到db_install.rsp文件中(下面的注释是对其上面参数的解释,拷贝时候一定要去掉里面的汉字注释,否则可能无法正常安装):

oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0

#默认即可
oracle.install.option=INSTALL_DB_SWONLY

#安装类型

ORACLE_HOSTNAME=oracle

#主机名称(hostname查询,这里要注意,主机名要在 /etc/hosts 文件中配置好ip对应关系,否则安装会报错)

UNIX_GROUP_NAME=oinstall

#安装组

INVENTORY_LOCATION=/home/oracle/oracle_11g/oraInventory

#INVENTORY目录位置,需填写成自己创建的目录位置

SELECTED_LANGUAGES=en,zh_CN

#选择支持语言

ORACLE_HOME=/home/oracle/oracle_11g/app/oracle/product/11.2.0/dbhome_1

#数据库目录地址

ORACLE_BASE=/home/oracle/oracle_11g/app

#BASE目录地址

oracle.install.db.InstallEdition=EE

#指定oracle版本

oracle.install.db.isCustomInstall=false

#是否自定义安装,false表示使用默认组件

oracle.install.db.customComponents=oracle.server:11.2.0.1.0,oracle.sysman.ccr:10.2.7.0.0,oracle.xdk:11.2.0.1.0,oracle.rdbms.oci:11.2.0.1.0,oracle.network:11.2.0.1.0,oracle.network.listener:11.2.0.1.0,oracle.rdbms:11.2.0.1.0,oracle.options:11.2.0.1.0,oracle.rdbms.partitioning:11.2.0.1.0,oracle.oraolap:11.2.0.1.0,oracle.rdbms.dm:11.2.0.1.0,oracle.rdbms.dv:11.2.0.1.0,orcle.rdbms.lbac:11.2.0.1.0,oracle.rdbms.rat:11.2.0.1.0

oracle.install.db.DBA_GROUP=dba

#dba用户组

oracle.install.db.OPER_GROUP=oinstall 、

#oper用户组

oracle.install.db.CLUSTER_NODES=

oracle.install.db.config.starterdb.type=GENERAL_PURPOSE

#数据库类型

oracle.install.db.config.starterdb.globalDBName=orcl

#globalDBName(这里要和第8步配置的sid一致)

oracle.install.db.config.starterdb.SID=orcl

#SID(这里要和第8步配置的sid一致)

oracle.install.db.config.starterdb.characterSet=AL32UTF8

#使用的编码格式

oracle.install.db.config.starterdb.memoryOption=true

oracle.install.db.config.starterdb.memoryLimit=1024

#自动管理的内存大小(M)

oracle.install.db.config.starterdb.installExampleSchemas=false

oracle.install.db.config.starterdb.enableSecuritySettings=true

oracle.install.db.config.starterdb.password.ALL=123456

#设定所有数据库用户使用同一个密码

oracle.install.db.config.starterdb.password.SYS=

oracle.install.db.config.starterdb.password.SYSTEM=

oracle.install.db.config.starterdb.password.SYSMAN=

oracle.install.db.config.starterdb.password.DBSNMP=

oracle.install.db.config.starterdb.control=DB_CONTROL

oracle.install.db.config.starterdb.gridcontrol.gridControlServiceURL=

oracle.install.db.config.starterdb.dbcontrol.enableEmailNotification=false

oracle.install.db.config.starterdb.dbcontrol.emailAddress=

oracle.install.db.config.starterdb.dbcontrol.SMTPServer=

oracle.install.db.config.starterdb.automatedBackup.enable=false

oracle.install.db.config.starterdb.automatedBackup.osuid=

oracle.install.db.config.starterdb.automatedBackup.ospwd=

oracle.install.db.config.starterdb.storageType=

oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=

oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=

oracle.install.db.config.asm.diskGroup=

oracle.install.db.config.asm.ASMSNMPPassword=

MYORACLESUPPORT_USERNAME=

MYORACLESUPPORT_PASSWORD=

SECURITY_UPDATES_VIA_MYORACLESUPPORT=

DECLINE_SECURITY_UPDATES=true

#设置安全更新(貌似是有bug,这个一定要选true,否则会无限提醒邮件地址有问题,终止安装。PS:不管地址对不对)

PROXY_HOST=

PROXY_PORT=

PROXY_USER=

PROXY_PWD=

$ cd /home/oracle/oracle_11g/app/database
$ ./runInstaller -silent -force -noconfig -responseFile /home/oracle/oracle_11g/app/database/response/db_install.rsp

控制台直到出现以下提示则表示安装完成:

20170807163849

备注:[WARNING] 是需要安装一些i386/i686 的包。查看log安装即可

--------------------------------------以下命令使用root用户操作--------------------------------------

13.运行orainstRoot.sh和root.sh

(1)若本机第一次安装oracle软件, 则执行orainstRoot.sh来建立oraInst.loc文件和修改权限:
$ su - root
# cd /home/oracle/oracle_11g/oraInventory
# ./orainstRoot.sh

Changing permissions of /home/oracle/oracle_11g/oraInventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.

Changing groupname of /home/oracle/oracle_11g/oraInventory to oinstall.
The execution of the script is complete.

脚本执行后主要进行的操作:
更改权限/home/oracle/oracle_11g/oraInventory.
添加组的读取和写入权限。
删除全局的读取, 写入和执行权限。
更改组名/home/oracle/oracle_11g/oraInventory 到 oinstall.

(2)执行$ORACLE_HOME下的root.sh来建立oratab,dbhome,oraenv,coraenv文件, 如果提示则一直回车:

# cd /home/oracle/oracle_11g/app/oracle/product/11.2.0/dbhome_1
# ./root.sh
Check /home/oracle/oracle_11g/app/oracle/product/11.2.0/dbhome_1/install/root_m22p135_2017-08-07_16-39-28.log for the output of root script

14.添加oracle环境变量

# vim /home/oracle/.bash_profile

export TNS_ADMIN=$ORACLE_HOME/network/admin
export PATH=.:${PATH}:$HOME/bin:$ORACLE_HOME/bin
export PATH=${PATH}:/usr/bin:/bin:/usr/bin/X11:/usr/local/bin
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$ORACLE_HOME/lib
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$ORACLE_HOME/oracm/lib
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/lib:/usr/lib:/usr/local/lib
export CLASSPATH=${CLASSPATH}:$ORACLE_HOME/JRE
export CLASSPATH=${CLASSPATH}:$ORACLE_HOME/JRE/lib
export CLASSPATH=${CLASSPATH}:$ORACLE_HOME/jlib
export CLASSPATH=${CLASSPATH}:$ORACLE_HOME/rdbms/jlib
export CLASSPATH=${CLASSPATH}:$ORACLE_HOME/network/jlib
export LIBPATH=${CLASSPATH}:$ORACLE_HOME/lib:$ORACLE_HOME/ctx/lib
export ORACLE_OWNER=oracle
export SPFILE_PATH=$ORACLE_HOME/dbs
export ORA_NLS10=$ORACLE_HOME/nls/data

$ source /home/oracle/.bash_profile

15.静默配置监听

$ $ORACLE_HOME/bin/netca /silent /responseFile /home/oracle/oracle_11g/app/database/response/netca.rsp

Parsing command line arguments:
Parameter "silent" = true
Parameter "responsefile" = /home/oracle/oracle_11g/app/database/response/netca.rsp
Done parsing command line arguments.
Oracle Net Services Configuration:
Profile configuration complete.
Oracle Net Listener Startup:
Running Listener Control: 
/home/oracle/oracle_11g/app/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

16.静默安装数据库

$ echo> /home/oracle/oracle_11g/app/database/response/dbca.rsp

$ vim /home/oracle/oracle_11g/app/database/response/dbca.rsp  #添加如下配置

[GENERAL]
RESPONSEFILE_VERSION = "11.2.0"
OPERATION_TYPE = "createDatabase"
[CREATEDATABASE]
GDBNAME = "orcl"
SID = "orcl"
TEMPLATENAME = "General_Purpose.dbc"
CHARACTERSET="AL32UTF8"
NATIONALCHARACTERSET="UTF8"
SYSPASSWORD="123456"
SYSTEMPASSWORD="123456"

$ $ORACLE_HOME/bin/dbca -silent -responseFile /home/oracle/oracle_11g/app/database/response/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 "/home/oracle/oracle_11g/app/cfgtoollogs/dbca/orcl/orcl.log" for further details.

17.测试数据库

(1)、启动数据库
$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Mon Aug 7 17:09:50 2017
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> start

SP2-1506: START, @ or @@ command has no arguments

注:可以使用show parameter;或者select table_name from dba_tables命令看看是否运行正常

(2)、监听检查

$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 07-AUG-2017 17:12:00

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                07-AUG-2017 17:01:30
Uptime                    0 days 0 hr. 10 min. 29 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /home/oracle/oracle_11g/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Listener Log File         /home/oracle/oracle_11g/app/diag/tnslsnr/m22p135/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=m22p135)(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

启动监听:lsnrctl start
查看监听:lsnrctl status
停止监听:lsnrctl stop

实例应该被动态注册到监听程序了. 到此oracle安装建库完毕!,在oracle用户下使用sqlplus登录数据库查看数据库是否安装成功!

$ sqlplus / as sysdba

Last modification:November 7th, 2019 at 03:28 am
如果觉得我的文章对你有用,请随意赞赏

Leave a Comment