linux下Oracle 12c 自启动配置及启动脚本

2017年7月19日

1. Oracle的一些基本参数

[oracle@localhost ~]$ echo $ORACLE_SID
oracledb

 

[oracle@localhost ~]$ echo $ORACLE_HOME
/u01/app/oracle/product/12.1.0/db_1

[oracle@localhost ~]$ echo $ORACLE_BASE
/u01/app/oracle

2. 修改/etc/oratab,使Oracle可以自启动

[oracle@localhost ~]$ vim /etc/oratab
增加一行
# $ORACLE_SID:$ORACLE_HOME:<N|Y>:
oracledb:/u01/app/oracle/product/12.1.0/dbhome_1:Y

3. 在 /etc/init.d/ 下创建文件oracle

[root@localhost ~]# touch /etc/init.d/oracle
[root@localhost ~]# chmod 755 /etc/init.d/oracle
[root@localhost ~]# vim /etc/init.d/oracle

添加如下脚本

  1. #!/bin/sh
  2. # chkconfig: 35 80 10
  3. # description: Oracle auto start-stop script.
  4. #
  5. # Set ORA_HOME to be equivalent to the $ORACLE_HOME
  6. # from which you wish to execute dbstart and dbshut;
  7. #
  8. # Set ORA_OWNER to the user id of the owner of the
  9. # Oracle database in ORA_HOME.
  10. ORA_HOME=/u01/app/oracle/product/12.1.0/dbhome_1
  11. ORA_OWNER=oracle
  12. if [ ! -f $ORA_HOME/bin/dbstart ]
  13. then
  14. echo "Oracle startup: cannot start"
  15. exit
  16. fi
  17. case "$1" in
  18. 'start')
  19. # Start the Oracle databases:
  20. echo "Starting Oracle Databases ... "
  21. echo "-------------------------------------------------" >> /var/log/oracle
  22. date +" %T %a %D : Starting Oracle Databases as part of system up." >> /var/log/oracle
  23. echo "-------------------------------------------------" >> /var/log/oracle
  24. su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart"  >>/var/log/oracle
  25. echo "Done"
  26. # Start the Listener:
  27. echo "Starting Oracle Listeners ... "
  28. echo "-------------------------------------------------" >> /var/log/oracle
  29. date +" %T %a %D : Starting Oracle Listeners as part of system up." >> /var/log/oracle
  30. echo "-------------------------------------------------" >> /var/log/oracle
  31. su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start" >>/var/log/oracle
  32. echo "Done."
  33. echo "-------------------------------------------------" >> /var/log/oracle
  34. date +" %T %a %D : Finished." >> /var/log/oracle
  35. echo "-------------------------------------------------" >> /var/log/oracle
  36. touch /var/lock/subsys/oracle
  37. ;;
  38. 'stop')
  39. # Stop the Oracle Listener:
  40. echo "Stoping Oracle Listeners ... "
  41. echo "-------------------------------------------------" >> /var/log/oracle
  42. date +" %T %a %D : Stoping Oracle Listener as part of system down." >> /var/log/oracle
  43. echo "-------------------------------------------------" >> /var/log/oracle
  44. su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop" >>/var/log/oracle
  45. echo "Done."
  46. rm -f /var/lock/subsys/oracle
  47. # Stop the Oracle Database:
  48. echo "Stoping Oracle Databases ... "
  49. echo "-------------------------------------------------" >> /var/log/oracle
  50. date +" %T %a %D : Stoping Oracle Databases as part of system down." >> /var/log/oracle
  51. echo "-------------------------------------------------" >> /var/log/oracle
  52. su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut" >>/var/log/oracle
  53. echo "Done."
  54. echo ""
  55. echo "-------------------------------------------------" >> /var/log/oracle
  56. date +" %T %a %D : Finished." >> /var/log/oracle
  57. echo "-------------------------------------------------" >> /var/log/oracle
  58. ;;
  59. 'restart')
  60. $0 stop
  61. $0 start
  62. ;;
  63. esac

4. 添加服务

[root@localhost ~]# chkconfig --level 35 oracle on

5. 需要在关机或重启机器之前停止数据库,做以下操作

[root@localhost ~]# ln -s /etc/init.d/oracle /etc/rc0.d/K01oracle //关机
[root@localhost ~]# ln -s /etc/init.d/oracle /etc/rc6.d/K01oracle //重启

6. 测试命令是否有效

[root@localhost ~]# service oracle start //启动oracleStarting Oracle Databases ...
Done
Starting Oracle Listeners ...
Done.
 
[root@localhost ~]# service oracle stop //关闭oracle
 
Stoping Oracle Listeners ...
Done.
Stoping Oracle Databases ...
Done.
 
# service oracle restart //重启oracle
[root@localhost ~]# service oracle restart
Stoping Oracle Listeners ...
Done.
Stoping Oracle Databases ...
Done.
 
Starting Oracle Databases ...
Done
Starting Oracle Listeners ...
Done.
 

7. 重启Linux

[root@localhost ~]# reboot

8. 重启后进入oracle用户,进sqlplus

[oracle@localhost Desktop]$ sqlplus / as sysdbaSQL*Plus: Release 12.1.0.1.0 Production on Sat Jul 18 23:16:17 2015
 
Copyright (c) 1982, 2013, Oracle. All rights reserved.
 
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
 
SQL> set linesize 300;
SQL> set pagesize 30;
SQL> select sysdate from dual;
 
SYSDATE
---------
18-JUL-15

 

数据库正常启动!

参考:http://www.jb51.net/article/32214.htm
原文:http://adelazhu.blog.51cto.com/9455045/1675970/

没有评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注