Linux

Oracle 客戶端拋出 ORA-12541: TNS:no listener

  • April 28, 2014

當我試圖連接我的遠端伺服器時-

sqlplus SYSTEM/oracle@192.168.0.171:1521/kannel

它向我顯示了這個錯誤-

SQL*Plus: Release 11.2.0.2.0 Production on Fri Nov 15 15:36:52 2013
copyright (c) 1982, 2010, Oracle.  All rights reserved.

ERROR:
ORA-12541: TNS:no listener

我檢查了我的監聽器,它正在執行

[root@roracle bin]# ./lsnrctl status

LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 15-NOV-2013 15:42:24

Copyright (c) 1991, 2011, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
TNS-12541: TNS:no listener
TNS-12560: TNS:protocol adapter error
TNS-00511: No listener
Linux Error: 111: Connection refused
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))
TNS-12541: TNS:no listener
TNS-12560: TNS:protocol adapter error
TNS-00511: No listener
Linux Error: 111: Connection refused

tnsnames.ora 文件包含 -

KANNEL =
(DESCRIPTION =
  (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
     (SERVER = DEDICATED)
     (SERVICE_NAME = kannel)
    )
)

listener.ora 文件包含

SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
  (GLOBAL_DBNAME = kannel)
  (ORACLE_HOME = /opt/u01/app/product/11.2.0/dbhome_1)
  (SID_NAME = kannel)
)
)

LISTENER=
(DESCRIPTION_LIST =
 (DESCRIPTION =
  (ADDRESS_LIST =
   (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
 )
  (ADDRESS_LIST =
   (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
  )
 )
)

sqlnet.ora 文件包含 -

SQLNET.AUTHENTICATION_SERVICES= (ALL)

NAMES.DIRECTORY_PATH= (TNSNAMES,ONAMES,HOSTNAME)

Oracle 主路徑 -

$ORACLE_HOME=/opt/u01/app/product/11.2.0/dbname_1

Oracle 基本路徑 -

$ORACLE_BASE=/opt/u01/app

我已經設置了環境變數

[root@roracle bin]# env | sort

}
_=/bin/env
CVS_RSH=ssh
G_BROKEN_FILENAMES=1
HISTCONTROL=ignoredups
HISTSIZE=1000
HOME=/root
HOSTNAME=roracle
LANG=en_IN
LESSOPEN=|/usr/bin/lesspipe.sh %s
LOADEDMODULES=
LOGNAME=root
LS_COLORS=rs=<......something........>:
MAIL=/var/spool/mail/root
module=() {  eval `/usr/bin/modulecmd bash $*`
MODULEPATH=/usr/share/Modules/modulefiles:/etc/modulefiles
MODULESHOME=/usr/share/Modules
OLDPWD=/root
ORACLE_BASE=/opt/u01/app/
ORACLE_HOME=/opt/u01/app/product/11.2.0/dbhome_1
ORACLE_SID=kannel
PATH=/usr/lib64/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
PWD=/opt/u01/app/product/11.2.0/dbhome_1/bin
QTDIR=/usr/lib64/qt-3.3
QTINC=/usr/lib64/qt-3.3/include
QTLIB=/usr/lib64/qt-3.3/lib
SHELL=/bin/bash
SHLVL=1
SSH_CLIENT=192.168.0.83 35604 22
SSH_CONNECTION=192.168.0.83 35604 192.168.0.171 22
SSH_TTY=/dev/pts/0
TERM=xterm
USER=root

當我以本地主機身份訪問數據庫時-

./sqlplus / as sysdba[oracle@roracle bin]$ ./sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Fri Nov 15 16:04:02 2013

Copyright (c) 1982, 2011, Oracle.  All rights reserved.

Connected to an idle instance.

SQL> select v$database;
select v$database
*
ERROR at line 1:
ORA-01034: ORACLE not available
Process ID: 0
Session ID: 0 Serial number: 0

我不明白我在哪裡弄錯了…..有人可以幫忙嗎?

會不會是您以 root 身份啟動了偵聽器程序?我可以看到您正在以 root 使用者身份嘗試 lsnrctl status,因此請確保您以 oracle 使用者身份啟動偵聽器程序,然後啟動數據庫(也以 Oracle 使用者身份)

此外,如果您收到“已連接到空閒實例”,這意味著您正在連接到未執行的實例,或者您為連接到要連接的實例設置了錯誤的環境。

確保路徑中有 Oracle 軟體目錄,例如 /u01/app/oracle/product/11.0/dbhome_1/bin

並將 ORACLE_SID 設置為數據庫實例名稱。

請以 oracle 使用者身份登錄並嘗試這些步驟。

設置你的 oracle 環境

$ . oraenv # note the dot!
$ <input your SID>

登錄並啟動。

$ sqlplus / as sysdba 
SQL>startup
SQL>exit;

啟動監聽器,確保數據庫註冊。

$ lsnrctl start
$ lsnrctl status

引用自:https://dba.stackexchange.com/questions/53380