EZCONNECT方式連線服務端

skyin_1603發表於2016-11-03
這裡介紹一種比較方便的連線服務端的方式:EZCONNECT 。
這種連線方式,只需要服務端配置監聽檔案就可以了,而不需要再客戶端配置tnsnames檔案的連線串。

---配置監聽:
[oracle@enmo admin]$ vi listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

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

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

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 03-NOV-2016 20:04:17
Copyright (c) 1991, 2013, Oracle.  All rights reserved.
Starting /u01/app/oracle/product/11.2.0/dbhome_1/bin/tnslsnr: please wait...
... ...
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date                03-NOV-2016 20:04:17
Uptime                    0 days 0 hr. 0 min. 38 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/enmo/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=enmo.oracle.com)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "PROD" has 1 instance(s).
  Instance "PROD", status READY, has 1 handler(s) for this service...
Service "PRODXDB" has 1 instance(s).
  Instance "PROD", status READY, has 1 handler(s) for this service...
The command completed successfully

--首先使用tnsnames方式作連線測試:
--使用連線串測試監聽:
ORA11GR2 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.6)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = PROD)
    )
  )

--串通服務機測試:
[oracle@host01 admin]$ tnsping ora11gr2

TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 03-NOV-2016 20:05:08
Copyright (c) 1997, 2013, Oracle.  All rights reserved.
Used parameter files:
/u01/app/oracle/product/11.2.0/dbhome_1/network/admin/sqlnet.ora

Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.6)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = PROD)))
OK (20 msec)
[oracle@host01 admin]$ 

--tnsping通後,連線服務機的資料庫測試:
[oracle@host01 admin]$ sqlplus sys/oracle@ora11gr2 as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Thu Nov 3 20:05:36 2016
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> 
SQL> show parameter service
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
service_names                        string      PROD
SQL> 
#連線成功。

---嘗試在另外一臺機進行EZCONNECT:
[oracle@host01 ~]$ sqlplus sys/oracle@192.168.2.6:1521/PROD as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Thu Nov 3 20:30:25 2016
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> 
SQL> show parameter service
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
service_names                        string      PROD

---在Windows的客戶端連線:

C:\Users\Asus>sqlplus sys/oracle@192.168.2.6:1521/PROD as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on 星期四 11月 3 22:00:41 2016
Copyright (c) 1982, 2010, Oracle.  All rights reserved.
連線到:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> show parameter service
NAME                                 TYPE
------------------------------------ ----------------------
VALUE
------------------------------
service_names                        string
PROD
SQL>
#都連線成功。
注意,一般情況下,在配置或者連線命令書寫無誤的情況下,若依然連線不到,則需要去配置sqlnet.ora檔案,
檔案所在的位置跟listener.ora檔案的路徑一樣在/u01/app/oracle/product/11.2.0/dbhome_1/network/admin。
[oracle@enmo admin]$ vi sqlnet.ora 
# sqlnet.ora Network Configuration File: /oracle/app/oracle/product/10.2.0/dbhome_1/network/admin/sqlnet.ora
# Generated by Oracle configuration tools.

NAMES.DIRECTORY_PATH= (TNSNAMES,EZCONNECT)

#此檔案明確遠端客戶端連線服務端的方式。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31392094/viewspace-2127788/,如需轉載,請註明出處,否則將追究法律責任。

相關文章