RAC监听与tns

Posted zyb_java

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了RAC监听与tns相关的知识,希望对你有一定的参考价值。

监听

个人理解:本来想通过scan ip来配置tns总数报12545,后来通过vip来配置tns

11g rac的监听在安装时创建,由grid用户管理监听,listener.ora文件在$ORACLE_HOME/network/admin目录中。rac中有asm实例和数据库实例。

[[email protected] ~]$ sqlplus "/as sysasm"

SQL> show parameter listen;

NAME                      TYPE             VALUE
----------------      ----------- ------------------------------
listener_networks     string
local_listener            string       (DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=node1-vip)(PORT=1521))))
remote_listener        string

[[email protected] ~]$ sqlplus "/as sysasm"

SQL> show parameter listen;

NAME                      TYPE             VALUE
----------------      ----------- ------------------------------
listener_networks     string
local_listener            string       (DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=node2-vip)(PORT=1521))))
remote_listener        string

查看监听状态:

节点1:

[[email protected] ~]$ lsnrctl status

 

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 18-JAN-2016 06:09:17

 

Copyright (c) 1991, 2009, Oracle.  All rights reserved.

 

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))

STATUS of the LISTENER

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

Alias                     LISTENER

Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production

Start Date                18-JAN-2016 00:15:53

Uptime                    0 days 5 hr. 53 min. 23 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Parameter File   /u01/11.2.0/grid/network/admin/listener.ora

Listener Log File         /u01/app/oracle/diag/tnslsnr/node1/listener/alert/log.xml

Listening Endpoints Summary...

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

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

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

Services Summary...

Service "+ASM" has 1 instance(s).

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

Service "RACDB" has 1 instance(s).

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

Service "RACDBXDB" has 1 instance(s).

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

(红色部分,如果在数据库实例中的host没有配置vip地址就不会显示)

The command completed successfully

节点2:

[[email protected] ~]$ lsnrctl status

 

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 18-JAN-2016 06:10:51

 

Copyright (c) 1991, 2009, Oracle.  All rights reserved.

 

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))

STATUS of the LISTENER

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

Alias                     LISTENER

Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production

Start Date                18-JAN-2016 00:15:54

Uptime                    0 days 5 hr. 54 min. 59 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Parameter File   /u01/11.2.0/grid/network/admin/listener.ora

Listener Log File         /u01/app/oracle/diag/tnslsnr/node2/listener/alert/log.xml

Listening Endpoints Summary...

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

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

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

Services Summary...

Service "+ASM" has 1 instance(s).

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

Service "RACDB" has 1 instance(s).

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

Service "RACDBXDB" has 1 instance(s).

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

The command completed successfully

查看oracle实例的listener配置:

[[email protected] ~]$ sqlplus "/as sysdba"

SQL> show parameter listen;

NAME                         TYPE              VALUE
-----------------      ----------- ------------------------------
listener_networks        string                                                                          (这个位置不能配置scan ip,试了不可行,本来想通过scan ip配置tns)
local_listener               string       (DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=node2-vip)(PORT=1521))))
remote_listener           string       rac-scan:1521

[[email protected] ~]$ sqlplus "/as sysdba"

SQL> show parameter listen;

NAME                         TYPE              VALUE
-----------------      ----------- ------------------------------
listener_networks        string
local_listener               string       (DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=node1-vip)(PORT=1521))))
remote_listener           string       rac-scan:1521

可通过下面语句修改参数:

alter system set local_listener = ‘(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=node1-vip)(PORT=1521))))‘ scope=both sid=‘RACDB1‘;

alter system register;

tns:

第一种:

rac =

  (DESCRIPTION =

    (ADDRESS_LIST =

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

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

    )

    (CONNECT_DATA =

      (SERVICE_NAME = RACDB)

    )

  )

这种情况,连接的实例挂掉,会断开重新连接另一个实例。

第二种:

TAF(Transparent Application Failover):

11g文档位置:Database Administration->Network Management->Local Naming Parameters(tnsname.ora)->

搜索retries ->Oracle Database Net Services Administrator‘s Guide

  Basic:

rac=

 (DESCRIPTION=

  (ADDRESS_LIST =

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

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

    )

    (LOAD_BALANCE = on)

    (CONNECT_DATA=

      (SERVICE_NAME=RACDB)

      (FAILOVER_MODE=

       (TYPE=select) –有session 和select (select 查询1w条,返回1k后挂掉,重新连接返回9k,session重新查询)两种

       (METHOD=basic)

       (RETRIES=20)

       (DELAY=15)

            )

            )

         )

--如果连接的实例挂掉,重新建立连接,不会先断开。

  Preconnect:

rac1=

 (DESCRIPTION=

  (ADDRESS=

       (PROTOCOL=tcp) 

       (HOST=192.168.56.201) 

       (PORT=1521))

  (CONNECT_DATA=

     (SERVICE_NAME=RACDB)

     (INSTANCE_NAME=RACDB1)

     (FAILOVER_MODE=

       (BACKUP=rac2)

       (TYPE=select)

       (METHOD=preconnect))))

rac2=

 (DESCRIPTION=

  (ADDRESS=

       (PROTOCOL=tcp) 

       (HOST=192.168.56.201) 

       (PORT=1521))

  (CONNECT_DATA=

     (SERVICE_NAME=RACDB)

     (INSTANCE_NAME=sales2)

     (FAILOVER_MODE=

       (BACKUP=RACDB2)

       (TYPE=select)

       (METHOD=preconnect))))

--切换快,但是浪费资源.先建立连接。

以上的方式为客户端,下面的方式为服务端。

第三种:

创建服务(oracle用户)

srvctl add service –d RACDB –s HAHA –r ‘RACDB2,RACDB1’ –P basic

启动服务

srvctl start service –d RACDB –s HAHA

show parameter service;服务名为HAHA不是RACDB.

通过函数修改

begin

  dbms_service.modify_service(service_name     => ‘HAHA‘,

                              failover_method  => ‘dbms_service.failover_method_basic‘,

                              failover_type    => ‘dbms_service.failover_type_select‘,

                              failover_retries => 180,

                              failover_delay   => 5);

end;

查看服务进程:crs_stat -t 列表中有没有HAHA的进程

客户端配置tns

rac-taf =

  (DESCRIPTION =

    (ADDRESS_LIST =

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

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

    )

    (CONNECT_DATA =

      (SERVICE_NAME = HAHA)

    )

  )

srvctl:

srvctl status database –d RACDB

srvctl status instance –d RACDB –i RACDB1

srvctl stop instance –d RACDB –I RACDB2

以上是关于RAC监听与tns的主要内容,如果未能解决你的问题,请参考以下文章

ORACLE RAC 监听配置 (listener.ora tnsnames.ora)

Oracle 11gR2 RAC 数据库不能连接(ORA-12537: TNS:connection closed)的解决

oracle11g RAC 下DBCA建库失败:ORA-12547: TNS:lost contact

Oracle 11gR2 RAC中的SCAN IP

oracle rac 监听日志在啥位置

ORA-12514:TNS:监听程序当前无法识别链接描述符中请求的服务