Oracle负载均衡配置代码

网络 网络优化 网络运维
文章摘要:本文详细介绍了Oracle负载均衡的具体配置。通过客户端和服务器端两方面进行配置,文中代码比较全面,值得大家参考。

对于专业的数据处理存储的Oracle ARC而言,负载均衡的设置就更为重要了。那么如何对Oracle负载均衡进行配置呢?就让我们一起看看本文来学习一下吧。我们将从客户端和服务器端来进行解说。

Oracle负载均衡主要是指新会话连接到RAC数据库时,如何判定这个新的连接要连到哪个节点进行工作。在Oracle负载均衡中分为两种,一种是基于客户端连接的,另外一种是基于服务器端的。

客户端的Oracle负载均衡配置相对简单,只需要在tnsnames.ora中添加LOAD_BALANCE=ON这么一个选项即可。比如下面的TNS:

  1. RAC =  
  2. (DESCRIPTION =  
  3. (ADDRESS = (PROTOCOL = TCP)(HOST = rac1-vip)(PORT = 1521))  
  4. (ADDRESS = (PROTOCOL = TCP)(HOST = rac2-vip)(PORT = 1521))  
  5. (LOAD_BALANCE = ON)  
  6. (FAILOVER = ON)  
  7. (CONNECT_DATA =  
  8. (SERVER = DEDICATED)  
  9. (SERVICE_NAME = rac)  
  10. )  

这样当客户端连接RAC数据库时,会随机在TNS里面挑个监听地址进行连接。在Oracle10g以前,假如有节点宕机或者类似事故时,客户端可能还是选择连接到这个节点,这样会发生较长时间的TCP等待超时。而在10g以后,由于VIP和FAN的引入,这样的情况可以得到很大程度的改善。客户端的Oracle负载均衡在通常情况下能够较好地工作,但是由于连接是在客户端随机发起的,这样客户端并不知道RAC各节点的负荷及连接数情况,有可能负荷大的节点还会源源不断地增加新的连接,导致RAC节点无法均衡工作。

从Oracle 10g开始,服务器端的Oracle负载均衡可以根据RAC中各节点的负荷及连接数情况,而判定将新的客户端连接分配到负荷最小的节点上去。RAC中各节点的PMON进程每3秒会将各自节点的负荷(包括LOAD、***LOAD、CPU使用率)及连接数更新到service_register里面,然后假如节点的负荷有发生变化,将会通知到监听程序,由监听程序再决定新的客户端连接分配至哪个节点。假如RAC中一个节点的监听失败了,PMON每一分钟会去检查一次是否已经恢复正常。

服务器端的监听配置是在各节点的tnsnames.ora里面添加一个连接到各个节点监听的条目,然后再在初始化参数里面设置remote_listeners这个参数。比如:

  1. LISTENERS_RAC =  
  2. (ADDRESS_LIST =  
  3. (ADDRESS = (PROTOCOL = TCP)(HOST = rac1-vip)(PORT = 1521))  
  4. (ADDRESS = (PROTOCOL = TCP)(HOST = rac2-vip)(PORT = 1521))  
  5. )   
  6.  
  7. ALTER SYSTEM SET REMOTE_LISTENER = LISTENERS_RAC; 

这样服务器端的Oracle负载均衡便配置完成。#p#

但是有时候由于PMON取节点负荷的延迟,导致客户端连接可能还是会连接到负荷较大的节点上,这时候便可以在服务器各节点的listener.ora里面加入PREFER_LEAST_LOADED_NODE=OFF这么一行,这样服务器端的Oracle负载均衡将不再根据节点的负荷来进行分配,而是根据节点的连接数进行分配,达到各个节点连接数比较平衡的效果。

另外一个不得不说的便是并行操作,假如有个会话连接以后要进行并行操作。由于连接时是按负荷或连接数连接,这样可能连接时各个节点连接数和负荷等比较平衡,但是这个并行会话启动多个并行进程以后,那么这个节点的负荷及连接数就会有可能上升得比较快。如果在RAC中开启了节点并行,那么有可能会把并行进程分配到多个节点运行以达到负载均衡的效果。

从Oracle 10.2开始,Oracle引入了Load Balance Advisor,对Oracle负载均衡有了进一步的改进。结合Service,可以对不同的SERVICE设置不同的Oracle负载均衡策略。Load Balance Advisor的配置可以通过DBMS_SERVICE包对SERVICE进行更改而完成。在Load Balance Advisor首先必须设置SERVICE负载均衡的目标,目标分为3种:

  1. GOAL_NONE Disables the load balancing advisory  
  2. GOAL_SERVICE_TIME The LBA calculates a weighted moving average of the total elapsed time for completed work plus the bandwidth that's available to the service to calculate the service goodness. This goal is ideal for services whose workload may change dramatically over a short period of time, e.g. an application that services a “clicks and mortar" store that provides customer self-service through an internet-based shopping web site.  
  3. GOAL_THROUGHPUT The LBA calculates a weighted moving average of throughput (i.e. the rate at which work is completed) in addition to the bandwidth available to the service to calculate the service goodness. This goal is best suited for long-duration tasks that are typically queued to run serially, e.g. scheduled jobs that handle large batches of transactions. 

另外可以额外设置连接的负载均衡:

  1. CLB_GOAL_SHORT The Load Balancing Advisory will be used for connection load balancing only if it is enabled (i.e. set to other than GOAL_NONE). If the LBA has been disabled, connection load balancing will utilize abridged advice determined by CPU utilization.  
  2. CLB_GOAL_LONG Connection load balancing will be determined by first tallying the total number of connections per instance, and then by counting the number of sessions per each service. Oracle recommends using this setting for services whose applications tend to connect for long periods of time (e.g. Oracle Forms). The Load Balancing Advisory can be used in conjunction with this setting as long as the connection pool has been sized to accommodate “gravitation “ within the pool without adding or subtracting connections. Oracle recommends this option as the most efficient design. 

 

责任编辑:佟健 来源: 互联网
相关推荐

2010-04-20 22:19:29

tomcat负载均衡配

2010-04-21 12:57:33

RAC负载均衡配置

2010-04-22 23:07:47

服务器负载均衡

2010-04-22 10:09:28

负载均衡器

2010-04-22 12:45:05

2010-04-20 22:36:52

负载均衡配置

2010-04-21 13:18:33

RAC负载均衡配置

2010-04-26 16:36:31

DNS负载均衡设置

2010-04-22 17:53:36

Apache负载均衡

2010-04-22 18:27:37

Apache负载均衡

2014-07-28 11:37:49

NginxTomcat

2017-07-03 08:08:25

负载均衡分类

2012-05-07 10:17:48

2010-04-20 21:27:28

tomcat负载均衡配

2017-05-19 14:45:01

OVN负载均衡器路由器

2010-04-22 16:41:56

负载均衡端口规则

2011-04-28 14:56:29

XenServer负载

2010-03-25 18:52:15

Nginx负载均衡

2010-04-23 11:05:16

流量负载均衡

2010-05-05 23:27:32

负载均衡配置
点赞
收藏

51CTO技术栈公众号