深入探讨Oracle网络服务解析

数据库 Oracle
就目前网络上出现的有关“Oracle网络服务解析”的疑问,我归纳总结了5种有效的方法,希望能帮助到大家。

近来,浏览BBS时,常看到“Oracle网络服务解析”的疑问,针对以上这类问题,我归纳总结了5种常用的方法。具体如下:
1、Oracle Internet Directory
2、External Naming
3、主机命名
4、Oracle Easy Connect
5、本地命名

下面分别介绍这五种方法:
第一种:Oracle Internet Directory管理复杂的Oracle网络服务器时有优势,管理员可以在一个比较集中位置配置和管理Net Service Names
第二种:External Naming 使用非Oracle工具管理和解析Oracle网络服务名称
第三种:主机命名方法(客户端为windows xp,服务器端为linux+oracle 9i)

1、配置客户端的sqlnet.ora

  1. # sqlnet.ora Network Configuration File: D:oracleproduct10.2.0client_1NETWORKADMINsqlnet.ora  
  2. # Generated by Oracle configuration tools.  
  3. # This file is actually generated by netca. But if customers choose to   
  4. # install "Software Only", this file wont exist and without the native   
  5. # authentication, they will not be able to connect to the database on NT.  
  6. SQLNET.AUTHENTICATION_SERVICES= (NTS)  
  7. NAMES.DIRECTORY_PATH= (TNSNAMES, HOSTNAME)  
  8.  

2、配置服务器端的listener.ora

  1. [oracle@linuxoracle admin]$ vi listener.ora  
  2. # LISTENER.ORA Network Configuration File: /u01/app/oracle/product/9.2.0/network/admin/listener.ora  
  3. # Generated by Oracle configuration tools.  
  4. LISTENER =  
  5. (DESCRIPTION =  
  6. (ADDRESS = (PROTOCOL = TCP)(HOST = linuxoracle)(PORT = 1521)) #注意HOST配置为主机名  
  7. )  
  8. SID_LIST_LISTENER =  
  9. (SID_LIST =  
  10. (SID_DESC =  
  11. (GLOBAL_DBNAME = linuxoracle) #注意GLOBAL_DBNAME为主机名  
  12. (ORACLE_HOME = /u01/app/oracle/product/9.2.0)  
  13. (SID_NAME = dg1)  
  14. )  
  15. (SID_DESC =  
  16. (GLOBAL_DBNAME = linuxoracle)  
  17. (ORACLE_HOME = /u01/app/oracle/product/9.2.0)  
  18. (SID_NAME = OEMREP)  
  19. )  
  20. )  
  21.  

说明:
如果没有正确配置GLOBAL_DBNAME,sqlplus连接时,会报如下错误:

  1. C:Documents and Settings ew>sqlplus system/lijie123@linuxoracle  
  2. SQL*Plus: Release 10.2.0.1.0 - Production on 星期三 9月 19 17:31:52 2007  
  3. Copyright (c) 1982, 2005, Oracle. All rights reserved.  
  4. ERROR:  
  5. ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务  
  6.  

3、配置完后,sqlplus连接
Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.

  1. C:Documents and Settings ew>sqlplus system/lijie123@linuxoracle  
  2. SQL*Plus: Release 10.2.0.1.0 - Production on 星期三 9月 19 17:19:48 2007  
  3. Copyright (c) 1982, 2005, Oracle. All rights reserved.  
  4. ERROR:  
  5. ORA-12154: TNS: 无法解析指定的连接标识符  
  6.  

报这样的错误,说明sqlplus不能正确解析linuxoracle,可能hosts或DNS的问题!!!
用记事本打开hosts
内容如下(省略了一部分):

  1. ..............................................................  
  2. # 102.54.94.97 rhino.acme.com # source server  
  3. # 38.25.63.10 x.acme.com # x client host  
  4. 127.0.0.1 localhost  
  5. 修该为:  
  6. ...............................................................  
  7. # 102.54.94.97 rhino.acme.com # source server  
  8. # 38.25.63.10 x.acme.com # x client host  
  9. 127.0.0.1 localhost  
  10. 192.168.1.61 linuxoracle  

4、sqlplus连接oracle服务器#p#

  1. C:Documents and Settings ew>sqlplus system/lijie123@linuxoracle  
  2. SQL*Plus: Release 10.2.0.1.0 - Production on 星期三 9月 19 18:37:51 2007  
  3. Copyright (c) 1982, 2005, Oracle. All rights reserved.  
  4.  

连接到:

  1. Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production  
  2. With the Partitioning, OLAP and Oracle Data Mining options  
  3. JServer Release 9.2.0.4.0 - Production  

SQL>
成功!!!

第四种:Oracle Easy Connect
只在oracle 10g以上版本使用
Oracel Easy Connect Naming
使用oracle easy connect naming必须满足以下要求
1、oracle net services 10g必须安装在客户端
2、客户端及服务器端必须支持TCP/IP,并启用
3、不允许高级连接描述符特性,如:连接池、外部过程调用
配置oracle easy connect naming
在sqlnet.ora增加下面这行:

  1. NAMES.DIRECTORY_PATH=(EZCONNECT,TNSNAMES) #注意增加了EZCONNECT  

oracle easy connect naming方法示例
eg:

  1. connect scott/tiger@hostname:port/servicesname  
  2. connect scott/tiger@//hostname/servicesname  

解释:
语法构件 描述
// 任选:通过URL连接时使用
hostname 必选: 主机名或IP
port 任选:端口号
servicesname 必选:oracle网络服务的名称

第五种:本地命名法
本地命名方法也被称为tnsnames.ora方法
可用Oracle net manager配置本地命名方法(当然也可以用OEM)
打开Oracle net manager,在Local选项中选择Service Naming进行添加,添加好的tnsnames.ora内容如下:

  1. eg:  
  2. TEST =  
  3. (DESCRIPTION =  
  4. (ADDRESS_LIST =  
  5. (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.61)(PORT = 1521))  
  6. )  
  7. (CONNECT_DATA =  
  8. (SERVICE_NAME = dg1)  
  9. )  
  10. )  
  11. TEST为网络服务名,SERVICE_NAME为oracle的服务名 

以上就探讨了些Oracle网络服务一般常用的解析方法,要想了解的更多相关问题的解决方案,请留意51cto.com站上的相关论坛。

【编辑推荐】

  1. Oracle性能诊断不能不知的秘籍
  2. Oracle 10g归档日志
  3. Windows2000服务器下安装Oracle9i与10g
  4. Oracle多表查询优化的代码示例
  5. Oracle更改的默认端口号剖析
责任编辑:佚名
相关推荐

2009-11-20 17:17:08

Oracle函数索引

2009-12-23 16:13:00

WPF Attache

2010-07-21 09:38:15

PHP缓存技术

2010-11-22 14:18:32

MySQL锁机制

2021-05-17 05:36:02

CSS 文字动画技巧

2015-09-02 08:57:56

JavaHashMap工作原理

2011-02-25 09:23:00

Java类加载器

2009-08-27 11:27:58

foreach语句C# foreach语

2010-03-05 13:44:00

Python序列

2023-01-12 17:18:06

数据库多云

2010-03-31 14:58:03

云计算

2009-10-16 09:17:39

屏蔽布线系统

2009-12-07 13:55:58

PHP array_m

2009-12-07 16:07:03

PHP类的继承

2017-01-03 17:57:46

Android异步精髓Handler

2009-11-12 13:56:54

2024-01-26 06:42:05

Redis数据结构

2013-07-11 09:45:48

扁平化扁平化设计

2009-12-11 11:08:31

静态路由策略

2009-12-14 14:40:10

Ruby全局域变量
点赞
收藏

51CTO技术栈公众号