Linux下Oracle 10g自动启动与关闭的实现
环境:RHEL 5.5 + Oracle 10g + VMWare 5.5
尝试在linux下进行oracle的自动启动与关闭,经过多次摸索,完整实现如下:
1、修改oratab文件,使数据库自动启动
#vi /etc/oratab
sid:/opt/app/ora10g/oracle/product/10.2.0/db_1:Y -----即把原来的N修改为Y。
2、修改dbstart、dbshut脚本,使之能够自动启动、关闭LISTENER
将dbstart与dbshut两个脚本中的ORACLE_HOME_LISTNER=$1改为
ORACLE_HOME_LISTNER=$ORACLE_HOME即可(我这个版本好像只修改dbstart,dbshut中没有什么要修改)
3、编写启动脚本/etc/rc.d/init.d/oracle
- #!/bin/bash
- #
- #################FUNCTION#############
- #
- # AutoStart Oracle and listener
- # AutoStop Oracle and listener
- #
- #####################################
- #
- # Created by ZhouYS 2003-11-26
- # Modified by XiaoFengBin 2010-09-13
- #
- # chkconfig: 2345 99 01
- # description: oracledb starts/stops the Oracle server
- case "$1"in
- start)
- echo "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 "dbstart" >> /var/log/oracle
- echo "Done."
- echo "Starting Oracle Listeners ... "
- echo "-------------------------------------------------" >> /var/log/oracle
- date +" %T %a %D : Starting Oracle Listeners as part of system up." >> /var/log/oracle
- echo "-------------------------------------------------" >> /var/log/oracle
- su - oracle -c "lsnrctl start" >> /var/log/oracle
- echo "Done."
- echo "Starting EM ... "
- echo "-------------------------------------------------" >> /var/log/oracle
- date +" %T %a %D : Starting EM as part of system up." >> /var/log/oracle
- echo "-------------------------------------------------" >> /var/log/oracle
- su - oracle -c "emctl start dbconsole" >> /var/log/oracle
- echo "Done."
- echo "Starting isqlplus ... "
- echo "-------------------------------------------------" >> /var/log/oracle
- date +" %T %a %D : Starting isqlplus as part of system up." >> /var/log/oracle
- echo "-------------------------------------------------" >> /var/log/oracle
- su - oracle -c "isqlplusctl 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 "Stoping EM ... "
- echo "-------------------------------------------------" >> /var/log/oracle
- date +" %T %a %D : Stoping EM as part of system down." >> /var/log/oracle
- echo "-------------------------------------------------" >> /var/log/oracle
- su - oracle -c "emctl stop dbconsole" >>/var/log/oracle
- echo "Done."
- echo "Stoping isqlplus ... "
- echo "-------------------------------------------------" >> /var/log/oracle
- date +" %T %a %D : Stoping isqlplus as part of system down." >> /var/log/oracle
- echo "-------------------------------------------------" >> /var/log/oracle
- su - oracle -c "isqlplusctl stop" >>/var/log/oracle
- echo "Done."
- echo "Stoping Oracle Listeners ... "
- echo "-------------------------------------------------" >> /var/log/oracle
- date +" %T %a %D : Stoping Oracle Listener as part of system down." >> /var/log/oracle
- echo "-------------------------------------------------" >> /var/log/oracle
- su - oracle -c "lsnrctl stop" >> /var/log/oracle
- echo "Done."
- echo "Stoping Oracle Databases ... "
- echo "-------------------------------------------------" >> /var/log/oracle
- date +" %T %a %D : Stoping Oracle Databases as part of system down." >> /var/log/oracle
- echo "-------------------------------------------------" >> /var/log/oracle
- su - oracle -c "dbshut" >>/var/log/oracle
- echo "Done."
- echo ""
- echo "-------------------------------------------------" >> /var/log/oracle
- date +" %T %a %D : Finished." >> /var/log/oracle
- echo "-------------------------------------------------" >> /var/log/oracle
- rm -f /var/lock/subsys/oracle
- ;;
- restart)
- $0 stop
- $0 start
- ;;
- *)
- echo "Usage: oracle {start|stop|restart}"
- exit 1
- esac
- exit 0
4、添加服务
[root@by init.d]# chmod 755 oracle
[root@by init.d]# chmod +x /etc/rc.d/init.d/oracle
[root@by init.d]# chkconfig --add oracle
[root@by init.d]# chkconfig --list oracle
oracle 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
如果出现:bash: chkconfig: command not found,那么一般是chkconfig包没装或者装了路径没设置对。
[root@by init.d]# PATH="$PATH":/sbin
[root@by init.d]# echo $PATH
/sbin:/usr/kerberos/sbin:/opt/oracle/product/10.2.0/db_1/bin:/usr/sbin:/usr/lib/qt-3.3/bin:/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/oracle/bin:/sbin
5、测试服务
[root@by init.d]# service oracle stop
如果出现如下错误:
Stoping EM ...
/home/oracle/.bash_profile: line 23: ulimit: open files: cannot modify limit: 不允许的操作
Done.
可在
[root@by init.d]# vi /etc/security/limits.conf
添加如下内容:
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
Ok,一切完成。关闭系统,重启,最后验证,都自动启动了。