:2. 在 /etc/init.d/ 下创建文件oracle,内容如下:
复制代码代码如下: #!/bin/sh # chkconfig: 35 80 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=/opt/oracle/102 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 \"-------------------------------------------------\" >> /var/log/oracle date +\" %T %a %D : Starting Oracle Databases as part of system up.\" >> /var/log/oracle echo \"-------------------------------------------------\" >> /var/log/oracle su - $ORA_OWNER -c \"$ORA_HOME/bin/dbstart\" >>/var/log/oracle echo \"Done\" # Start the Listener: 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 - $ORA_OWNER -c \"$ORA_HOME/bin/lsnrctl start\" >>/var/log/oracle
echo \"Done.\" echo \"-------------------------------------------------\" >> /var/log/oracle date +\" %T %a %D : Finished.\" >> /var/log/oracle echo \"-------------------------------------------------\" >> /var/log/oracle touch /var/lock/subsys/oracle 'stop') # Stop the Oracle Listener: 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 - $ORA_OWNER -c \"$ORA_HOME/bin/lsnrctl stop\" >>/var/log/oracle
echo \"Done.\" rm -f /var/lock/subsys/oracle # Stop the Oracle Database: 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 - $ORA_OWNER -c \"$ORA_HOME/bin/dbshut\" >>/var/log/oracle echo \"Done.\" echo \"\" echo \"-------------------------------------------------\" >> /var/log/oracle date +\" %T %a %D : Finished.\" >> /var/log/oracle
echo \"-------------------------------------------------\" >> /var/log/oracle 'restart') $0 stop $0 start esac 我测试的内容为,并且实验成功以下脚本实现了oracle 开机自启
#注意:例子中的oralce命令在/u01/app/oracle/product/10.2.0/db_1/bin/目录。
#修改ORA_HOME的值为ORACLE的目录。
#45,46行一定要加上
1. #!/bin/bash
2. #root
3. #chkconfig: 345 51 49
4. #description: starts the oracle dabase deamons
5. #
6. ORA_HOME=/u01/app/oracle/product/10.2.0/db_1
7. ORA_OWNER=oracle
8. case \"$1\" in
9. 'start')
10. echo -ne \"Starting oracle 11g ... \\n\"
11. su - $ORA_OWNER -c \"$ORA_HOME/bin/dbstart\"
12. echo -e \"Done.\\n\"
13. echo -e \"Starting Oracle Listeners ... \\n\"
14. su - $ORA_OWNER -c \"$ORA_HOME/bin/lsnrctl start\"
15. echo -e \"Done.\\n\"
16. su - $ORA_OWNER -c \"$ORA_HOME/bin/emctl start dbconsole\" #启动web
管理界面:http://host_ip_address:1158/em
17. echo -ne \"input root password......\\n\"
18. su - root -c \"touch /var/lock/subsys/oracle11g\"
19. echo -e \"\\n\"
20. ;;
21. 'stop')
22. echo -ne \"shutting down oracle 11g ... \\n\"
23. su - $ORA_OWNER -c \"$ORA_HOME/bin/dbshut\"
24. echo -ne \"dbshut ok !\\n\"
25. su - $ORA_OWNER -c \"$ORA_HOME/bin/lsnrctl stop\"
26. echo -ne \"lsnrctl stop ok !\\n\"
27. su - $ORA_OWNER -c \"$ORA_HOME/bin/emctl stop dbconsole\"
28. #su - root -c \"/home/oracle/ufsoft/stop.sh\"
29. echo -ne \"input root password......\\n\"
30. su - root -c \"rm -f /var/lock/subsys/oracle11g\"
31. echo
32. ;;
33. 'restart')
34. echo -ne \"restarting oracle 11g ... \\n\"
35. $0 stop
36. $0 start
37. echo
38. ;;
39. *)
40. echo \"Usage: oracle {start|stop|restart} \"
41. exit 1
42. esac
43. exit 0
45.#chkconfig: - 85 15
46.#description:oracle is a World Wide Web server. It is used to server \\dddd
3. 改变文件权限
# chmod 755 /etc/init.d/oracle
4. 添加服务
# chkconfig --level 35 oracle on
#chkconfig --list | grep oracle //查看启动状态
5. 需要在关机或重启机器之前停止数据库,做一下操作
# ln -s /etc/init.d/oracle /etc/rc0.d/K01oracle //关机
# ln -s /etc/init.d/oracle /etc/rc6.d/K01oracle //重启
6. 使用方法
# service oracle start //启动oracle
# service oracle stop //关闭oracle
# service oracle restart //重启oracle
7. 测试
a. 开机自启动
复制代码代码如下: Last login: Mon Nov 26 19:57:06 2012 from 10.0.0.145 [root@ORS ~]# su - oracle [oracle@ORS ~]$ sqlplus \"/as sysdba\"
SQL*Plus: Release 10.2.0.1.0 - Production on Mon Nov 26 20:07:33 2012 Copyright (c) 1982, 2005, Oracle. All rights reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning, OLAP and Data Mining options SQL> set linesize 300; SQL> set pagesize 30; SQL> select * from scott.emp; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- --------- ---------- ---------- ---------- SMITH CLERK 7902 17-DEC-80 800 20 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
WARD SALESMAN 7698 22-FEB-81 1250 500 30 JONES MANAGER 7839 02-APR-81 2975 20 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30 BLAKE MANAGER 7839 01-MAY-81 2850 30 CLARK MANAGER 7839 09-JUN-81 2450 10 SCOTT ANALYST 7566 19-APR-87 3000 20 KING PRESIDENT 17-NOV-81 5000 10 TURNER SALESMAN 7698 08-SEP-81 1500 0 30 ADAMS CLERK 7788 23-MAY-87 1100 20 JAMES CLERK 7698 03-DEC-81 950 30 FORD ANALYST 7566 03-DEC-81 3000 20 MILLER CLERK 7782 23-JAN-82 1300 10
rows selected. SQL> b. service oracle stop 复制代码代码如下: SQL> Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options [oracle@ORS ~]$ logout [root@ORS ~]# service oracle stop Stoping Oracle Listeners ... Done. Stoping Oracle Databases ... Done. [root@ORS ~]# su - oracle [oracle@ORS ~]$ sqlplus \"/as sysdba\" SQL*Plus: Release 10.2.0.1.0 - Production on Mon Nov 26 20:17:20 2012 Copyright (c) 1982, 2005, Oracle. All rights reserved. Connected to an idle instance.
SQL> set linesize 300; SQL> set pagesize 30; SQL> select * from scott.emp; select * from scott.emp * ERROR at line 1: ORA-01034: ORACLE not available SQL>
c. service oracle start
复制代码代码如下: SQL> Disconnected [oracle@ORS ~]$ logout [root@ORS ~]# service oracle start Starting Oracle Databases ... Done
Starting Oracle Listeners ... Done. [root@ORS ~]# d. service oracle restart 复制代码代码如下: [root@ORS ~]# service oracle restart Stoping Oracle Listeners ... Done. Stoping Oracle Databases ... Done.
Starting Oracle Databases ... Done Starting Oracle Listeners ... Done. [root@ORS ~]# 至此,Oracle服务启动&停止脚本与开机自启动设置完毕。