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
eg:
# sqlnet.ora Network Configuration File: D:oracleproduct10.2.0client_1NETWORKADMINsqlnet.ora
# Generated by Oracle configuration tools.
# This file is actually generated by netca. But if customers choose to
# install "Software Only", this file wont exist and without the native
# authentication, they will not be able to connect to the database on NT.
SQLNET.AUTHENTICATION_SERVICES= (NTS)
NAMES.DIRECTORY_PATH= (TNSNAMES, HOSTNAME)
2、配置服务器端的listener.ora
[oracle@linuxoracle admin]$ vi listener.ora
# LISTENER.ORA Network Configuration File: /u01/app/oracle/product/9.2.0/network/admin/listener.ora
# Generated by Oracle configuration tools.
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = linuxoracle)(PORT = 1521)) #注意HOST配置为主机名
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = linuxoracle) #注意GLOBAL_DBNAME为主机名
(ORACLE_HOME = /u01/app/oracle/product/9.2.0)
(SID_NAME = dg1)
)
(SID_DESC =
(GLOBAL_DBNAME = linuxoracle)
(ORACLE_HOME = /u01/app/oracle/product/9.2.0)
(SID_NAME = OEMREP)
)
)
说明:
如果没有正确配置GLOBAL_DBNAME,sqlplus连接时,会报如下错误:
C:Documents and Settings ew>sqlplus system/lijie123@linuxoracle
SQL*Plus: Release 10.2.0.1.0 - Production on 星期三 9月 19 17:31:52 2007
Copyright (c) 1982, 2005, Oracle. All rights reserved.
ERROR:
ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务
3、配置完后,sqlplus连接
Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.
C:Documents and Settings ew>sqlplus system/lijie123@linuxoracle
SQL*Plus: Release 10.2.0.1.0 - Production on 星期三 9月 19 17:19:48 2007
Copyright (c) 1982, 2005, Oracle. All rights reserved.
ERROR:
ORA-12154: TNS: 无法解析指定的连接标识符
报这样的错误,说明sqlplus不能正确解析linuxoracle,可能hosts或DNS的问题!!!
用记事本打开hosts
内容如下(省略了一部分):
..............................................................
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
127.0.0.1 localhost
修该为:
...............................................................
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
127.0.0.1 localhost
192.168.1.61 linuxoracle
4、sqlplus连接oracle服务器
C:Documents and Settings ew>sqlplus system/lijie123@linuxoracle
SQL*Plus: Release 10.2.0.1.0 - Production on 星期三 9月 19 18:37:51 2007
Copyright (c) 1982, 2005, Oracle. All rights reserved.
连接到:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
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增加下面这行:
NAMES.DIRECTORY_PATH=(EZCONNECT,TNSNAMES) #注意增加了EZCONNECT
oracle easy connect naming方法示例
eg:
connect scott/tiger@hostname:port/servicesname
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内容如下:
eg:
TEST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.61)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = dg1)
)
)
TEST为网络服务名,SERVICE_NAME为oracle的服务名