CentOS 6.5 Oracle 11g 开机自启动配置详解
CentOS 6.5 环境下 Oracle 数据库开机自启动的环境配置详解
测试环境:CentOS 6.5 操作系统搭配 Oracle 11g 数据库
配置自启动前遇到的问题
在虚拟机中运行的 Oracle 环境,每次重启系统后,使用 PL/SQL Developer 客户端连接时,首先会收到如下错误提示:
无 TNS 监听程序
解决该问题的方法是切换至系统 oracle 用户并执行 lsnrctl start 命令。但在执行前,由于 ORACLE_HOME 环境变量尚未生效,需先使环境变量文件生效,具体步骤如下:
[oracle@localhost ~]$ source .bash_profile
[oracle@localhost ~]$ echo $ORACLE_HOME
/home/oracle/app/oracle/product/11.2.0/dbhome_1
[oracle@localhost ~]$ lsnrctl start
启动完成后,再次尝试连接,又出现新的报错:

Oracle 数据库实例未启动。启动步骤如下:
[oracle@localhost ~]$ sqlplus /nolog
SQL*Plus: Release 11.2.0.1.0 Production on Wed Oct 19 14:29:10 2026
Copyright (c) 1982, 2009, Oracle. All rights reserved.
SQL> conn / as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 776646656 bytes
Fixed Size 2217384 bytes
Variable Size 490736216 bytes
Database Buffers 281018368 bytes
Redo Buffers 2674688 bytes
Database mounted.
Database opened.
配置开机自启动
将上述手动操作过程全部配置为开机自动执行。
确保环境变量生效
可能是因为通过终端 su 切换至 oracle 用户而非桌面登录,导致 .bash_profile 文件未被读取。将文件内容写入 .bashrc 文件后,重启即可生效。
TNS 监听与 Oracle 服务自启动配置
编辑 /etc/oratab 文件,将最后一行末尾的 N 修改为 Y
# 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:/home/oracle/app/product/11.2.0/dbhome_1:Y
注意路径可能因安装位置不同而有所差异
编辑 /etc/rc.local 文件,在末尾增加以下两行代码:
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
service smb restart
su - oracle -c 'lsnrctl start'
su - oracle -c 'dbstart'
su - oracle -c 'emctl start dbconsole'
dbstart 是数据库自带的启动脚本,只需将其加入 rc.local 以实现开机调用。但还需对 dbstart 进行微调,修改其中的 ORACLE_HOME_LISTNER 变量,使其指向 $ORACLE_HOME:
# First argument is used to bring up OracleNet Listener
ORACLE_HOME_LISTNER=$ORACLE_HOME
重启虚拟机后,PL/SQL Developer 可直接成功连接。
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!