1. 程式人生 > >oracle在centos7中配置自啟動和遠端連線(plsql)

oracle在centos7中配置自啟動和遠端連線(plsql)

  • 先把幾個常見命令貼出來:
啟動監聽:lsnrctl start 
檢視監聽:lsnrctl status 
停止監聽:lsnrctl stop 

sqlplus "/as sysdba"
或者
sqlplus /nolog;
connect /as sysdba

然後輸入startup
就可以正常的啟動資料庫了。

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

oracle 遠端連線配置

我先把用到的命令都放在這了,如果整個安裝oracle都是沒有問題的,其實你就可以如下操作。說實話我是被網上的資料害慘了,各種改配置的,其實沒必要,我第二次安裝的時候發現其實並沒有那麼麻煩,就是如下幾步。

1、啟動監聽;lsnrctl start
2、開啟oracle連線
sqlplus /nolog;
connect /as sysdba
測試:
lsnrctl status
見到如下資訊就可以了
這裡寫圖片描述
3、oracle客戶端配置
找到這個位置
F:\dev\plsql developer\oracle\OraClient Lite\product\11.2.0\client_lite\network\admin
修改這個檔案
tnsnames.ora
目錄下其他的檔案可以不在意,我的那些都是空。

LISTENER_ORCL =
  (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168
.186.133)(PORT = 1521)) ORCL = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.186.133)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = ORCL) ) )

4、plsql 的配置

開啟plsql
點選cancel
接著配置如下 配置你的oracle_home,就是你oracle客戶端地址
這裡寫圖片描述
接著如下操作database有下拉選擇
這裡寫圖片描述


帳號和密碼填好後即可以使用了。

我以前也查了不少資料,很複雜,這也要那也要,但是我重灌oracle這次就是這麼簡單!

oracle自啟動配置

下面就是讓oracle在centos7中自啟動,其實就是將上面的監聽和oracle啟動一同寫到自啟動服務中。

1、鍵入如下命令

vi /etc/oratab

沒有oratab檔案的新增如下

#this file is used by ORACLE utilities.  It is created by root.sh
# and updated by the Database Configuration Assistant when creating
# a database.
# A colon, ':', is used as the field terminator.  A new line terminates
# the entry.  Lines beginning with a pound sign, '#', are comments.
#
# Entries are of the form:
#   $ORACLE_SID:$ORACLE_HOME:<N|Y>:
#
# The first and second fields are the system identifier and home
# directory of the database respectively.  The third filed indicates
# to the dbstart utility that the database should , "Y", or should not,
# "N", be brought up at system boot time.
#
# Multiple entries with the same $ORACLE_SID are not allowed.
#
ORCL:/usr/local/oracle/oracle/product/11.2.0/db_1:Y

2、鍵入命令“vi /etc/rc.d/rc.local”新增如下

su oracle -lc "/usr/local/oracle/oracle/product/11.2.0/db_1/bin/lsnrctl start"
su oracle -lc "/usr/local/oracle/oracle/product/11.2.0/db_1/bin/dbstart"

3、新建Oracle服務啟動指令碼

vi /etc/init.d/oracle

新建一個以oracle命名的檔案,新增如下

#!/bin/sh
# chkconfig: 345 61 61
# description: Oracle 11g R2 AutoRun Servimces
# /etc/init.d/oracle
#
# Run-level Startup script for the Oracle Instance, Listener, and
# Web Interface
export ORACLE_BASE=/usr/local/oracle/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_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
su $ORA_OWNR -lc $ORACLE_HOME/bin/dbstart
echo "Oracle Start Succesful!OK."
;;
stop)
# Oracle listener and instance shutdown
su $ORA_OWNR -lc $ORACLE_HOME/bin/dbshut
echo "Oracle Stop Succesful!OK."
;;
reload|restart)
$0 stop
$0 start
;;
*)
echo $"Usage: `basename $0` {start|stop|reload|reload}"
exit 1
esac
exit 0

切記不要少如下內容,否則chkconfig 不可使用

#!/bin/sh
# chkconfig: 345 61 61

4、增加 oracle服務控制指令碼執行許可權

 chmod +x /etc/rc.d/init.d/ oracle

5、將 oracle服務加入到系統服務

chkconfig --add  oracle

檢查 oracle服務是否已經生效

chkconfig --list  oracle

這裡寫圖片描述

啟動oracle

service oracle start

停止oracle服務

service oracle stop