该脚本在启动前具有自检测是否启动功能。防止多次重启。
目前已经测试在Rad linux 下可行
启动
/etc/init.d/oracle_ws start
停止
/etc/init.d/oracle_ws start
oracle 系统默认安装在/opt/oracle/product/10.2/db_1
1) 因原始安装默认$ORACLE_HOME/bin/dbstart 内有个bug
内侦听器路径给写死成绝对路径,实际这个路径不存在。需要手动调整改为$ORACLE_HOME
如下:
vi $ORACLE_HOME/bin/dbstart
找到# Set this to bring up Oracle Net Listener
修改成ORACLE_HOME_LISTNER 变量替换为$ORACLE_HOME 该自变量已经在启动脚本提前定义好了。
ORACLE_HOME_LISTNER=$ORACLE_HOME
保存退出
2) vi /etc/oratab
orcl:/opt/oracle/product/10.2/db_1:Y
3) vi /etc/init.d/oracle_ws
内容为后边的脚本自己修改ORACLE_HOME 变量为本地的oracle.保存退出
4) 编写服务启动脚本
vi /etc/init.d/oracle_ws_auto
#!/usr/bin/sh
/etc/init.d/oracle_ws start
vi /etc/init.d/oracle_ws_stop
#!/usr/bin/sh
/etc/init.d/oracle_ws stop
chmod -R 777 /etc/init.d/oracle_ws*
5)挂接oracle 开机自启动,关机注销
cd /etc/init.d/rc3.d/
#分别进入rc3.d 建立自启动软连接,以及系统停止kill 连接
ln -s /etc/init.d/oracle_ws_auto S15oracle
ln -s /etc/init.d/oracle_ws_stop K07oracle
ws:~ # cd /etc/init.d/rc3.d/
ws:/etc/init.d/rc3.d # ll *oracle
lrwxrwxrwx 1 root root 17 Jul 20 21:09 K07oracle -> ../oracle_ws_stop
lrwxrwxrwx 1 root root 17 Jul 20 21:07 S15oracle -> ../oracle_ws_auto
6) 跟踪测试日志 tail -f /var/log/oracle 根据提示进行以上几个步骤操作
如果不成功手动进入启动
su - oracle
sqlplus /nolog
conn / as sysdba
startup
quit
注step 6) 必须在正常oracle启动不成功才用的手动测试不是必需的。
su - root
ps-ef|grep oracle|wc -l 看下oracle 进程数
#oracle_ws 脚本
#!/usr/bin/sh
#
#chkconfig:2345 98 05
#description:Oracle Server
#/etc/init.d/oracle_ws
#∶启动及停止 Oracle 数据库和监听程序
#$id by walksing 20100720
export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2/db_1
export ORACLE_SID=orcl
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_USER=oracle
case "$1" in
start)
echo -n "Starting Oracle Databases: "
echo "----------------------------------------------------" >> /var/log/oracle
if [ -f /var/lock/subsys/oracle ]; then
echo "Oracle has started,please stop it before starting."
exit 1
fi
date +"! %T %a %D : Starting Oracle Databases as part of system up." >> /var/log/oracle
echo "----------------------------------------------------" >> /var/log/oracle
su - "$ORACLE_USER" -c "dbstart" >> /var/log/oracle
echo "Done."
echo -n "Starting Oracle Listeners: "
su - "$ORACLE_USER" -c "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_USER" -c "lsnrctl stop" >> /var/log/oracle
echo "Done."
rm -f /var/lock/subsys/oracle
echo -n "Shutting Down Oracle Databases: "
su - "$ORACLE_USER" -c "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_USER" -c " dbstop " >> /var/log/oracle
su - "$ORACLE_USER" -c " dbstart" >> /var/log/oracle
echo "Done."
echo -n "Restarting Oracle Listeners: "
su - "$ORACLE_USER" -c "lsnrctl stop" >> /var/log/oracle
su - "$ORACLE_USER" -c "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
目前已经测试在Rad linux 下可行
启动
/etc/init.d/oracle_ws start
停止
/etc/init.d/oracle_ws start
oracle 系统默认安装在/opt/oracle/product/10.2/db_1
1) 因原始安装默认$ORACLE_HOME/bin/dbstart 内有个bug
内侦听器路径给写死成绝对路径,实际这个路径不存在。需要手动调整改为$ORACLE_HOME
如下:
vi $ORACLE_HOME/bin/dbstart
找到# Set this to bring up Oracle Net Listener
修改成ORACLE_HOME_LISTNER 变量替换为$ORACLE_HOME 该自变量已经在启动脚本提前定义好了。
ORACLE_HOME_LISTNER=$ORACLE_HOME
保存退出
2) vi /etc/oratab
orcl:/opt/oracle/product/10.2/db_1:Y
3) vi /etc/init.d/oracle_ws
内容为后边的脚本自己修改ORACLE_HOME 变量为本地的oracle.保存退出
4) 编写服务启动脚本
vi /etc/init.d/oracle_ws_auto
#!/usr/bin/sh
/etc/init.d/oracle_ws start
vi /etc/init.d/oracle_ws_stop
#!/usr/bin/sh
/etc/init.d/oracle_ws stop
chmod -R 777 /etc/init.d/oracle_ws*
5)挂接oracle 开机自启动,关机注销
cd /etc/init.d/rc3.d/
#分别进入rc3.d 建立自启动软连接,以及系统停止kill 连接
ln -s /etc/init.d/oracle_ws_auto S15oracle
ln -s /etc/init.d/oracle_ws_stop K07oracle
ws:~ # cd /etc/init.d/rc3.d/
ws:/etc/init.d/rc3.d # ll *oracle
lrwxrwxrwx 1 root root 17 Jul 20 21:09 K07oracle -> ../oracle_ws_stop
lrwxrwxrwx 1 root root 17 Jul 20 21:07 S15oracle -> ../oracle_ws_auto
6) 跟踪测试日志 tail -f /var/log/oracle 根据提示进行以上几个步骤操作
如果不成功手动进入启动
su - oracle
sqlplus /nolog
conn / as sysdba
startup
quit
注step 6) 必须在正常oracle启动不成功才用的手动测试不是必需的。
su - root
ps-ef|grep oracle|wc -l 看下oracle 进程数
#oracle_ws 脚本
#!/usr/bin/sh
#
#chkconfig:2345 98 05
#description:Oracle Server
#/etc/init.d/oracle_ws
#∶启动及停止 Oracle 数据库和监听程序
#$id by walksing 20100720
export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2/db_1
export ORACLE_SID=orcl
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_USER=oracle
case "$1" in
start)
echo -n "Starting Oracle Databases: "
echo "----------------------------------------------------" >> /var/log/oracle
if [ -f /var/lock/subsys/oracle ]; then
echo "Oracle has started,please stop it before starting."
exit 1
fi
date +"! %T %a %D : Starting Oracle Databases as part of system up." >> /var/log/oracle
echo "----------------------------------------------------" >> /var/log/oracle
su - "$ORACLE_USER" -c "dbstart" >> /var/log/oracle
echo "Done."
echo -n "Starting Oracle Listeners: "
su - "$ORACLE_USER" -c "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_USER" -c "lsnrctl stop" >> /var/log/oracle
echo "Done."
rm -f /var/lock/subsys/oracle
echo -n "Shutting Down Oracle Databases: "
su - "$ORACLE_USER" -c "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_USER" -c " dbstop " >> /var/log/oracle
su - "$ORACLE_USER" -c " dbstart" >> /var/log/oracle
echo "Done."
echo -n "Restarting Oracle Listeners: "
su - "$ORACLE_USER" -c "lsnrctl stop" >> /var/log/oracle
su - "$ORACLE_USER" -c "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