CentOS下使用OTK脚本安装Oracle数据库详解
建议采用OTK脚本进行Oracle的安装操作,此举能显著提升安装成功率。
Description
oraToolKit is the Swiss Army Knife for Oracle. Standards and well designed tools help DBA's mastering Oracle 10g / 11g throughout the whole lifecycle. OTK runs on Linux, zLinux, Solaris, AIX, HP-UX and other UNIX based systems.
来自
一、安装前的系统约束条件 1. 内存需求
系统最小需具备1GB内存,推荐配置为2GB或更高。
2. Swap交换空间设置
当物理内存介于1GB至2GB之间时,Swap大小应设定为物理内存的1.5倍。
若物理内存处于2GB到16GB区间,Swap大小应与物理内存保持一致。
对于超过16GB物理内存的系统,Swap固定设置为16GB。
3. 共享内存/dev/shm要求
其容量必须大于每个Oracle实例中MEMORY_MAX_TARGET与MEMORY_TARGET参数之和。
4. /tmp临时目录空间
需预留至少1GB的可用空间。
5. 硬盘存储需求
用于存放Oracle软件及数据文件的分区,容量不得少于10GB。
6. 操作系统版本
本指南基于CentOS 6.5 64位系统,基础服务器(Basic Server)版本。
二、具体安装流程 1. 准备Oracle安装包
需下载以下三个文件: linux.x64_11gR2_database_1of2.zip linux.x64_11gR2_database_2of2.zip oratoolkit-1.0.2.1.5-1.noarch.rpm 将上述文件统一放置于/media/oracle目录下。
2. 部署OTK工具
首先以root用户身份登录系统。
将oratoolkit-1.0.2.1.5-1.noarch.rpm安装包移动至Yum本地源目录/Media/Packages中。
进入Packages目录后执行安装指令。
# yum -y install oratoolkit*
3. 重置Oracle用户密码
OTK已自动创建oracle用户,接下来需为其设置密码。 # passwd oracle
4. 使用swReqCheck检查环境依赖
OTK内置智能环境依赖检查功能,可识别Linux系统中缺失的必要组件,例如缺少的软件包。
# /opt/oracle/otk/current/bin/installManager swReqCheck osSetup11gR2.cfg
..
..
..
20140419_010832: Info: Action swReqCheck of installManager ended with 44 WARNINGS
当前安装的CentOS 6.5 64bit Basic Server系统缺失较多包,检测结果显示存在44个警告(WARNINGS)。
其中包含43个缺失的安装包,以及1个可忽略的警告信息。
# 20140419_011022: Warning: Oracle software runs on CentOS however this combination is NOT supported by Oracle
为解决缺失包问题,可利用Shell脚本批量处理。OTK提供了必需安装包的清单文件。
#先拼装命令
REQ_FILE_DIR="/opt/oracle/otk/current/conf/installManager/requirement"
REQ_FILE_PATH="$REQ_FILE_DIR/ora11gR2-redhat-5-x86_64.pkg.lst"
YUM_COMMAND=$(echo "yum -y install")
YUM_COMMAND+=$(egrep -v "#" $REQ_FILE_PATH | grep 32-bit | awk '{ print " "$1".i[356]86" }')
YUM_COMMAND+=$(egrep -v "#" $REQ_FILE_PATH | grep 64-bit | awk '{ print " "$1".x86_64" }')
#用echo看看最终拼装的命令是什么样
echo $YUM_COMMAND
#执行命令
$YUM_COMMAND
#再次执行环境检查
/opt/oracle/otk/current/bin/installManager swReqCheck osSetup11gR2.cfg
重新执行检查结果:
# 20130521_170131: Info: Action swReqCheck of installManager with ONE WARNING
仅剩一个可忽略的警告,表明系统环境已满足Oracle安装要求。
5. 编译安装rlwrap以增强SQL*Plus功能
rlwrap is a wrapper that uses the GNU readline library to allow the editing of keyboard input for any other command. Input history is kept between invocations, separately for each command; history completion and search work as in bash and completion word lists can be specified on the command line.
来自
OTK集成了rlwrap工具。
该工具增强了SQL*Plus的命令历史记录保存及自动补全能力。
开始编译安装rlwrap。
# cd /opt/oracle/otk/current/tools/rlwrap/
# ./configure
# make
# make install
# rlwrap -v
版本号为rlwrap 0.30。
6. 调用OTK的installManager执行osSetup
On the one hand it does what is required from Oracle documentation and on the other hand it setups also the environment for OTK. The next bullet list shows a summary.
来自
# /opt/oracle/otk/current/bin/installManager osSetup osSetup11gR2.cfg
7. 迁移Oracle安装文件至资源目录
OTK默认读取Oracle安装文件的目录路径为/var/opt/oracle/repository;
OTK的swInst实例安装命令将读取此目录下的内容:
# cd /media/oracle
# chown oracle:oinstall *
# mv linux.x64_11gR2_database_1of2.zip linux.x64_11gR2_database_2of2.zip /var/opt/oracle/repository/
8. 切换至Oracle用户并修改配置文件
# su - oracle
------------------------------------------------------
oraToolKit environment variables
------------------------------------------------------
Installation directory : /opt/oracle/otk
Release : 1.0.2.1.5
$RUN directory : /opt/oracle/otk/1.0/bin
$LOG_BASE directory : /var/opt/oracle/otk/1.0/log
------------------------------------------------------
# vi .profile.custom.interactive
重点修改文件中的SITE值。
9. 启动Oracle数据库安装
OTK通过swInst动作安装数据库,其工作原理如下:
The main purpose of swInst action is to execute OUI in silent mode in order to install the software. However, before it can be executed it is required to unzip the file containing the software. OTK starts here and takes care also about the extraction before launching runInstaller script.
来自
利用Shell脚本自动执行数据库安装过程:
#bash
# /opt/oracle/otk/1.0/conf/installManager 配置文件路径
cd $INSTALL_CONF
# 拷贝Oracle11gR2配置文件,Step1,2,3
cp sample/swInstEeSrv11gR2-Step[123]-linux-x86_64.cfg .
# swInst 引导安装
installManager swInst swInstEeSrv11gR2-Step1-linux-x86_64.cfg
installManager swInst swInstEeSrv11gR2-Step2-linux-x86_64.cfg
installManager swInst swInstEeSrv11gR2-Step3-linux-x86_64.cfg
等待片刻后,若输出如下信息,则表明安装成功。 ----------------------------------------------------------------------------------------------------
20140419_132032: Info: Executing libinstallManager.printInfoMsg function
Check in the logs if there are commands to be executed manually.
-Usually /opt/oracle/sesrv/11.1.0/db1/cfgtoollogs/configToolAllCommands contains such commands
-Usually /opt/oracle/sesrv/11.1.0/db1/root.sh with root privileges has to be executed in case appctl framework is not used.
-Usually /opt/oracle/sesrv/11.1.0/db1/install/changePerm.sh needs to be executed when other OS users requires Oracle libraries
----------------------------------------------------------------------------------------------------
20140419_132032: Info: Action swInst of installManager ended successfully
----------------------------------------------------------------------------------------------------
完成剩余配置步骤,需执行root.sh命令。安装最后阶段需手动运行剩余脚本:
# su -
# /opt/oracle/eesrv/11.2.0/db1/root.sh
# exit
10. 创建数据库实例
OTK使用dbSetup工具来创建数据库实例。
# cd $INSTALL_CONF
# ls -l dbSetup*.cfg
dbSetup-dev.cfg
dbSetup-prod.cfg
dbSetup-test.cfg
本次安装选用开发模式(dev),此外还支持测试模式(test)和生产模式(prod);
编辑dbSetup-dev.cfg配置文件,必须调整的配置项包括:
ORACLE_HOME的值:
$ORACLE_BASE/sesrv/11.1.0/db1
将其修改为:
$ORACLE_BASE/eesrv/11.2.0/db1
随后执行安装命令:
# installManager dbSetup dbSetup-dev.cfg
系统将开始安装数据库实例,耗时约十几分钟,最终显示如下输出:
----------------------------------------------------------------------------------------------------
20130419_013000: Info: Executing libmiscellaneous.getFooter function
20130419_013000: Info: Terminating installManager execution
20130419_013000: Info: Summary log file: /var/opt/oracle/otk/1.0/log-old/installManager/../installManager.log
20130419_013000: Info: Detailed log file: /var/opt/oracle/otk/1.0/log-old/installManager/dbsetup-20130522_012901.log
20130419_013000: Info: Action dbSetup of installManager ended successfully
----------------------------------------------------------------------------------------------------
Congratulations! 数据库现已可用。
11. 登录SQL*Plus界面
# su - oracle
------------------------------------------------------
Oracle database environment variables
------------------------------------------------------
$ORACLE_HOME : /opt/oracle/eesrv/11.2.0/db1
$ORACLE_SID : dev
$TNS_ADMIN : /opt/oracle/network
------------------------------------------------------
------------------------------------------------------
oraToolKit environment variables
------------------------------------------------------
Installation directory : /opt/oracle/otk
Release : 1.0.2.1.5
$RUN directory : /opt/oracle/otk/1.0/bin
$LOG_BASE directory : /var/opt/oracle/otk/1.0/log
------------------------------------------------------
# sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Sat Apr 19 11:27:47 2014
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>
查看数据库中存在的用户列表。
SQL>select username from dba_users;
USERNAME
------------------------------
SYSTEM
SYS
OTK
ORACLE_OCM
DBSNMP
DIP
OUTLN
EXFSYS
PERFSTAT
APPQOSSYS
HAPROBE
11 rows selected.
这证明SQL*Plus功能正常。
12. 使用CTL工具管理数据库
OTK提供了一个通用的Oracle数据库管理工具,用以替代Oracle原有的APPCTL框架。
$ ctl status all //查看当前状态
# ctl start all //启动数据库
$ ctl stop all //停止数据库