程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Oracle數據庫 >> Oracle教程 >> oracle監聽

oracle監聽

編輯:Oracle教程

oracle監聽


監聽分為動態注冊和靜態注冊   動態注冊:   oracle實例啟動之後通過pmon進程實時的把實例狀態和參數傳遞給listener,動態注冊可以不需要listener.ora文件和tnsnames.ora文件,數據庫一定在開啟的狀態     啟動數據庫:

[oracle@up admin]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 30 20:30:14 2015

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

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area  409194496 bytes
Fixed Size    2213856 bytes
Variable Size  293603360 bytes
Database Buffers  104857600 bytes
Redo Buffers    8519680 bytes
Database mounted.
Database opened.
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@up admin]$

 

查看監聽配置文件所在的目錄,沒有listener和tnsnames文件
[oracle@up admin]$ pwd
/u01/app/oracle/product/11.2.0/network/admin
[oracle@up admin]$ ls
listener.ora.old  samples  shrept.lst  sqlnet.ora  tnsnames.ora.old

 

啟動監聽:
[oracle@up admin]$ lsnrctl start

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 30-OCT-2015 20:32:41

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

Starting /u01/app/oracle/product/11.2.0/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Log messages written to /u01/app/oracle/diag/tnslsnr/up/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=up.oracle.com)(PORT=1521)))

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date                30-OCT-2015 20:32:42
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Log File         /u01/app/oracle/diag/tnslsnr/up/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=up.oracle.com)(PORT=1521)))
The listener supports no services
The command completed successfully
[oracle@up admin]$

 

  然後在客戶端登錄
[oracle@up admin]$ sqlplus scott/[email protected]/orcl

SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 30 21:21:29 2015

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


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL>

 

登錄成功。   靜態注冊   靜態注冊listener不知道數據庫的狀態,根據listener文件裡的配置來設置監聽 listener.ora文件內容如下:
[oracle@up admin]$ cat listener.ora 
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/network/admin/listener.ora
# Generated by Oracle configuration tools.

#LISTENER =
#  (DESCRIPTION_LIST =
#    (DESCRIPTION =
#      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
#      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.231.3)(PORT = 1521))
#    )
#  )

#ADR_BASE_LISTENER = /u01/app/oracle
SID_LIST_LISTENER = 
  (SID_LIST = 
    (SID_DESC =
      (GLOBAL_DBNAME = oracle)  
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0)
      (SID_NAME = oracle)
    )
  (SID_DESC =
      (GLOBAL_DBNAME = ora11g)  
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0)
      (SID_NAME = oracle)
    )
  )

 

listener文件中   global_dbname表示對外提供的服務名,需和tnsnames.ora文件中SERVICE_NAME的值一樣   ORACLE_HOME表示數據庫所在的位置   SID_NAME表示數據庫的SID   我的listener文件中sid為orcl的數據庫向外提供了兩個服務名,oracle和ora11g 客戶端登錄時可以用oracle,也可以用ora11g   tnsnames.ora文件內容如下:
[oracle@up admin]$ cat tnsnames.ora 
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.231.3)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = oracle)
    )
  )
ORA11G =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.231.3)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = ora11g)
    )
  )

 

tnsname文件中   HOST表示數據庫服務器的IP地址,或者數據庫服務器的主機名 端口號可以自己設定,但需要在數據庫中修改數據庫裡的參數,默認為1521 SERVICE_NAME的值必須和listener文件裡GLOBAL_DBNAME的值一致   啟動監聽
[oracle@up admin]$ lsnrctl start

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 30-OCT-2015 22:46:30

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

Starting /u01/app/oracle/product/11.2.0/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 11.2.0.1.0 - Production
System parameter file is /u01/app/oracle/product/11.2.0/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/up/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=up.oracle.com)(PORT=1521)))

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date                30-OCT-2015 22:46:30
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/11.2.0/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/up/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=up.oracle.com)(PORT=1521)))
Services Summary...
Service "ora11g" has 1 instance(s).
  Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
Service "oracle" has 1 instance(s).
  Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully

 

  出現有“Services ‘ora11g’ has 1 instance(s)......"這個信息時,表示監聽程序已經啟動成功了   使用客戶端登錄:
[oracle@up ~]$ sqlplus scott/[email protected]/oracle

SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 30 23:36:58 2015

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


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> 

 

  這是使用oracle登錄,然後使用ora11g登錄
[oracle@up ~]$ sqlplus scott/[email protected]/ora11g

SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 30 23:37:44 2015

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

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> 

 

使用ora11g也登錄成功

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved