Oracle在$ORACLE_HOME/bin下提供许多对数据库进行操作的脚本,其中dbstart和dbshut可分别用来启动和关闭数据库。注意,这两个脚本已包含监听器的启动或关闭,但并未对EM进行相关的操作。使用如下命令:
/oracle/product/11.2.0/db_1/bin/dbstart /oracle/product/11.2.0/db_1 #启动数据库实例(包含监听器)
/oracle/product/11.2.0/db_1/bin/dbshut /oracle/product/11.2.0/db_1 #关闭数据库实例(包括监听器)
以上命令要成功启动数据库实例还得打开Oracle设置的一个关卡:vi /etc/oratab,修改行:
orcl:/oracle/product/11.2.0/db_1:Y #默认为orcl:/oracle/product/11.2.0/db_1:N
这时候用命令启动会报ORACLE_HOME_LISTNER没有设置
[oracle@primary bin]$ /oracle/product/11.2.0/db_1/bin/dbstart /oracle/product/11.2.0/db_1
ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener
修改dbstart和dbshut
dbstart修改前
# First argument is used to bring up Oracle Net Listener
ORACLE_HOME_LISTNER=$1
if [ ! $ORACLE_HOME_LISTNER ] ; thenecho "ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener"echo "Usage: $0 ORACLE_HOME"
elseLOG=$ORACLE_HOME_LISTNER/listener.log
dbstart修改后
# First argument is used to bring up Oracle Net Listener
ORACLE_HOME_LISTNER=/u01/app/oracle/product/11.2.0/db_1 // --/u01/app/oracle/product/11.2.0/db_1为$ORACLE_HOME
if [ ! $ORACLE_HOME_LISTNER ] ; thenecho "ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener"echo "Usage: $0 ORACLE_HOME"
elseLOG=$ORACLE_HOME_LISTNER/listener.log
同理dbshut也做相应修改
在启动了Linux系统之后,转到 /etc/init.d 目录下;
[root@oracle ~]# cd /etc/init.d
使用 vi 命令,新建一个以 oracle 命名的文件(并将以下代码复制至文件中)
[root@oracle init.d]# vi oracle#!/bin/sh
# chkconfig: 345 61 61
# description: Oracle 11g AutoRun Services
# /etc/init.d/oracle
#
# Run-level Startup script for the Oracle Instance, Listener, and
# Web Interfaceexport ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export ORACLE_SID=ddhldata
export PATH=$ORACLE_HOME/bin:$PATHORA_OWNR="oracle"# if the executables do not exist -- display errorif [ ! -f $ORACLE_HOME/bin/dbstart -o ! -d $ORACLE_HOME ]
thenecho "Oracle startup: cannot start"exit 1
fi# depending on parameter -- startup, shutdown, restart
# of the instance and listener or usage displaycase "$1" instart)# Oracle listener and instance startupsu $ORA_OWNR -lc $ORACLE_HOME/bin/dbstartecho "Oracle Start Succesful!OK.";;stop)# Oracle listener and instance shutdownsu $ORA_OWNR -lc $ORACLE_HOME/bin/dbshutecho "Oracle Stop Succesful!OK.";;reload|restart)$0 stop$0 start;;*)echo $"Usage: `basename $0` {start|stop|reload|reload}"exit 1
esac
exit 0
在编辑完成之后,使用 :x 命令保存此文件。
赋予执行权限
[root@oracle init.d]# chmod 750 /etc/init.d/oracle
做一个链接:
[root@oracle init.d]# ln -s /etc/init.d/oracle /etc/rc1.d/K61oracle[root@oracle init.d]# ln -s /etc/init.d/oracle /etc/rc3.d/S61oracle
执行以下命令:
[root@oracle init.d]# chkconfig --level 345 oracle on[root@oracle init.d]# chkconfig --add oracle //添加到服务里