为了避免开发库偶尔需要维护服务器重启,所以在开发库中配置了oracle随系统自动启停的脚本。
1. 首先修改Oracle系统配置文件:/etc/oratab,只有这样,Oracle 自带的dbstart和dbshut才能够发挥作用
1 2 3 4 5 6 7 |
[root@DB ~]# vi /etc/oratab oradev:/home/opt/oracle/11.2/db_1:N 将文件中末尾的N修改为Y即可,需要大写 [root@DB ~]# cat /etc/oratab oradev:/home/opt/oracle/11.2/db_1:Y |
2. 创建自动启停脚本,在 /etc/init.d/ 目录下创建文件oracle,内容如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
[root@DB ~]# cd /etc/init.d/ [root@DB init.d]# vi 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=/home/opt/oracle/11.2/db_1 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 [root@DB init.d]# |
3. 更改文件权限为可执行
1 2 3 4 |
[root@DB init.d]# chmod 755 oracle [root@DB init.d]# ll oracle -rwxr-xr-x. 1 root root 2482 5月 25 09:44 oracle [root@DB init.d]# |
4. 添加oracle服务
1 2 3 |
[root@DB init.d]# chkconfig --level 35 oracle on [root@DB init.d]# chkconfig --list oracle oracle 0:关闭 1:关闭 2:关闭 3:启用 4:关闭 5:启用 6:关闭 |
5. 配置事件,需要在关机或重启机器之前停止数据库
1 2 3 4 5 |
关机: [root@DB init.d]# ln -s /etc/init.d/oracle /etc/rc0.d/K01oracle 重启: [root@DB init.d]# ln -s /etc/init.d/oracle /etc/rc6.d/K01oracle |
6. 测试服务
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
[root@DB subsys]# service oracle stop Stoping Oracle Listeners ... Done. Stoping Oracle Databases ... Done. [oracle@DB bin]$ lsnrctl status LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 25-MAY-2016 10:03:15 Copyright (c) 1991, 2013, Oracle. All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1))) TNS-12541: TNS:no listener TNS-12560: TNS:protocol adapter error TNS-00511: No listener Linux Error: 2: No such file or directory Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.130)(PORT=1521))) TNS-12541: TNS:no listener TNS-12560: TNS:protocol adapter error TNS-00511: No listener Linux Error: 111: Connection refused [oracle@DB bin]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Wed May 25 10:03:59 2016 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to an idle instance. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
[root@DB subsys]# service oracle start Starting Oracle Databases ... Done Starting Oracle Listeners ... Done. [oracle@DB bin]$ lsnrctl status LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 25-MAY-2016 10:04:37 Copyright (c) 1991, 2013, Oracle. All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1))) STATUS of the LISTENER ------------------------ Alias LISTENER Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production Start Date 25-MAY-2016 10:04:34 Uptime 0 days 0 hr. 0 min. 3 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Parameter File /home/opt/oracle/11.2/db_1/network/admin/listener.ora Listener Log File /home/opt/oracle/diag/tnslsnr/DB/listener/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1))) (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.1.130)(PORT=1521))) Services Summary... Service "oradev" has 1 instance(s). Instance "oradev", status UNKNOWN, has 1 handler(s) for this service... The command completed successfully [oracle@DB bin]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Wed May 25 10:04:44 2016 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> |
7. 关机重启服务器测试
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
[root@DB ~]# init 6 待重启完成后,查看oracle运行状态----- [root@DB ~]# su - oracle [oracle@DB ~]$ lsnrctl status LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 25-MAY-2016 10:09:37 Copyright (c) 1991, 2013, Oracle. All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1))) STATUS of the LISTENER ------------------------ Alias LISTENER Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production Start Date 25-MAY-2016 10:09:17 Uptime 0 days 0 hr. 0 min. 19 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Parameter File /home/opt/oracle/11.2/db_1/network/admin/listener.ora Listener Log File /home/opt/oracle/diag/tnslsnr/DB/listener/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1))) (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.1.130)(PORT=1521))) Services Summary... Service "oradev" has 1 instance(s). Instance "oradev", status UNKNOWN, has 1 handler(s) for this service... The command completed successfully [oracle@DB ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Wed May 25 10:09:42 2016 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> select open_mode from v$database; OPEN_MODE -------------------- READ WRITE |
配置完毕。
- 本文固定链接: http://www.savedba.com/?p=935
- 转载请注明: 版权所有,文章允许转载,但必须以链接方式注明源地址,否则追究法律责任!