oracle9.2 for Redhat8 开机自启动:

oracle9.2 for Redhat8 开机自启动:

1,修改Oracle系统配置文件/etc/oratab
/etc/oratab 格式为: SID:ORACLE_HOME:AUTO
把AUTO域设置为Y(大写),只有这样,oracle 自带的dbstart和dbshut才能够发挥作用。
# 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:<N|Y>:
#
# 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.
#
#
*:/home/oracle/product/10.1:N
orcl:/home/oracle/product/10.1:Y

2,编写服务脚本
root身份登陆,将脚本命名为oracle_dbstart_redhat.sh,保存在/etc/rc.d/init.d下
[root@localhost root]# vi /etc/rc.d/init.d/oracle_dbstart_redhat.sh
内容如下:
case "$1" in
start)
echo -n "Starting Oracle Databases: "
echo "----------------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Starting Oracle Databases as part of system up." >> /var/log/oracle
echo "----------------------------------------------------" >> /var/log/oracle
##su - oracle -c /opt/ora9/product/9.2/bin/dbstart >> /var/log/oracle
su - oracle -c /home/oracle/product/10.1/bin/dbstart >> /var/log/oracle
echo "Done."
echo -n "Starting Oracle Listeners: "
##su - oracle -c "/opt/ora9/product/9.2/bin/lsnrctl start" >> /var/log/oracle
su - oracle -c "/home/oracle/product/10.1/bin/lsnrctl start" >> /var/log/oracle
echo "Done."
echo ""
echo "----------------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Finished." >> /var/log/oracle
echo "----------------------------------------------------" >> /var/log/oracle
touch /var/lock/subsys/oracle
;;
stop)
echo -n "Shutting Down Oracle Listeners: "
echo "----------------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Shutting Down Oracle Databases as part of system down." >> /var/log/oracle
echo "----------------------------------------------------" >> /var/log/oracle
##su - oracle -c "/opt/ora9/product/9.2/bin/lsnrctl stop" >> /var/log/oracle
su - oracle -c "/home/oracle/product/10.1/bin/lsnrctl stop" >> /var/log/oracle
echo "Done."
rm -f /var/lock/subsys/oracle
echo -n "Shutting Down Oracle Databases: "
##su - oracle -c /opt/ora9/product/9.2/bin/dbshut >> /var/log/oracle
su - oracle -c /home/oracle/product/10.1/bin/dbshut >> /var/log/oracle
echo "Done."
echo ""
echo "----------------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Finished." >> /var/log/oracle
echo "----------------------------------------------------" >> /var/log/oracle
;;
restart)
echo -n "Restarting Oracle Databases: "
echo "----------------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Restarting Oracle Databases as part of system up." >> /var/log/oracle
echo "----------------------------------------------------" >> /var/log/oracle
su - oracle -c /home/oracle/product/10.1/bin/dbshut >> /var/log/oracle
su - oracle -c /home/oracle/product/10.1/bin/dbstart >> /var/log/oracle
##su - oracle -c /opt/ora9/product/9.2/bin/dbstart >> /var/log/oracle
echo "Done."
echo -n "Restarting Oracle Listeners: "
##su - oracle -c "/opt/ora9/product/9.2/bin/lsnrctl stop" >> /var/log/oracle
##su - oracle -c "/opt/ora9/product/9.2/bin/lsnrctl start" >> /var/log/oracle
su - oracle -c "/home/oracle/product/10.1/bin/lsnrctl stop" >> /var/log/oracle
su - oracle -c "/home/oracle/product/10.1/bin/lsnrctl start" >> /var/log/oracle
echo "Done."
echo ""
echo "----------------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Finished." >> /var/log/oracle
echo "----------------------------------------------------" >> /var/log/oracle
touch /var/lock/subsys/oracle
;;
*)
echo "Usage: oracle {start|stop|restart}"
exit 1
esac

保存后,改变文本属性为chmod 755 oracle


3,建立服务连接
系统启动时启动数据库,我们需要以下连结∶
--------------------------------------------------------------------------------
[oracle@localhost rc2.d]$ ln -s /etc/init.d/oracle_dbstart_redhat.sh /etc/rc2.d/S99oracle_dbstart_redhat
[oracle@localhost rc3.d]$ ln -s /etc/init.d/oracle_dbstart_redhat.sh /etc/rc3.d/S99oracle_dbstart_redhat
--------------------------------------------------------------------------------
要在重新启动时停止数据库,我们需要以下连结∶
--------------------------------------------------------------------------------
[oracle@localhost rc0.d]$ ln -s /etc/init.d/oracle_dbstart_redhat.sh /etc/rc0.d/K01oracle_dbstart_redhat # 停止
[oracle@localhost rc6.d]$ ln -s /etc/init.d/oracle_dbstart_redhat.sh /etc/rc6.d/K01oracle_dbstart_redhat # 重新启动

你可能感兴趣的:(oracle,C++,c,redhat,C#)