监听器是Oracle基于服务器端的一种网络服务,主要用于监听客户端向数据库服务器端提出的连接请求。既然是基于服务器端的服务,那么它也只存在于数据库服务器端,进行监听器的设置也是在数据库服务器端完成的。
二、本地服务名(Tnsname)
Oracle客户端与服务器端的连接是通过客户端发出连接请求,由服务器端监听器对客户端连接请求进行合法检查,如果连接请求有效,则进行连接,否则拒绝该连接。
本地服务名是Oracle客户端网络配置的一种,另外还有Oracle名字服务器(Oracle Names Server)等。Oracle常用的客户端配置就是采用的本地服务名,本文中介绍的也主要是基于本地服务名的配置。
三、Oracle网络连接配置方法
配置Oracle服务器端与客户端都可以在其自带的图形化Oracle网络管理器(Oracle Net Manager)里完成(强烈建议在这个图形化的工具下完成Oracle服务端或客户端的配置)。在Windows下,点击“开始/程序/Oracle - OraHome92/Configuration and Migration Tools/Net Manager”启动Oracle网络管理器工具,在Linux/Unix下,利用netmgr命令来启动图形化Oracle网络管理器,如:$ netmgr。
四、客户端连接服务器端常见问题排除方法
要排除客户端与服务器端的连接问题,首先检查客户端配置是否正确(客户端配置必须与数据库服务器端监听配置一致),再根据错误提示解决。下面列出几种常见的连接问题:
1、 ORA-12541: TNS: 没有监听器:
显而易见,服务器端的监听器没有启动,另外检查客户端IP地址或端口填写是否正确。启动监听器:
$ lsnrctl start或C:\lsnrctl start。
2、 ORA-12500: TNS: 监听程序无法启动专用服务器进程:
对于Windows而言,没有启动Oracle实例服务。启动实例服务:C:\oradim –startup -sid myoracle。
3、 ORA-12535: TNS: 操作超时:
出现这个问题的原因很多,但主要跟网络有关。解决这个问题,首先检查客户端与服务端的网络是否畅通,如果网络连通,则检查两端的防火墙是否阻挡了连接。
4、 ORA-12154: TNS: 无法处理服务名:
检查输入的服务名与配置的服务名是否一致。另外注意生成的本地服务名文件(Windows下如D:\oracle\ora92\network\admin \tnsnames.ora,Linux/Unix下$ORACLE_HOME/network/admin/tnsnames.ora)里每项服务的首行服务名称前不能有空格。
5、 ORA-12514: TNS: 监听进程不能解析在连接描述符中给出的 SERVICE_NAME打开Net Manager,选中服务名称,检查服务标识栏里的服务名输入是否正确。该服务名必须与服务器端监听器配置的全局数据库名一致。
6、 Windows下启动监听服务提示找不到路径:
用命令或在服务窗口中启动监听提示找不到路径,或监听服务启动异常。打开注册表,进入HKEY_LOCAL_MACHINE/SYSTEM/Current ControlSet/Services/OracleOraHome92TNSListener项,查看ImagePath字符串项是否存在,如果没有,设定值为D:\oracle\ora92\BIN\TNSLSNR,不同的安装路径设定值做相应的更改。这种方法同样适用于Oracle实例服务,同上,找到如同HKEY_LOCAL_MACHINE/SYSTEM/Current ControlSet/Services/Oracle ServiceMYORACLE项,查看ImagePath字符串项是否存在,如果没有,则新建,设定值为d:\oracle\ora92\ binORACLE.EXE MYORACLE。
专用服务器:一个客户端连接对应一个服务器进程共享服务器:多个客户端连接对应一个服务器进程,服务器端存在一个进程调度器来管理。
判断oracle是共享模式还是专用模式用以下方法:
show
parameter
shared_server
如果数值>
0
,就是enable了共享服务器。
如何启用Oracle Shared Server
在某些应用中共享服务器还是有独特的优势的,从官方描述中可以看到如下优势:
减少实例进程的数目
增加对外服务的用户数目
减少无用或者空闲服务器的进程数目
减少oracle数据库对内存占用和os的开销
实现负载平衡
相对于专有服务器模式,一个比较重要的区别是共享服务器要求使用net services来连接,即使用户经常和服务器进程在同一台机器上也是如此。
但是在某些情况下必须使用专用服务器:比如使用sysdba登陆进行管理操作的时候。
当然,要使用这两种不同的模式,重要的还是在服务器进行配置后还要在客户端的连接串配置有所体现
专用服务器连接---(SERVER = DEDICATED)
共享服务器连接---(SERVER = SHARED)
那么如何配置共享服务器呢?有两个参数是必须的:
DISPATCHERS
SHARED_SERVERS
可选择配置的参数:
MAX_DISPATCHERS
MAX_SHARED_SERVERS
CIRCUITS
SHARED_SERVER_SESSIONS
大部分情况下我们只要修改DISPATCHERS即可,我们先看下默认的专用服务器情况下参数:
[oracle@test ~]$ sqlplus "/as sysdba"
SQL*Plus: Release 10.2.0.5.0 - Production on Tue Aug 14 15:04:26 2012
Copyright (c) 1982, 2010, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
sys@GT10G>select * from v$version
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Prod
PL/SQL Release 10.2.0.5.0 - Production
CORE10.2.0.5.0Production
TNS for Linux: Version 10.2.0.5.0 - Production
NLSRTL Version 10.2.0.5.0 - Production
sys@GT10G>show parameter disp
NAME TYPE VALUE
------------------------------------ -------- ------------------------------
dispatchers string (PROTOCOL=TCP) (SERVICE=gt10gXDB)
max_dispatchers integer
共享服务器和专用服务器还可以从监听程序的信息体现出来,我们先记录下修改之前的专用服务器的监听状态和信息:
[oracle@test ~]$ lsnrctl status
LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 14-AUG-2012 15:03:32
Copyright (c) 1991, 2010, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=test)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 10.2.0.5.0 - Production
Start Date14-AUG-2012 14:52:08
Uptime0 days 0 hr. 11 min. 24 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/oracle/10g/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File /u01/oracle/10g/product/10.2.0/db_1/network/log/listener.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=test)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "gt10g" has 1 instance(s).
Instance "gt10g", status READY, has 1 handler(s) for this service...
Service "gt10gXDB" has 1 instance(s).
Instance "gt10g", status READY, has 1 handler(s) for this service...
Service "gt10g_XPT" has 1 instance(s).
Instance "gt10g", status READY, has 1 handler(s) for this service...
The command completed successfully
[oracle@test ~]$ lsnrctl service
LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 14-AUG-2012 15:03:39
Copyright (c) 1991, 2010, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=test)(PORT=1521)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0
LOCAL SERVER
Service "gt10g" has 1 instance(s).
Instance "gt10g", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0 state:ready
LOCAL SERVER
Service "gt10gXDB" has 1 instance(s).
Instance "gt10g", status READY, has 1 handler(s) for this service...
Handler(s):
"D002" established:0 refused:0 current:0 max:1022 state:ready
DISPATCHER <machine: test, pid: 18635>
(ADDRESS=(PROTOCOL=tcp)(HOST=test)(PORT=47446))
Service "gt10g_XPT" has 1 instance(s).
Instance "gt10g", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0 state:ready
LOCAL SERVER
The command completed successfully
现在我们要设置一下共享服务器,这里我们只要设置DISPATCHERS参数:
sys@GT10G>alter system set DISPATCHERS = "(PROTOCOL=TCP)(DISPATCHERS=3)(PROTOCOL=IPC)(DISPATCHERS=1)"
System altered.
我们首先从监听状态和信息来看下前后的不同:
[oracle@test ~]$ lsnrctl status
LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 14-AUG-2012 15:07:37
Copyright (c) 1991, 2010, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=test)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 10.2.0.5.0 - Production
Start Date14-AUG-2012 14:52:08
Uptime0 days 0 hr. 15 min. 28 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/oracle/10g/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File /u01/oracle/10g/product/10.2.0/db_1/network/log/listener.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=test)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "gt10g" has 1 instance(s).
Instance "gt10g", status READY, has 2 handler(s) for this service...
Service "gt10gXDB" has 1 instance(s).
Instance "gt10g", status READY, has 1 handler(s) for this service...
Service "gt10g_XPT" has 1 instance(s).
Instance "gt10g", status READY, has 2 handler(s) for this service...
The command completed successfully
[oracle@test ~]$ lsnrctl service
LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 14-AUG-2012 15:09:22
Copyright (c) 1991, 2010, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=test)(PORT=1521)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0
LOCAL SERVER
Service "gt10g" has 1 instance(s).
Instance "gt10g", status READY, has 2 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0 state:ready
LOCAL SERVER
"D000" established:0 refused:0 current:0 max:1022 state:ready
DISPATCHER <machine: test, pid: 19006>
(ADDRESS=(PROTOCOL=ipc)(KEY=#19006.1))
Service "gt10gXDB" has 1 instance(s).
Instance "gt10g", status READY, has 1 handler(s) for this service...
Handler(s):
"D002" established:0 refused:0 current:0 max:1022 state:ready
DISPATCHER <machine: test, pid: 18635>
(ADDRESS=(PROTOCOL=tcp)(HOST=test)(PORT=47446))
Service "gt10g_XPT" has 1 instance(s).
Instance "gt10g", status READY, has 2 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0 state:ready
LOCAL SERVER
"D000" established:0 refused:0 current:0 max:1022 state:ready
DISPATCHER <machine: test, pid: 19006>
(ADDRESS=(PROTOCOL=ipc)(KEY=#19006.1))
The command completed successfully
比较下可以看到最大的变化就是共享服务器在监听信息中体现出了调度进程"D000"。
接下来我们通过修改tnsname配置参数来实际连接,再通过视图可以看到我们已经有一个共享模式连接到服务器了:
GT10G4 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.4)(PORT = 1521))
(CONNECT_DATA =
(SERVER = SHARED) #重点在这里
(SERVICE_NAME = gt10g)
)
)
sys@GT10G>Select Count(*) From V$CIRCUIT
COUNT(*)
----------
1
那么,如果我们没有配置共享服务模式的参数,但是客户端配置了使用共享模式连接,会是什么结果呢?
alter system set DISPATCHERS="(PROTOCOL=TCP) (SERVICE=gt10gXDB)"
alter system reset DISPATCHERS scope=spfile sid='*'
尝试了上述两条语句发现还是无法恢复内存中的参数值,只好重启数据库,发现还是不行,后来搜索了下发现直接清空即可:
sys@GT10G>alter system set dispatchers='' scope=both
System altered.
sys@GT10G>show parameter disp
NAME TYPE VALUE
------------------------------------ -------- ------------------------------
dispatchers string
max_dispatchers integer
这个时候在客户端继续尝试用共享模式连接会发现报错了:
C:\Users\Administrator>sqlplus gtlions/gtlions@gt10g4
SQL*Plus: Release 10.2.0.1.0 - Production on 星期二 8月 14 15:41:14 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
ERROR:
ORA-12520: TNS: 监听程序无法为请求的服务器类型找到可用的处理程序
-The End-
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)