Linux下oracle 12C自動啓動監聽及服務

oracle 數據庫開機自啓動sql

1:查看ORACLE_HOME是否設置

[oracle@ssy:~]$ echo $ORACLE_HOME  
/u01/app/oracle/product/12.1.0/dbhome_1數據庫

二、執行數據庫自帶啓動腳本dbstart   bash

[oracle@ssy ~]$ dbstart 

ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener
Usage: /u01/app/oracle/product/12.1.0/dbhome_1/bin/dbstart ORACLE_HOMEoracle

錯誤緣由是:dbstart和dbshut腳本文件中ORACLE_HOME_LISTNER的設置有問題。
 
三、編輯dbstart和dbshut腳本文件

sudo gedit /u01/app/oracle/product/12.1.0/dbhome_1/bin/dbstart
sudo gedit /u01/app/oracle/product/12.1.0/dbhome_1/bin/dbshutapp

將ORACLE_HOME_LISTNER=$1spa

修改成:ORACLE_HOME_LISTNER=$ORACLE_HOMErest

四、編輯oratab文件ip

sudo gedit /etc/oratabget

將orcl:/u01/app/oracle/product/12.1.0/dbhome_1:Nit

修改成:orcl:/u01/app/oracle/product/10.2.0/db_1:Y

五、編輯listener.ora文件

添加以下內容
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME = /u01/app/oracle/product/12.1.0/dbhome_1)
(SID_NAME = orcl)
)
)

六、設置開機自啓動

方法一:建立自啓動腳本

一、建立oracle文件

sudo gedit /etc/rc.d/init.d/oracle

編寫以下內容

==============================================================================

#!/bin/bash
# chkconfig: 345 99 10
# description: Startup Script for Oracle Databases
# /etc/rc.d/init.d/oracle
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/12.1.0/dbhome_1
export ORACLE_SID=orcl
export PATH=$PATH:$ORACLE_HOME/bin
ORA_OWNR="oracle" 

# if the executables do not exist -- display error
if [ ! -f $ORACLE_HOME/bin/dbstart -o ! -d $ORACLE_HOME ]
then
echo "Oracle startup: cannot start"
exit 1
fi
# depending on parameter -- startup, shutdown, restart
# of the instance and listener or usage display
case "$1" in
start)
# Oracle listener and instance startup
echo -n "Starting Oracle: "
su - $ORA_OWNR -c "$ORACLE_HOME/bin/dbstart"
su - $ORA_OWNR -c "$ORACLE_HOME/bin/lsnrctl start"
touch /var/lock/Oracle
su - $ORA_OWNR -c "$ORACLE_HOME/bin/emctl start dbconsole"
#su - $ORA_OWNR -c "$ORACLE_HOME/bin/isqlplusctrl start"
echo "OK"
;;
stop)
# Oracle listener and instance shutdown
echo -n "Shutdown Oracle: "
su - $ORA_OWNR -c "$ORACLE_HOME/bin/emctl stop dbconsole"
#su - $ORA_OWNR -c "$ORACLE_HOME/bin/isqlplusctrl stop"
su - $ORA_OWNR -c "$ORACLE_HOME/bin/dbshut"
su - $ORA_OWNR -c "$ORACLE_HOME/bin/lsnrctl stop"
rm -f /var/lock/Oracle
echo "OK"
;;
reload|restart)
$0 stop
$0 start
;;
*)
echo "Usage: `basename $0` start|stop|restart|reload"
exit 1
esac
exit 0

==============================================================================

二、更改oracle文件權限

ls -l | grep oracle

-rw-r--r-- 1 root root  1311 3月  13 21:07 oracle

sudo chmod +x oracle

ls -l | grep oracle

-rwxr-xr-x 1 root root  1311 3月  13 21:07 oracle

三、更新系統服務的運行級

sudo apt-get install sysv-rc-conf
sudo cp /usr/sbin/sysv-rc-conf /usr/sbin/chkconfig
sudo chkconfig --level 2345 oracle on

[oracle@ssy:/etc/rc.d/init.d]$ ./oracle
Usage: oracle start|stop|restart|reload
[oracle@ssy:/etc/rc.d/init.d]$ cd /etc/rc.d/rc5.d/
[oracle@ssy:/etc/rc.d/rc5.d]$ ls -l | grep oracle
lrwxrwxrwx 1 root root 16 3月 13 21:25 S20oracle -> ../init.d/oracle

方法二:編輯rc.local啓動文件

sudo gedit /etc/rc.d/rc.local

文件末尾添加以下兩行

su - oracle -lc /u01/app/oracle/product/12.1.0/dbhome_1/bin/dbstart
su - oracle -lc "/u01/app/oracle/product/12.1.0/dbhome_1/bin/lsnrctl start"
注意:第二個命令有空格,因此要用引號

七、重啓主機,查看數據庫和監聽是否自啓動

ps -ef | grep orcl
lsnrctl status
ps -ef | grep LISTEN | grep -v grep

相關文章
相關標籤/搜索