方法一:
1、编写脚本
[root@localhost init.d]# pwd
/etc/init.d
[root@localhost init.d]# more oracle
#!/bin/bash
# Set ORA_HOME to be equivalent to the $ORACLE_HOME
# from which you wish to execute dbstart and dbshut
#
# set ORA_OWNER to the user id of the owner of the
# Oracle database in ORA_HOME
ORA_HOME=/opt/oracle/product/9.2.0.4
ORA_OWNER=oracle
if [ ! -f $ORA_HOME/bin/dbstart ]
then
echo "Not find dbstart,can not start Oracle "
exit
fi
case "$1" in
'start')
# Start the Oracle databses:
echo "Oracle Starting..."
su - $ORA_OWNER -c $ORA_HOME/bin/dbstart &
echo "Oracle started Succeed"
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start"
;;
'stop')
#Stop the Oracle database;
echo "Oracle Shutdowning ..."
su - $ORA_OWNER -c $ORA_HOME/bin/dbshut &
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop &"
;;
* ) echo $1;;
esac
[root@localhost init.d]#
2、设置权限
[root@localhost init.d]# chmod +x oracle
[root@localhost init.d]# ls -l oracle
-rwxr-xr-x 1 root root 731 Aug 12 09:45 oracle
3、建立链接到5启动级别
[root@localhost rc5.d]# ln -s /etc/init.d/oracle S90oracle
[root@localhost rc5.d]# ln -s /etc/init.d/oracle K01oracle
4、查看建立的链接情况
[root@localhost rc5.d]# ls -l *oracle*
lrwxrwxrwx 1 root root 18 Aug 12 09:51 K01oracle -> /etc/init.d/oracle
lrwxrwxrwx 1 root root 18 Aug 12 09:51 S90oracle -> /etc/init.d/oracle
5、修改/etc/oratab文件内容如下
[root@localhost ~]# more /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.
#
#
mydb:/opt/oracle/product/9.2.0.4:Y
6、init 6后检查,发现ORACLE已经启动
[root@localhost ~]# ps -ef|grep ora
oracle 6153 1 0 15:23 ? 00:00:00 ora_pmon_mydb
oracle 6155 1 0 15:23 ? 00:00:00 ora_dbw0_mydb
oracle 6157 1 0 15:23 ? 00:00:00 ora_lgwr_mydb
oracle 6159 1 0 15:23 ? 00:00:00 ora_ckpt_mydb
oracle 6161 1 0 15:23 ? 00:00:00 ora_smon_mydb
oracle 6163 1 0 15:23 ? 00:00:00 ora_reco_mydb
oracle 6165 1 0 15:23 ? 00:00:00 ora_s000_mydb
oracle 6167 1 0 15:23 ? 00:00:00 ora_d000_mydb
oracle 6172 1 0 15:24 ? 00:00:00 /opt/oracle/product/9.2.0.4/bin/tnslsnr LISTENER -inherit
root 7425 7384 0 15:24 pts/1 00:00:00 grep ora
方法二、
1、编写脚本,注意红色字体
[root@localhost init.d]# pwd
/etc/init.d
[root@localhost init.d]# more oracle
#!/bin/bash
# Set ORA_HOME to be equivalent to the $ORACLE_HOME
# from which you wish to execute dbstart and dbshut
#
# set ORA_OWNER to the user id of the owner of the
# Oracle database in ORA_HOME
ORA_HOME=/opt/oracle/product/9.2.0.4
ORA_OWNER=oracle
if [ ! -f $ORA_HOME/bin/dbstart ]
then
echo "Not find dbstart,can not start Oracle "
exit
fi
case "$1" in
'start')
# Start the Oracle databses:
echo "Oracle Starting..."
su - $ORA_OWNER -c $ORA_HOME/bin/dbstart &
echo "Oracle started Succeed"
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start"
;;
'stop')
#Stop the Oracle database;
echo "Oracle Shutdowning ..."
su - $ORA_OWNER -c $ORA_HOME/bin/dbshut &
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop &"
;;
* ) echo $1;;
esac
[root@localhost init.d]#
2、设置权限
[root@localhost init.d]# chmod +x oracle
[root@localhost init.d]# ls -l oracle
-rwxr-xr-x 1 root root 731 Aug 12 09:45 oracle
3、编辑如下文件,注意红色字体
[root@localhost etc]# vi 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
#start oracle.....
su - oracle<dbstart
lsnrctl start
EOF
[root@localhost rc.d]# pwd
/etc/rc.d
[root@localhost rc.d]# vi rc1.local --需要创建该文件
#Shutdown Oracle....
su - oracle<lnsrctl stop
dbshut
EOF
[root@localhost ~]# ln -s /etc/rc.d/rc1.local /etc/rc0.d/K01oracle
4、修改/etc/oratab文件内容如下
[root@localhost ~]# more /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.
#
#
mydb:/opt/oracle/product/9.2.0.4:Y
5、init 6后检查,发现ORACLE已经启动
[root@localhost ~]# ps -ef|grep ora
oracle 6153 1 0 15:23 ? 00:00:00 ora_pmon_mydb
oracle 6155 1 0 15:23 ? 00:00:00 ora_dbw0_mydb
oracle 6157 1 0 15:23 ? 00:00:00 ora_lgwr_mydb
oracle 6159 1 0 15:23 ? 00:00:00 ora_ckpt_mydb
oracle 6161 1 0 15:23 ? 00:00:00 ora_smon_mydb
oracle 6163 1 0 15:23 ? 00:00:00 ora_reco_mydb
oracle 6165 1 0 15:23 ? 00:00:00 ora_s000_mydb
oracle 6167 1 0 15:23 ? 00:00:00 ora_d000_mydb
oracle 6172 1 0 15:24 ? 00:00:00 /opt/oracle/product/9.2.0.4/bin/tnslsnr LISTENER -inherit
root 7425 7384 0 15:24 pts/1 00:00:00 grep ora