linux oracle 服务自动启动、关闭

linux oracle 服务自动启动、关闭

首先以root权限登录

1、创建服务脚本执行输出日志目录
   mkdir -p /logs/oracle  
   chmod -R 777 /logs
2、进行服务脚本存入目录
   cd /etc/rc.d/init.d
3、编写执行脚本oracle  vi oracle
#!/bin/sh
# chkconfig:2345 99 10
# description: Oracle auto start-stop script.

#
# 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=/u01/app/oracle/product/10.2.0/db_1
ORA_OWNER=oracle
if [ ! -f $ORA_HOME/bin/dbstart ]
then
    echo "Oracle startup: cannot start"
    exit
fi
case "$1" in
'start')
# Start the Oracle databases:
echo "Starting Oracle Databases ... "
echo "-------------------------------------------------" >> /logs/oracle/log
date +" %T %a %D : Starting Oracle Databases as part of system up." >> /logs/oracle/log
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart" >>/logs/oracle/log
echo "Done"

# Start the Listener:
echo "Starting Oracle Listeners ... "
echo "-------------------------------------------------" >> /logs/oracle/log
date +" %T %a %D : Starting Oracle Listeners as part of system up." >> /logs/oracle/log
echo "-------------------------------------------------" >> /logs/oracle/log
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start" >>/logs/oracle/log
echo "Done."
echo "-------------------------------------------------" >> /logs/oracle/log
date +" %T %a %D : Finished." >> /var/log/oracle
echo "-------------------------------------------------" >> /logs/oracle/log
touch /var/lock/subsys/oracle
;;

'stop')
# Stop the Oracle Listener:
echo "Stoping Oracle Listeners ... "
echo "-------------------------------------------------" >> /logs/oracle/log
date +" %T %a %D : Stoping Oracle Listener as part of system down." >> /logs/oracle/log
echo "-------------------------------------------------" >> /logs/oracle/log
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop" >>/logs/oracle/log
echo "Done."
rm -f /var/lock/subsys/oracle

# Stop the Oracle Database:
echo "Stoping Oracle Databases ... "
echo "-------------------------------------------------" >> /logs/oracle/log
date +" %T %a %D : Stoping Oracle Databases as part of system down." >> /logs/oracle/log
echo "-------------------------------------------------" >> /logs/oracle/log
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut" >>/var/log/oracle
echo "Done."
echo ""
echo "-------------------------------------------------" >> /logs/oracle/log
date +" %T %a %D : Finished." >> /var/log/oracle
echo "-------------------------------------------------" >> /logs/oracle/log
;;

'restart')
$0 stop
$0 start
;;
esac
4、赋予执行权限
   chmod +x oracle
5、查看系统运行级别
   sudo runlevel
   --N 5
6、进行运行级别服务执行目录并创建链接
   cd /etc/rc.d/r5.d
   ln -s ../init.d/oracle K10oracle
   ln -s ../init.d/oracle S99oracle
 7、重启测试即可
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值