Linux Oracle服務啟動&停止指令碼與開機自啟動

來源:互聯網
上載者:User

在CentOS 6.3下安裝完Oracle 10g R2,重開機之後,你會發現Oracle沒有自行啟動,這是正常的,因為在Linux下安裝Oracle的確不會自行啟動,必須要自行設定相關參數,首先先介紹一般而言如何啟動oracle。

一、在Linux下啟動Oracle

登入到CentOS,切換到oracle使用者權限

# su – oracle

接著輸入:

$ sqlplus "/as sysdba"

原本的畫面會變為
SQL>

接著請輸入
SQL> startup

就可以正常的啟動資料庫了。

另外停止資料庫的指令如下:
SQL> shutdown immediate

二、檢查Oracle DB監聽器是否正常

回到終端機模式,輸入:

$ lsnrctl status

檢查看看監聽器是否有啟動

如果沒有啟動,可以輸入:

$ lsnrctl start

啟動監聽器

SQL> conn sys@orcl as sysdba

然後輸入密碼,sys以sysdba身份登入資料庫。

三、啟動emctl

另外也可以發現http://localhost.localdomain:1158/em 目前是沒有反應的,這邊要另外啟動,啟動的指令如下:

$ emctl start dbconsole

這個指令已耗用時間較長,執行完的畫面如下:

手動啟動Oracle資料庫完畢,下面建立系統自行啟動Oracle的指令碼。

四、Oracle啟動&停止指令碼

1. 修改Oracle系統設定檔:/etc/oratab,只有這樣,Oracle 內建的dbstart和dbshut才能夠發揮作用。

# vi /etc/oratab
orcl:/opt/oracle/102:Y

# Entries are of the form:
#   $ORACLE_SID:$ORACLE_HOME:<N|Y>:

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/102ORA_OWNER=oracleif [ ! -f $ORA_HOME/bin/dbstart ]then    echo "Oracle startup: cannot start"    exitficase "$1" in'start')# Start the Oracle databases:echo "Starting Oracle Databases ... "echo "-------------------------------------------------" >> /var/log/oracledate +" %T %a %D : Starting Oracle Databases as part of system up." >> /var/log/oracleecho "-------------------------------------------------" >> /var/log/oraclesu - $ORA_OWNER -c "$ORA_HOME/bin/dbstart" >>/var/log/oracleecho "Done"# Start the Listener:echo "Starting Oracle Listeners ... "echo "-------------------------------------------------" >> /var/log/oracledate +" %T %a %D : Starting Oracle Listeners as part of system up." >> /var/log/oracleecho "-------------------------------------------------" >> /var/log/oraclesu - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start" >>/var/log/oracleecho "Done."echo "-------------------------------------------------" >> /var/log/oracledate +" %T %a %D : Finished." >> /var/log/oracleecho "-------------------------------------------------" >> /var/log/oracletouch /var/lock/subsys/oracle;;'stop')# Stop the Oracle Listener:echo "Stoping Oracle Listeners ... "echo "-------------------------------------------------" >> /var/log/oracledate +" %T %a %D : Stoping Oracle Listener as part of system down." >> /var/log/oracleecho "-------------------------------------------------" >> /var/log/oraclesu - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop" >>/var/log/oracleecho "Done."rm -f /var/lock/subsys/oracle# Stop the Oracle Database:echo "Stoping Oracle Databases ... "echo "-------------------------------------------------" >> /var/log/oracledate +" %T %a %D : Stoping Oracle Databases as part of system down." >> /var/log/oracleecho "-------------------------------------------------" >> /var/log/oraclesu - $ORA_OWNER -c "$ORA_HOME/bin/dbshut" >>/var/log/oracleecho "Done."echo ""echo "-------------------------------------------------" >> /var/log/oracledate +" %T %a %D : Finished." >> /var/log/oracleecho "-------------------------------------------------" >> /var/log/oracle;;'restart')$0 stop$0 start;;esac

3. 改變檔案許可權
# chmod 755 /etc/init.d/oracle

4. 添加服務
# chkconfig --level 35 oracle on

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
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902 17-DEC-80        800                    20
      7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
      7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
      7566 JONES      MANAGER         7839 02-APR-81       2975                    20
      7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
      7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
      7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
      7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
      7839 KING       PRESIDENT            17-NOV-81       5000                    10
      7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
      7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
      7900 JAMES      CLERK           7698 03-DEC-81        950                    30
      7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
      7934 MILLER     CLERK           7782 23-JAN-82       1300                    10

14 rows selected.

SQL>

b. service oracle stop

SQL> Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - ProductionWith the Partitioning, OLAP and Data Mining options[oracle@ORS ~]$ logout[root@ORS ~]# service oracle stopStoping 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 2012Copyright (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 availableSQL> 

c. service oracle start

SQL> Disconnected[oracle@ORS ~]$ logout[root@ORS ~]# service oracle startStarting Oracle Databases ... DoneStarting Oracle Listeners ... Done.[root@ORS ~]# 

d. service oracle restart

[root@ORS ~]# service oracle restartStoping Oracle Listeners ... Done.Stoping Oracle Databases ... Done.Starting Oracle Databases ... DoneStarting Oracle Listeners ... Done.[root@ORS ~]# 

至此,Oracle服務啟動&停止指令碼與開機自啟動設定完畢。

 

CentOS 6.3(x32)下安裝Oracle 10g R2

http://www.cnblogs.com/mchina/archive/2012/11/06/2737472.html

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.