Linux下Oracle 10g自动启动与关闭的实现

时间:2022-01-03 03:55:16

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

[c-sharp] view plaincopyprint?
  1. #!/bin/bash  
  2. #  
  3. #################FUNCTION############# 
  4. #  
  5. # AutoStart Oracle and listener  
  6. # AutoStop Oracle and listener  
  7. #  
  8. #####################################  
  9. #  
  10. # Created  by ZhouYS       2003-11-26  
  11. # Modified by XiaoFengBin  2010-09-13 
  12. #  
  13. # chkconfig: 2345 99 01  
  14. # description: oracledb starts/stops the Oracle server 
  15.  
  16. case "$1"in  
  17. start)  
  18. echo "Starting Oracle Databases ... "  
  19. echo "-------------------------------------------------" >> /var/log/oracle  
  20. date +" %T %a %D : Starting Oracle Databases as part of system up." >> /var/log/oracle  
  21. echo "-------------------------------------------------" >> /var/log/oracle  
  22. su - oracle -c "dbstart" >> /var/log/oracle  
  23. echo "Done."  
  24. echo "Starting Oracle Listeners ... "  
  25. echo "-------------------------------------------------" >> /var/log/oracle  
  26. date +" %T %a %D : Starting Oracle Listeners as part of system up." >> /var/log/oracle  
  27. echo "-------------------------------------------------" >> /var/log/oracle  
  28. su - oracle -c "lsnrctl start" >> /var/log/oracle  
  29. echo "Done."  
  30. echo "Starting EM ... "  
  31. echo "-------------------------------------------------" >> /var/log/oracle  
  32. date +" %T %a %D : Starting EM as part of system up." >> /var/log/oracle  
  33. echo "-------------------------------------------------" >> /var/log/oracle  
  34. su - oracle -c "emctl start dbconsole" >> /var/log/oracle  
  35. echo "Done."  
  36. echo "Starting isqlplus ... "  
  37. echo "-------------------------------------------------" >> /var/log/oracle  
  38. date +" %T %a %D : Starting isqlplus as part of system up." >> /var/log/oracle  
  39. echo "-------------------------------------------------" >> /var/log/oracle  
  40. su - oracle -c "isqlplusctl start" >> /var/log/oracle  
  41. echo "Done."  
  42. echo ""  
  43. echo "-------------------------------------------------" >> /var/log/oracle  
  44. date +" %T %a %D : Finished." >> /var/log/oracle  
  45. echo "-------------------------------------------------" >> /var/log/oracle  
  46. touch /var/lock/subsys/oracle  
  47.  
  48. ;;  
  49. stop)  
  50. echo "Stoping EM ... "  
  51. echo "-------------------------------------------------" >> /var/log/oracle  
  52. date +" %T %a %D : Stoping EM as part of system down." >> /var/log/oracle  
  53. echo "-------------------------------------------------" >> /var/log/oracle  
  54. su - oracle -c "emctl stop dbconsole" >>/var/log/oracle  
  55. echo "Done." 
  56. echo "Stoping isqlplus ... "  
  57. echo "-------------------------------------------------" >> /var/log/oracle  
  58. date +" %T %a %D : Stoping isqlplus as part of system down." >> /var/log/oracle  
  59. echo "-------------------------------------------------" >> /var/log/oracle  
  60. su - oracle -c "isqlplusctl stop" >>/var/log/oracle  
  61. echo "Done." 
  62. echo "Stoping Oracle Listeners ... "  
  63. echo "-------------------------------------------------" >> /var/log/oracle  
  64. date +" %T %a %D : Stoping Oracle Listener as part of system down." >> /var/log/oracle  
  65. echo "-------------------------------------------------" >> /var/log/oracle  
  66. su - oracle -c "lsnrctl stop" >> /var/log/oracle  
  67. echo "Done."  
  68. echo "Stoping Oracle Databases ... "  
  69. echo "-------------------------------------------------" >> /var/log/oracle  
  70. date +" %T %a %D : Stoping Oracle Databases as part of system down." >> /var/log/oracle  
  71. echo "-------------------------------------------------" >> /var/log/oracle  
  72. su - oracle -c "dbshut" >>/var/log/oracle  
  73. echo "Done."  
  74. echo ""  
  75. echo "-------------------------------------------------" >> /var/log/oracle  
  76. date +" %T %a %D : Finished." >> /var/log/oracle  
  77. echo "-------------------------------------------------" >> /var/log/oracle  
  78. rm -f /var/lock/subsys/oracle  
  79.  
  80. ;;  
  81. restart)  
  82. $0 stop  
  83. $0 start  
  84.  
  85. ;;  
  86. *)  
  87. echo "Usage: oracle {start|stop|restart}"  
  88. exit 1  
  89. esac  
  90. 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,一切完成。关闭系统,重启,最后验证,都自动启动了。