成都创新互联网站制作重庆分公司

ORACLERAC均衡负载

    oracle集群数据库有些时候并没有实现自动负载均衡,基本所有业务都在某一个节点上,所以容易造成某一个节点宕机的情况,针对这种情况我们就需要手动为期配置负载均衡。针对负载均衡配置有在服务器端和客户端两种入手方法(但是我发现主要还是服务器端配置效果更明显)

创新互联公司坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都网站制作、成都网站建设、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的河曲网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

    一、服务器端配置

      1、首先要在每个节点服务器上tnsnames.ora文件进行如下,注意看红色部分,而且我建议在HOST后面的值直接写IP地址,如果写hosts文件的主机名的话,有可能会出现TNS连接超时的情况。

RACDB =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.230.153)(PORT = 1521))/*一节点的IP*/

    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.230.154)(PORT = 1521))/*二节点的IP*/

    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.230.155)(PORT = 1521))/*如果是11G的话,需要把scan ip也写上,不然你用scan ip连不上去*/

    (LOAD_BALANCE = yes)                                             /*这个参数必须添加,不然没法实现均衡负载*/

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = RACDB)

    )

  )

 

LISTENERS_RACDB =

  (ADDRESS_LIST =

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

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

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

  )


      2、任意一个节点执行如下操作。在初始化参数中设置参数remote_listeners

   

SQL> conn system/admin@racdb 

已连接。

SQL> show parameter remote_listener

 

NAME                                 TYPE        VALUE

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

remote_listener                      string                                         /*可以看到当前的值为空*/

SQL>

SQL> alter system set remote_listener='LISTENERS_RACDB' sid='*';                   /*这个值一定要和前面tnsnames.ora文件里的一样*/

#(reset命令可以撤销设置,恢复默认值)                                          

系统已更改。

 show parameter remote_listener

 

NAME                                 TYPE        VALUE

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

remote_listener                      string      LISTENERS_RACDB                     /*可以看到刚才修改的已经生效*/

    3、现在可以看下监听信息,正确配置参数后,通过lsnrctl status命令看到在监听启动以后,可以看到监听器上有2个instance。

[grid@node01 bin]# lsnrctl status

 

LSNRCTL for Linux: Version 10.2.0.4.0 - Production on 18-DEC-2014 05:40:08

 

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

 

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))

STATUS of the LISTENER

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

Alias                     LISTENER_NODE01

Version                   TNSLSNR for Linux: Version 10.2.0.1.0 - Production

Start Date                18-DEC-2014 00:18:07

Uptime                    0 days 15 hr. 22 min. 1 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Parameter File   /orac/orahome/oracle/product/11.2.0/db_1/network/admin/listener.ora

Listener Log File         /orac/orahome/oracle/product/11.2.0/db_1/network/log/listener_node01.log

Listening Endpoints Summary...

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

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

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

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

Services Summary...

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

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

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

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

Service "RACDB" has 2 instance(s).

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

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

Service "RACDBXDB" has 2 instance(s).

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

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

Service "RACDB_XPT" has 2 instance(s).

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

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

The command completed successfully

二、客户端配置   

 在每个客户端或者JDBC的程序都用LOAD_BALANCE = yes的参数即可

                 客户端的tnsnames.ora如下修改

                   

RAC_DB =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.230.153)(PORT = 1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.230.154)(PORT = 1521))
     (LOAD_BALANCE = yes)
      (FAILOVER = on)
    )
    (CONNECT_DATA =
      (SERVICE_NAME = RAC_DB)
     (FAILOVER_MODE = (TYPE = SELECT)
                       (METHOD = BASIC)
                       (RETRIES = 20)
                       (DELAY = 10)
      )
    )
  )

标红的这几个参数代表意义:

LOAD_BALANCE=YES 表示的负载均衡,而且这个应该是客户端的负载均衡,就是随机的进行连接分配。

FAILOVER =ON 表示的是客户端连接时的故障转移。也就是说在建立会话的时候如果发现一个节点出现故障就去检测另外的节点。默认就是开启的。但是现在ORACLE一般使用TAF,就是说即使在连接期间出现故障,也会转移到其他节点继续操作
failover_mode 有几个参数TYPE MOTHOD RETRIES DELAY。
mothod 取值 basic preconnect(前者是在感知了错误才建立到其他节点的连接,后者是预先建立到其他节点的连接)
TYPE 取值 SELECT或 SESSION(前者在故障节点的查询结果不会抛弃,在新节点继续余下的操作,后者就是重新进行操作,抛弃以前的操作)
retries就是重试次数
DELAY 重试间隔时间,也可以使用SERVICE来做服务端的 TAF。


分享标题:ORACLERAC均衡负载
URL链接:http://cxhlcq.com/article/jcscep.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部