在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/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
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. 開機自啟動
代碼如下: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
代碼如下:d. service oracle restart
代碼如下:至此,Oracle服務啟動&停止腳本與開機自啟動設置完畢。