CentOS 6.5 安装 Oracle 11gR2 及自动启动配置
提示:以下操作需使用 root 用户权限执行。
安装必要的依赖软件包。
核心策略是利用 Oracle YUM 仓库,通过 yum 命令批量安装依赖项,从而省去手动逐一安装的繁琐过程。
配置 YUM 仓库以获取 Oracle 相关的依赖包。
请注意,此处提供的是适用于 CentOS 6.X 系列的 Oracle 依赖仓库配置,其他 Linux 版本可能存在差异。
导入 GPG 密钥以确保软件包来源可信。
wget https://public-yum.oracle.com/RPM-GPG-KEY-oracle-ol6 -O /etc/pki/rpm-gpg/RPM-GPG-KEY-oracle --no-check-certificate
执行安装 Oracle 所需的所有依赖包。
yum install oracle-rdbms-server-11gR2-preinstall
配置主机名(hostname)。
编辑 /etc/sysconfig/network 文件,将 HOSTNAME 字段修改为期望的主机名。
vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=oracle.buzheng.org
打开 /etc/hosts 文件,添加本机 IP 地址与主机名的映射关系。
vi /etc/hosts
192.168.1.15 oracle.buzheng.org oracle
Oracle 用户相关设置。
在安装完 Oracle 依赖包后,系统会自动创建 oracle 用户及相关用户组,无需手动新建。
更改 oracle 用户的登录密码。
[root@oracle ~]# passwd oracle
更改用户 oracle 的密码 。
新的 密码:
重新输入新的 密码:
passwd: 所有的身份验证令牌已经成功更新。
调整系统资源限制参数。
在 /etc/security/limits.d/90-nproc.conf 文件末尾追加以下内容。
[root@oracle ~]# vi /etc/security/limits.d/90-nproc.conf
# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.
* soft nproc 1024
root soft nproc unlimited
* - nproc 16384
将 SELinux 安全策略调整为 permissive(宽容)模式。
修改 /etc/selinux/config 配置文件中的 SELINUX 选项。
[root@oracle ~]# vi /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=permissive
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
重启服务器使上述系统级更改生效。
[root@oracle]# reboot
建立 Oracle 安装目录结构并分配相应权限。
[root@oracle]# mkdir -p /u01/app/oracle/product/11.2.0/dbhome_1
[root@oracle]# chown -R oracle:oinstall /u01
[root@oracle]# chmod -R 775 /u01
授予 oracle 用户访问 X Server 的权限以支持图形化安装。
[root@oracle]# xhost + # 要在主机上运行,不能是远程 shell
提示:以下操作需切换至 oracle 用户执行。
配置 Oracle 运行所需的环境变量。
切换到 oracle 用户身份,编辑 .bash_profile 文件,在其中加入环境变量配置代码。
[root@oracle]# su oracle
[oracle@oracle]# vi .bash_profile
# Oracle Settings
TMP=/tmp; export TMP
TMPDIR=$TMP; export TMPDIR
ORACLE_HOSTNAME=oracle.buzheng.org; export ORACLE_HOSTNAME
ORACLE_UNQNAME=orcl; export ORACLE_UNQNAME
ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1; export ORACLE_HOME
ORACLE_SID=orcl; export ORACLE_SID
PATH=/usr/sbin:$PATH; export PATH
PATH=$ORACLE_HOME/bin:$PATH; export PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib; export CLASSPATH export PATH
下载 Oracle 安装包并解压后进行安装。
获取 Oracle 安装介质。
访问 Oracle 官方下载页面 http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html ,下载以下两个文件至 /home/oracle 目录:
linux.x64_11gR2_database_1of2.zip
linux.x64_11gR2_database_2of2.zip
解压下载的压缩包并启动安装程序。
unzip linux.x64_11gR2_database_1of2.zip
unzip linux.x64_11gR2_database_2of2.zip
cd database
./runInstaller
若系统语言为中文,安装界面可能出现乱码,建议先将环境变量设置为英文后再进行安装。
export LANG=en_US
./runInstaller
由于缺乏截图,主要安装步骤简述如下:
- Create and configure a database
- Server Class
- Single instance database installation
- Advanced install
- Language: English
- Enterprise Edition
- database type: General Purpose / Transaction Processing
- Memory: Enable Automatic Memory Management
- Character sets: Use Unicode(AL32UTF8)
图形界面安装结束时,会提示需要使用 ROOT 用户执行以下两个脚本以完成最后配置。
[root@oracle ~]# /u01/app/oraInventory/orainstRoot.sh
Changing permissions of /u01/app/oraInventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.
Changing groupname of /u01/app/oraInventory to oinstall.
The execution of the script is complete.
[root@oracle ~]# /u01/app/oracle/product/11.2.0/dbhome_1/root.sh
Running Oracle 11g root.sh script...
The following environment variables are set as:
ORACLE_OWNER= oracle
ORACLE_HOME= /u01/app/oracle/product/11.2.0/dbhome_1
Enter the full pathname of the local bin directory: [/usr/local/bin]:
Copying dbhome to /usr/local/bin ...
Copying oraenv to /usr/local/bin ...
Copying coraenv to /usr/local/bin ...
Creating /etc/oratab file...
Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root.sh script.
Now product-specific root actions will be performed.
Finished product-specific root actions.
常见问题排查。
1. 当环境变量中的 ORACLE_SID 与实际安装配置不一致时,会导致 startup 命令执行失败,错误信息如下:
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initDB11G.ora'
2. 若远程客户端连接时报错 ora-12514(监听程序当前无法识别连接描述符中请求的服务),则需配置 listener.ora 文件,添加相应节点。
SID_LIST_LISTENER =
(SID_LIST=
(SID_DESC =
(SID_NAME = orcl)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
)
)
至此,Oracle 安装已完成,可通过访问 Web 管理界面进行验证。后续步骤同样关键,请继续阅读。
提示:以下操作需使用 root 用户权限执行。
配置防火墙规则,开放数据库侦听端口。
将 1521 端口(即配置的 Oracle 侦听端口)加入防火墙允许列表,以便远程用户能正常访问 Oracle 服务。
iptables -I INPUT 4 -m state --state NEW -p tcp --dport 1521 -j ACCEPT
service iptables save
service iptables reload
设置 Oracle 服务开机自动启动。
虽然可以通过命令手动启动或停止数据库,但系统重启后不会自动拉起 Oracle 服务,这带来不便。下文记录如何将 Oracle 注册为系统服务以实现开机自启。
修改 /etc/oratab 配置文件。
修改 /etc/oratab 文件最后一行的最后一个字符,将其由 N 改为 Y。此举旨在让 dbstart 命令能在系统启动时自动运行,配置示例如下:
[root@oracle ~]# vi /etc/oratab
#
# This file is used by ORACLE utilities. It is created by root.sh
# and updated by the Database Configuration Assistant when creating
# a database.
# A colon, ':', is used as the field terminator. A new line terminates
# the entry. Lines beginning with a pound sign, '#', are comments.
#
# Entries are of the form:
# $ORACLE_SID:$ORACLE_HOME::
#
# The first and second fields are the system identifier and home
# directory of the database respectively. The third filed indicates
# to the dbstart utility that the database should , "Y", or should not,
# "N", be brought up at system boot time.
#
# Multiple entries with the same $ORACLE_SID are not allowed.
#
#
orcl:/u01/app/oracle/product/11.2.0/dbhome_1:Y
创建 /etc/init.d/oracle 初始化脚本。
在 /etc/init.d/ 目录下创建名为 oracle 的文件,作为 Oracle 自启动脚本,内容如下:
#!/bin/sh
# chkconfig: 345 61 61
# description: Oracle 11g R2 AutoRun Servimces
# /etc/init.d/oracle
#
# Run-level Startup script for the Oracle Instance, Listener, and
# Web Interface
ORACLE_HOME="/u01/app/oracle/product/11.2.0/dbhome_1"
ORA_OWNR="oracle"
# if the executables do not exist -- display error
if [ ! -f "$ORACLE_HOME/bin/dbstart" ]
then
echo "Oracle startup: cannot start"
exit 1
fi
# parameter: start, stop, restart
case "$1" in
start)
# Oracle listener and instance startup
su $ORA_OWNR -s /bin/bash $ORACLE_HOME/bin/dbstart $ORACLE_HOME
echo "Oracle Start Succesful!OK."
;;
stop)
# Oracle listener and instance shutdown
su $ORA_OWNR -s /bin/bash $ORACLE_HOME/bin/dbshut $ORACLE_HOME
echo "Oracle Stop Succesful!OK."
;;
restart)
$0 stop
$0 start
;;
*)
echo $"Usage: `basename $0` {start|stop|restart}"
exit 1
esac
exit 0
赋予该启动脚本执行权限,并建立相应的符号链接。
# chmod 750 /etc/init.d/oracle
# ln -s /etc/init.d/oracle /etc/rc1.d/K61oracle
# ln -s /etc/init.d/oracle /etc/rc3.d/S61oracle
脚本配置完成后,即可使用 service 命令来启动或停止 Oracle,此时 Oracle 已成为标准的系统服务。
service oracle start
service oracle stop
service oracle restart
将 Oracle 服务设置为开机自启动状态。
# chkconfig --add oracle
# chkconfig --level 345 oracle on
总结。
现在可以重启机器进行测试。以上即为全部内容,希望能为您的学习或工作提供帮助,如有疑问欢迎留言交流。