Listener

来源:互联网 发布:loop细分曲面算法 编辑:程序博客网 时间:2024/05/01 07:38
Oracle Net Service

1.要先确认client端安装了oracle client,并且clinet 能够和server端能够通信.

2.listener 的版本必须和数据库的版本一样或者比数据库版本更新。

listener配置文件位置

$ORACLE_HOME/network/admin/listener.ora

RAC cluster or single node 的listener文件拥有者是grid。

动态注册-不需要对listener.ora文件有任何配置

静态注册-要求有SID_LIST_listener_name存在,如果用oem管理数据库的这个参数也是必须要的。

SID_LIST_LISTENER=  (SID_LIST=    (SID_DESC=      (SID_NAME=plsextproc)      (ORACLE_HOME=/oracle11g)      (PROGRAM=extproc)))
静态注册:

SID:instance_name

service_name:global_dbname:当处理客户请求时,listener试着同客户端配置连接描述符定义的service_name比对。如果客户端的用的是SID,listener就不会比对。

oracle_home:实例的家目录,如果不定义,listener默认oracle_home为实例的家目录。

The following example shows an excerpt of a listener.ora file statically configured for a database service calledsales.us.example.com:

SID_LIST_listener=(SID_LIST= (SID_DESC=  (GLOBAL_DBNAME=sales.us.example.com)  (SID_NAME=sales)  (ORACLE_HOME=/u01/app/oracle/11g)))

Important:

If you are using connect-time failover orTransparent Application Failover (TAF), such as in an Oracle Real Application Clusters environment, then do not set theGLOBAL_DBNAME parameter.


[oracle@julia01 admin]$ lsnrctl statusLSNRCTL for Linux: Version 11.2.0.1.0 - Production on 20-MAR-2013 22:11:56Copyright (c) 1991, 2009, Oracle.  All rights reserved.Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))STATUS of the LISTENER

lsnrctl

>start   listener_name

listener_name 是listener.ora文件列出的listener名字。如果是使用默认的listener就不需要指定 默认使用LISTENER

确认数据库 已经完成服务注册。

lsnrctl>service [listener_name]

客户端连接:

easy connect to connect to a database

CONNECT username/password@host[:port][/service_name][:server][/instance_name]


[oracle@julia01 ~]$ sqlplus scott/julia033@//9.115.17.92:1521/orcl SQL*Plus: Release 11.2.0.1.0 Production on Wed Mar 20 04:27:40 2013Copyright (c) 1982, 2009, Oracle.  All rights reserved.Connected to:Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - ProductionWith the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,Data Mining and Real Application Testing options

LSNRCTL> serviceConnecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))Services Summary...Service "+ASM" has 1 instance(s).  Instance "+ASM1", status READY, has 1 handler(s) for this service...    Handler(s):      "DEDICATED" established:0 refused:0 state:ready         LOCAL SERVERService "orcl" has 1 instance(s).  Instance "orcl1", status READY, has 1 handler(s) for this service...    Handler(s):      "DEDICATED" established:3 refused:0 state:ready         LOCAL SERVERService "orclXDB" has 1 instance(s).  Instance "orcl1", status READY, has 1 handler(s) for this service...    Handler(s):      "D000" established:0 refused:0 current:0 max:1022 state:ready         DISPATCHER <machine: juliaz2, pid: 13594>         (ADDRESS=(PROTOCOL=tcp)(HOST=juliaz2)(PORT=60749))The command completed successfully

如果一个instance 的status是unknow 说明这个实例是静态注册到listener.ora文件中,所以状态是unknow

Service "XXXXXXXXXXXXXXXX" has 1 instance(s).  Instance "XXXXXXXX", status UNKNOWN, has 1 handler(s) for this service...    Handler(s):      "DEDICATED" established:2 refused:0         LOCAL SERVER

一个数据库可以提供多个服务,这样做的好处是:

一个单一的数据库可以不同的方式呈现给不同的用户。

能够更好的限制资源,可以限制请求某个某个服务的资源。

DBMS_SERVICE package can also be used to create services


To connect to a database service, clients use a connect descriptor that provides the location of the database and the name of the database service. The following example is an Easy Connect descriptor that connects to a database service named sales.us.example.com, and the host sales-server (the port is 1521 by default):

sales-server/sales.us.example.com

[oracle@julia01 ~]$ sqlplus scott/julia033@//9.115.17.92:1521/orcl 

制定service_name 在client端

The following example shows the tnsnames.ora entry for the preceding Easy Connect connect descriptor and database service:

通过(service_name=sales.us.example.com)指定客户端要连接的服务名称。

(DESCRIPTION=  (ADDRESS=(PROTOCOL=tcp)(HOST=sales-server)(PORT=1521))  (CONNECT_DATA=    (SERVICE_NAME=sales.us.example.com)))


Specifying an Instance Name

指定要连接的instance的name,如果你的环境的cluster的话,有多个实例。

通过指定(instance_name=sales1),指定客户端需要连接的instance。

(DESCRIPTION=  (ADDRESS=(PROTOCOL=tcp)(HOST=sales-server)(PORT=1521))  (CONNECT_DATA=    (SERVICE_NAME=sales.us.example.com)    (INSTANCE_NAME=sales1)))

Specifying a Service Handler

指定service handler

没有指定的情况下,默认选择share,然后dedicate

通过指定(server=shared),客户端要求连接shared service handler.

(DESCRIPTION=  (ADDRESS=(PROTOCOL=tcp)(HOST=sales-server)(PORT=1521))  (CONNECT_DATA=    (SERVICE_NAME=sales.us.example.com)     (SERVER=shared)))

当llistener接受到client发来的请求时,listener选择已经注册了的service handler 来处理客户请求,根据选择的handler的类型(shared/dedicate),通信协议,数据库的操作系统,listener会做一下几件事情:

.把客户请求直接递交给dispatcher

.把dispatcher 和dedicated server 进程的位置返回给client,然后clinet就会直接与dispatcher 和dedicated server process通信。

.listener生成(spawn的意思就是产卵)确实是生成一个dedicate server ,把client请求递交给这个dedicate server process。

listener做完以上的事情以后,client就直接与oracle database 通信了(其实是通过service handler啦),listener不参与这个通信过程。

listener继续监听客户端发来的连接请求。


关于dispatchers

The shared server architecture uses a dispatcher process to direct client connections to a common request queue. An idle shared server process from a shared pool of server processes picks up a request from the common queue. This approach enables a small pool of server processes to serve a large number of clients. A significant advantage of the shared server model over the dedicated server model is reduced system resources, enabling support of an increased number of users.

he listener uses the dispatcher as a type of service handler to which it can direct client requests. When a client request arrives, the listener performs one of the following actions:

  • Hands the connection request directly to a dispatcher.

  • Issues a redirect message to the client, containing the protocol address of a dispatcher. The client then terminates the network session to the listener and establishes a network session to the dispatcher, using the network address provided in the redirect message.

About Dedicated Server Processes

In a dedicated server configuration, the listener starts a separate dedicated server process for each incoming client connection request dedicated to servicing the client. After the session is complete, the dedicated server process terminates. Because a dedicated server process has to be started for each connection, this configuration may require more system resources than shared server configurations.

A dedicated server process is a type of service handler that the listener starts when it receives a client request. To complete a client/server connection, one of the following actions occurs:

  • The dedicated server inherits the connection request from the listener.

  • The dedicated server informs the listener of its listening protocol address. The listener passes the protocol address to the client in a redirect message and terminates the connection. The client connects to the dedicated server directly using the protocol address.



服务注册 :使listener决定一个数据库服务和他的服务句柄是不是可用 。

服务句柄 :专一的服务器进程用来 与数据库连接 .

service handler -----客户进程是不能直接与数据库打交道的,必须通过这个中间进程来操作数据库。

在服务注册阶段,PMON进程把实例名称,数据库服务名,类型,服务句柄地址提动给listener .  listener能够根据这些信息,当有client request时,启动相应的service handler 。

服务名 service names
服务名是一个或者多个实例的组合,service name 是一个逻辑名称,代表数据库提供的一种服务用来处理client发来的请求。

       当一个client向listener发来请求,它请求的是某个服务。当数据库的实例启动时,数据库会把自己提供的服务的服务名注册到listener。listener 就知道后台数据库能够提供什么服务,当有clinet发来请求时,listener就把这个请求转交给相应的service handler .

listener 就是一个传话的,client说它要找谁办什么事,listener就去把那个人喊来接待这个clinet,前提找的人(service name)要存在,然后listener就去招呼下一个clinet。

这个是在专有服务器模式下的工作方式。

服务注册 :
PMON在启动的时候,把实例的信息注册到listener中,这样listener才能把客户的请求发向正确的service handler(专门负责与数据库的连接)。
PMON为listener提供了一下信息:
     .数据库提供的服务的名称
     .服务所在的实例的名称,和它现在的负载和能承受的最大负载
     .实例可用的service handler(专有服务器和共享服务器),她们的类型,协议地址,现在负载和能承受的最大负载

这种注册是PMON自动完成的, 不需要配置listener.ora文件。 动态注册减少了管理多个数据库或实例的工作量。
初始化参数service_name 列出了实例所提供的服务。

         每个listener 通过配置有一个或者多个协议地址来指定它监听的终点。协议address: 用来指定listener监听的的协以及和协议相关的具体信息。

(DESCRIPTION=
   (ADDRESS=(PROTOCOL=tcp)(HOST=sales-server)(PORT=1521)))
这个例子,通过一个tcp/ip地址来指定listener监听的server(sales_server)以及端口号(1521)

Oracle Restart

         在单实例环境中,增加数据库可用性,使用srvctl工具,可以添加组件,例如listener到Oracle Restart configuration 。这个配置能够使listener 在fail 后自动重启。

 使用oracle restart,需要注意以下:

        .使用srvctl工具来启动和停止Listener,不要使用listener control,lsnrclt 工具

        .每个linstener必须有唯一的名字。

Block Connection Request

       发生在当一个请求来时,相应的实例还没有注册,或者数据库在restricted mode,例如:正在shutdown . 这种情况下,PMON会指示listener block对这个实例所有的所有连接请求。试图连接的client将会收到一下错误信息:

  • ORA-12526: TNS:listener: all appropriate instances are in restricted mode

  • ORA-12527: TNS:listener: all appropriate instances are in restricted mode or blocking new connections

  • ORA-12528: TNS:listener: all appropriate instances are blocking new connections

最后一个错误信息,说明实例还没有注册到listener中。

原创粉丝点击