Oracle Net Listener

$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 21-SEP-2018 03:29:08

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=su)(PORT=1521)))

STATUS of the LISTENER

------------------------

Alias                     LISTENER

Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production

Start Date                21-SEP-2018 03:28:50

Uptime                    0 days 0 hr. 0 min. 18 sec

Trace Level                off

Security                  ON: Local OS Authentication

SNMP                    OFF

Listener Parameter File   /oracle/product/11.2.0/dbhome_1/network/admin/listener.ora

Listener Log File         /oracle/diag/tnslsnr/su/listener/alert/log.xml

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=su)(PORT=1521)))

  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXPROC0)))

Services Summary...

Service "B" has 1 instance(s).

  Instance "INSTANCE_TEST", status READY, has 1 handler(s) for this service...

Service "C" has 1 instance(s).

  Instance "INSTANCE_TEST", status READY, has 1 handler(s) for this service...

Service "ORCL" has 2 instance(s).

  Instance "INSTANCE_TEST", status READY, has 1 handler(s) for this service...

  Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...

Service "PLSExtProc" has 1 instance(s).

  Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...

Service "orclXDB" has 1 instance(s).

  Instance "INSTANCE_TEST", status READY, has 1 handler(s) for this service...

The command completed successfully

Lsnrctl status显示分为两部分:监听的参数配置以及服务信息,服务信息包括服务名及对应的实例,status为unknown表示为静态注册,其它状态为动态注册

监听服务状态包括:

READY means that the instance can accept connections.

BLOCKED means that the instance cannot accept connections.

READY/SECONDARY means that this is a secondary instance in an Oracle Real Application Clusters primary/secondary configuration, and is ready to accept connections.

RESTRICTED means the instance is in restricted mode. The listener blocks all connections to this instance.

UNKNOWN means that the instance is registered statically in the listener.ora file rather than dynamically with service registration. Therefore, the status is not known.

Dynamic Service Registration

动态注册进程11g还是pmon,12c变为LREG进程了

The listener determines whether a database service and its service handlers are available through service registration. During registration, the Listener Registration (LREG) process provides the listener with information about the following:

  1. Names of the database services provided by the database
  2. Name of the database instance associated with the services and its current and maximum load
  3. Service handlers (dispatchers and dedicated servers) available for the instance, including their type, protocol addresses, and current and maximum load

The preceding information enables the listener to direct a client request appropriately.

LREG进程会在启动数据库时动态注册,之后差不多1分钟周期注册监听,手动注册命令alter system register.

动态注册相关数据库参数

  1. SERVICE_NAMES

数据库会向监听注册两个服务名:

  1. service_names值,默认为db_name+db_domain
  2. db_name+db_domain值

可以定义多个服务,如alter system set service_names='a,b,c';

  1. INSTANCE_NAME

instance_name默认为SID

The value for the INSTANCE_NAME parameter defaults to the Oracle system identifier (SID).

  1. LOCAL_LISTENER

动态注册的默认监听器是LISTENER监听器,1521端口,使用local_listener参数更改默认行为.

By default, the LREG process registers service information with its local listener on the default local address of TCP/IP, port 1521. To have the LREG process register with a local listener that does not use TCP/IP, port 1521, configure the LOCAL_LISTENER parameter in the initialization parameter file to locate the local listener.

共享服务器使用DISPATCHERS参数

For a shared server environment, you can use the LISTENER attribute of the DISPATCHERS parameter in the initialization parameter file to register the dispatchers with a nondefault local listener.

LOCAL_LISTENER is a comma-delimited list parameter. If a comma appears in the string, then the entire string must be enclosed in double quotation marks.

Set the LOCAL_LISTENER parameter as follows:

ALTER SYSTEM SET LOCAL LISTENER=["]listener_address["][,...];

For shared server connections, set the LISTENER attribute as follows:

ALTER SYSTEM SET DISPATCHERS="(PROTOCOL=tcp)(LISTENER=listener_address)";

使用默认:ALTER SYSTEM SET LOCAL_LISTENER='';

使用tnsnames.ora的连接符:ALTER SYSTEM SET LOCAL_LISTENER=listener_sales1;

listener_sales1=

 (DESCRIPTION =

  (ADDRESS = (PROTOCOL=tcp)(HOST=sales-server)(PORT=1421)))

配置共享服务器:

ALTER SYSTEM SET DISPATCHERS="(PROTOCOL=tcp)(LISTENER=listener_sales1)";

直接配置:

alter system set local_listener='(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.11.135)(PORT = 1522))';

注:tnsnames.ora中的连接不能有CONNECT_DATA,这时你无法通过Oracle Enterprise Manager Cloud Control and Oracle Net Manager配置,只能手动输入tnsnames.ora, 另外上面直接配置地址也不能有CONNECT_DATA

  1. REMOTE_LISTENER

A remote listener is a listener residing on one computer that redirects connections to a database instance on another computer. In a dedicated server environment, you must enable the LREG background process to register with a remote listener.

You do this by configuring the REMOTE_LISTENER parameter, which is a comma-delimited list parameter, in the initialization parameter file. The syntax of REMOTE_LISTENER is as follows:

ALTER SYSTEM SET REMOTE_LISTENER=["]listener_address["][,...];

如果是共享服务器还是配置DISPATCHERS

In a shared server environment, you can use the same registration technique as for a dedicated server environment. Alternatively, you can set the LISTENER attribute of the DISPATCHERS parameter in the initialization parameter file to register the dispatchers with any listener.

The syntax of the LISTENER attribute is as follows:

ALTER SYSTEM SET DISPATCHERS="(PROTOCOL=tcp)(LISTENER=listener_address)";

配置方法同local_listener, 示例:

ALTER SYSTEM SET REMOTE_LISTENER=listener_sales2;

ALTER SYSTEM SET DISPATCHERS="(PROTOCOL=tcp)(LISTENER=listeners_sales2)";

  1. LISTENER_NETWORKS

相当于local以及remote listener设置的另一种写法,没啥必要

By specifying a set of listeners in the LISTENER_NETWORKS initialization parameter, you can designate a subset of local listeners with a subset of remote listeners. Listeners specified by the LISTENER_NETWORKS parameter should not be specified by the LOCAL_LISTENER and REMOTE_LISTENER parameters.

The syntax of LISTENER_NETWORKS parameter is as follows:

LISTENER_NETWORKS = '((NAME=network_name)

                      (LOCAL_LISTENER=["]listener_address[,...]["])

                      [(REMOTE_LISTENER=["]listener_address[,...]["])])'

Assume there are two distinct networks, network1 and network2. On network1, there is a local listener named local1, and a remote listener named remote1. On network2, there is a local listener named local2, and a remote listener named remote2. The following syntax sets up registration so that the listeners only redirect connections to listeners on the same network.

LISTENER_NETWORKS =

    '((NAME=network1) (LOCAL_LISTENER=local1) (REMOTE_LISTENER=remote1))',

    '((NAME=network2) (LOCAL_LISTENER=local2) (REMOTE_LISTENER=remote2))'

Static Service

动态服务是通过配置数据库实现的,静态服务是通过配置监听文件实现的,通过监听文件直接告诉实例的位置,监听不会去测试实际实例状态,所以状态会是UNKOWN. 在listener.ora中通过设置以下变量值来定位实例:

GLOBAL_DBNAME----提供的监听服务名,它与ORACLE的service_names名没关系,静态监听不需要service_names.

ORACLE_HOME, SID_NAME ----定位实例在OS中的位置,同样与数据库参数无关,其中SID_NAME值会作为监听的实例名

因为不是数据库去注册,所以也不涉及LOCAL_LISTENER或REMOTE_LISTENER问题

  • Dynamic Service & Static Service

不论是动态服务还是静态服务对于客户端是透明的,即均是通过监听的服务名连接的

  1. 一般情况都要使用动态服务:

Service registration offers the following benefits:

  1. Connect-time failover

Because the listener always monitors the state of the instances, service registration facilitates automatic failover of a client connect request to a different instance if one instance is down.

  1. Connection load balancing

Service registration enables the listener to forward client connect requests to the least-loaded instance and dispatcher or dedicated server. Service registration balances the load across the service handlers and nodes.

  1. High-availability for Oracle Real Application Clusters and Oracle Data Guard
  2. 静态服务无法使用共享模式连接
  1. 在以下情况使用静态服务:

Configuration of static service information is necessary in the following cases:

  1. Use of external procedure calls
  2. Use of Oracle Heterogeneous Services
  3. Use of Oracle Data Guard
  4. Remote database startup from a tool other than Oracle Enterprise Manager Cloud Control
  5. Connections to Oracle databases earlier than Oracle8i release 2 (8.1)

动态注册只能在数据库mount或open下连接,而静态注册无关数据库启动状态

$ vim listener.ora

LISTENER =

    (DESCRIPTION_LIST =

      (DESCRIPTION =

        (ADDRESS = (PROTOCOL = TCP)(HOST = su)(PORT = 1521))

        (ADDRESS = (PROTOCOL = IPC)(KEY = EXPROC0))

      )

     )

SID_LIST_LISTENER =

 (SID_LIST =

  (SID_DESC =

    (GLOBAL_DBNAME = a)

    (ORACLE_HOME = /oracle/product/11.2.0/dbhome_1)

    (SID_NAME = orcl)

  )

)

SQL> shutdown immediate

$ lsnrctl stop

$ lsnrctl start

$ sqlplus sys/sys@192.168.123.11/orcl as sysdba

ERROR:

ORA-12514: TNS:listener does not currently know of service requested in connect descriptor

$ sqlplus sys/sys@192.168.123.11/a as sysdba

SQL> startup  

(四)Manage listener.ora

可以不配置listener.ora文件,这时将使用默认监听LISTENER及1521端口,数据库也将默认动态注册到此监听,但这时没有静态服务,如果使用还是要配置

Because the configuration parameters have default values, it is possible to start and use a listener with no configuration. This default listener has a name of LISTENER, supports no services on startup, and listens on the following TCP/IP protocol address:

(ADDRESS=(PROTOCOL=tcp)(HOST=host_name)(PORT=1521))

以下为listener.ora基本配置,更多查看listener.ora参数配置

LISTENER =           ---此是监听配置,并非监听的动态服务

---动态服务是数据库层面配置监听的服务名与实例名

(DESCRIPTION_LIST =

      (DESCRIPTION =

        (ADDRESS = (PROTOCOL = TCP)(HOST = su)(PORT = 1522))

        (ADDRESS = (PROTOCOL = IPC)(KEY = EXPROC0))

      )

     )

SID_LIST_LISTENER =    ---此为配置对应监听的静态服务

 (SID_LIST =

  (SID_DESC =

    (GLOBAL_DBNAME = ORCL)  --静态服务名

    (ORACLE_HOME = /oracle/product/11.2.0/dbhome_1)

    (SID_NAME = orcl)          --静态实例名

  )

  (SID_DESC =

    (GLOBAL_DBNAME = A)     

    (ORACLE_HOME = /oracle/product/11.2.0/dbhome_1)

    (SID_NAME = orcl)

  )

)

Protocol Parameters: 详细说明见《Oracle Net原理》

关于监听IP:

  1. 如果配置HOST值为IP,则在此IP上监听,如果设置为0.0.0.0则监听主机所有IP地址
  2. 如果配置HOST值为域名,则按DNS获取的IP顺序在第一个成功连通的IP上监听(无论是否设置IP=FIRST),如果此IP与主机名(hostname)解析的IP一样,则监听主机所有IP地址,但如果此时设置监听IP=FIRST属性,则还是只监听DNS解析的第一个成功连通的IP

For a given host name, Oracle Net attempts to connect to all IP addresses returned by Domain Name System (DNS) name resolution until a successful connection is established or all addresses have been attempted.

同一监听不同数据库

如果数据库相同版本没问题,如果不同版本要用高版本监听同时监听全部数据

可以在监听IP或端口进行区分:

LISTENER =       

(DESCRIPTION_LIST =

      (DESCRIPTION =

        (ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521))

        (ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1522))

      )

     )

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值