ITPub博客

首页 > 数据库 > Oracle > EZCONNECT方式连接服务端

EZCONNECT方式连接服务端

原创 Oracle 作者:skyin_1603 时间:2016-11-03 22:41:13 0 删除 编辑
这里介绍一种比较方便的连接服务端的方式: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博客 ” ,链接:https://blog.itpub.net/31392094/viewspace-2127788/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: DBLINK
请登录后发表评论 登录
全部评论

注册时间:2016-09-06

  • 博文量
    231
  • 访问量
    215112