Oracle RAC 客户端连接负载均衡(Load Balance)
实现负载均衡(Load Balance)是Oracle RAC最重要的特性之一,主要是把负载平均分配到集群中的各个节点,以提高系统的整体吞吐能力。通常情况下有两种方式来实现负载均衡,一个是基于客户端连接的负载均衡,一个是基于服务器端监听器(Listener)收集到的信息来将新的连接请求分配到连接数较少实例上的实现方式。本文主要讨论的是基于客户端连接的负载均衡,并给出演示。
与负载均衡配置之前的监听配置请参考
ORACLE RAC 监听配置 (listener.ora tnsnames.ora)
ORACLE RAC 下非缺省端口监听配置(listener.ora tnsnames.ora)
一、客户端的负载均衡
客户端的负载均衡主要是通过为tnsnames.ora增加load_balance=yes条目来实现,下面看看oracle(Note:226880.1)的解释
The client load balancing feature enables clients to randomize connection requests among the listeners. Oracle Net progresses through the list of
protocol addresses in a random sequence, balancing the load on the various listeners. Without client load balancing, Oracle Net progresses through the
list of protocol addresses sequentially until one succeeds. This normally is referred to connect-time load balance.
从上面的描述中可以得知,如果未开启load_balance=yes时,Oracle Net会根据地址列表按顺序来选择一个进行连接,直到连接成功为止。
如果第一个host主机连接失败,在有多个地址的情形下,接下来选择第二个地址连接,依此类推,直到连接成功为止。
当开启了load_balance=yes时,则Oracle Net会从多个地址中随机地选择一个地址进行连接,直到连接成功为止。
注意,此连接方式仅根据地址列表随机选择,并不考虑到各个实例上当前真正连接数量的多少,也即是没有考虑各个节点真实的连接负载情况。
二、服务器与客户端的配置情况
- 1、服务器端监听器配置
- oracle@bo2dbp:~> more $ORACLE_HOME/network/admin/listener.ora --#节点bo2dbp上的listener
- # listener.ora.bo2dbp Network Configuration File: /u01/oracle/db/network/admin/listener.ora.bo2dbp
- # Generated by Oracle configuration tools.
- LISTENER_NEW_BO2DBP =
- (DESCRIPTION_LIST =
- (DESCRIPTION =
- (ADDRESS = (PROTOCOL = TCP)(HOST = bo2dbp-vip.2gotrade.com)(PORT = 1314)(IP = FIRST))
- (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.51)(PORT = 1314)(IP = FIRST))
- )
- )
- ...........................--#其余部分省略,注意此处的配置是使用了1314的非缺省监听器端口号
- oracle@bo2dbs:/u01/oracle/db/network/admin> more listener.ora --#节点bo2dbs上的listener
- # listener.ora.bo2dbs Network Configuration File: /u01/oracle/db/network/admin/listener.ora.bo2dbs
- # Generated by Oracle configuration tools.
- LISTENER_NEW_BO2DBS =
- (DESCRIPTION_LIST =
- (DESCRIPTION =
- (ADDRESS = (PROTOCOL = TCP)(HOST = bo2dbs-vip.2gotrade.com)(PORT = 1314)(IP = FIRST))
- (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.52)(PORT = 1314)(IP = FIRST))
- )
- )
- ...............
- 2、参数配置
- -->instrance ora10g1上的参数配置
- SQL> show parameter instance_na
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- instance_name string ora10g1
- SQL> show parameter listener
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- local_listener string local_lsnr_ora10g1
- remote_listener string remote_lsnr_ora10g
- -->instrance ora10g2上的参数配置
- SQL> show parameter instance_name
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- instance_name string ora10g2
- SQL> show parameter listener
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- local_listener string local_lsnr_ora10g2
- remote_listener string remote_lsnr_ora10g
- -->instrance ora10g2上的监听信息
- SQL> ho ps -ef | grep lsnr
- oracle 17372 1 0 11:00 ? 00:00:00 /u01/oracle/db/bin/tnslsnr LISTENER_NEW_BO2DBS -inherit
- oracle 17502 24301 0 12:10 pts/0 00:00:00 /bin/bash -c ps -ef | grep lsnr
- oracle 17504 17502 0 12:10 pts/0 00:00:00 grep lsnr
- SQL> ho lsnrctl status LISTENER_NEW_BO2DBS
- Listening Endpoints Summary...
- (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.62)(PORT=1314)))
- (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.52)(PORT=1314)))
- Services Summary...
- Service "ora10g" has 2 instance(s).
- Instance "ora10g1", status READY, has 1 handler(s) for this service...
- Instance "ora10g2", status READY, has 2 handler(s) for this service...
- ..........
- -->由于只是测试基于客户端的load balance,因此移出remote_listener参数
- SQL> alter system reset remote_listener scope=both sid='*';
- alter system reset remote_listener scope=both sid='*'
- *
- ERROR at line 1:
- ORA-32009: cannot reset the memory value for instance * from instance ora10g2
- SQL> alter system reset remote_listener scope=spfile sid='*';
- System altered.
- SQL> ho srvctl stop database -d ora10g -->关闭数据库ora10g
- SQL> ho srvctl start database -d ora10g -->启动数据库ora10g使得刚刚修改的remote_listener生效
- SQL> ho lsnrctl status LISTENER_NEW_BO2DBS -->此时可以看到只有ora10g2注册到监听器
- Listening Endpoints Summary...
- (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.62)(PORT=1314)))
- (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.52)(PORT=1314)))
- Services Summary...
- Service "PLSExtProc" has 1 instance(s).
- Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
- Service "ora10g" has 1 instance(s).
- Instance "ora10g2", status READY, has 1 handler(s) for this service...
- ..........
- oracle@bo2dbp:~> lsnrctl status LISTENER_NEW_BO2DBP #同样在节点bo2dbp也只有ora10g1注册到监听器
- Listening Endpoints Summary...
- (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.61)(PORT=1314)))
- (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.51)(PORT=1314)))
- Services Summary...
- Service "ora10g" has 1 instance(s).
- Instance "ora10g1", status READY, has 1 handler(s) for this service...
- .........
- 3、客户端配置
- SZDB:~ # ifconfig eth1 | grep "inet addr"|cut -d " " -f12|cut -d : -f2 #客户端主机的ip
- 192.168.7.2
- SZDB:~ # su - oracle
- oracle@SZDB:~> cat /etc/hosts --#客户端主机添加了RAC上的两个虚拟节点的ip信息
- 192.168.7.61 bo2dbp-vip.2gotrade.com bo2dbp-vip
- 192.168.7.62 bo2dbs-vip.2gotrade.com bo2dbs-vip
- oracle@SZDB:~> tail -12 $ORACLE_HOME/network/admin/tnsnames.ora
- ORA10G =
- (DESCRIPTION =
- (ADDRESS = (PROTOCOL = TCP)(HOST = bo2dbp-vip.2gotrade.com)(PORT = 1314))
- (ADDRESS = (PROTOCOL = TCP)(HOST = bo2dbs-vip.2gotrade.com)(PORT = 1314))
- (LOAD_BALANCE = yes)
- (CONNECT_DATA =
- (SERVER = DEDICATED)
- (SERVICE_NAME = ora10g)
- )
- )
三、测试负载均衡(load balance)
- 1、启用load balance的测试
- oracle@SZDB:~> more load_balance.sh
- #!/bin/bash
- for i in {1..100}
- do
- echo $i
- sqlplus -S system/oracle@ORA10G <<EOF
- select instance_name from v\$instance;
- EOF
- sleep 1
- done
- exit 0
- # Author: Robinson Cheng
- # Blog : http://blog.csdn.net/robinson_0612
- oracle@SZDB:~> ./load_balance.sh >load_bal.log
- oracle@SZDB:~> head -20 load_bal.log
- 1
- INSTANCE_NAME
- ----------------
- ora10g2
- 2
- INSTANCE_NAME
- ----------------
- ora10g1
- 3
- INSTANCE_NAME
- ----------------
- ora10g2
- 4
- oracle@SZDB:~> grep ora10g1 load_bal.log |wc -l
- 47
- oracle@SZDB:~> grep ora10g2 load_bal.log |wc -l
- 53
- 从上面的log日志中可以看出启用客户端的负载均衡基本上使得从客户端发起连接的能够保持均衡。
- 2、未启用load balance的测试
- 从客户端的tnsnames.ora中移出(LOAD_BALANCE = yes)选项,然后继续使用上面的脚本来测试
- oracle@SZDB:~> grep ora10g1 no_load_bal.log |wc -l
- 100
- oracle@SZDB:~> grep ora10g2 no_load_bal.log |wc -l
- 0
- 从上面的日志中可以看出当移出LOAD_BALANCE = yes项后,所有的用户连接请求都被定为到ora10g1,这是因为连接请求从tnsnames.ora中选择
- 列在ADDRESS项中排在第一行的位置。
- 下面我们关闭实例ora10g1,再来测试连接情形
- oracle@bo2dbp:~> srvctl stop instance -d ora10g -i ora10g1
- oracle@SZDB:~> ./load_balance.sh >no_load_bal_new.log
- oracle@SZDB:~> grep ora10g1 no_load_bal_new.log |wc -l
- 0
- oracle@SZDB:~> grep ora10g2 no_load_bal_new.log |wc -l
- 100
- 由于实例ora10g1已经关闭,因此所有的连接请求都被分配到ora10g2。
四、总结
1、客户端的负载均衡配置较为简单,仅仅是在客户端的tnsnames.ora添加 LOAD_BALANCE = yes |on
2、其连接分配原则是根据tnsnames.ora中连接标识符下的ADDRESS列表随机选择来进行与服务器之间的连接
3、如果选择列表中的某个节点listener或instance不可用,则再从剩余的ADDRESS列表随机选择,直到成功为止
转:http://blog.csdn.net/leshami/article/details/8060634
Oracle RAC 客户端连接负载均衡(Load Balance)的更多相关文章
- Oracle RAC 服务器端连接负载均衡(Load Balance)
Oracle RAC服务器端的负载均衡是根据RAC中各节点的连接负荷数情况,将新的连接请求分配到负荷最小的节点上去.当数据库处于运行时,RAC中各节点的PMON进程每3秒会将各自节点的连接负荷数更新到 ...
- "高可用方案工具包" high availability toolkit 1.2 公布了。version 1.2 新增了 负载均衡 load balance 的技术实现
"高可用方案工具包" high availability toolkit 1.2 公布了. version 1.2 新增了 负载均衡 load balance 的技术实现. 项目 ...
- 【mq】从零开始实现 mq-07-负载均衡 load balance
前景回顾 [mq]从零开始实现 mq-01-生产者.消费者启动 [mq]从零开始实现 mq-02-如何实现生产者调用消费者? [mq]从零开始实现 mq-03-引入 broker 中间人 [mq]从零 ...
- 【高可用HA】Nginx (1) —— Mac下配置Nginx Http负载均衡(Load Balancer)之101实例
[高可用HA]Nginx (1) -- Mac下配置Nginx Http负载均衡(Load Balancer)之101实例 nginx版本: nginx-1.9.8 参考来源: nginx.org [ ...
- 【高可用HA】Apache (4) —— Mac下配置Apache Httpd负载均衡(Load Balancer)之mod_jk
Mac下配置Apache Httpd负载均衡(Load Balancer)之mod_jk httpd版本: httpd-2.4.17 jk版本: tomcat-connectors-1.2.41 参考 ...
- 【高可用HA】Apache (3) —— Mac下配置Apache Httpd负载均衡(Load Balancer)之mod_proxy
Mac下配置Apache Httpd负载均衡(Load Balancer)之mod_proxy httpd版本: httpd-2.4.17 参考来源: Apache (1) -- Mac下安装Apac ...
- 章文嵩博士和他背后的负载均衡(LOAD BANLANCER)帝国
案首语: 阿里集团技术大牛,@正明,淘宝基础核心软件研发负责人.LVS创始人.阿里云首席科学家章文嵩博士从阿里离职,去追求技术人生另一段历程,让阿里像我一样的很多热爱技术的工程师都有一丝牵动和感触. ...
- RAC,客户端连接失败ORA-12514
今天上午,某项目运维组的同事过来求助:"某系统的应用有问题了,WEB页面打开以后出现ORACLE的ORA-12514错误,貌似监听有问题了!" 该系统的数据是采用RAC部署的模式, ...
- Oracle 11g 客户端连接 oracle 10g 服务端,乱码问题
从网上搜索资料基本确定:字符集错误 Pl/sql 连接到oracle 数据库 “select userenv('language') from dual” 找到服务端的对应的字符集,拷贝之: 到本 ...
随机推荐
- WP 类似扑克牌布局控件和类似扑克卡片控件
一.说明 本文代码来源: <windows phone 7 程序设计> Charles Petzold 控件效果: 二.要点: 1.ItemControl.子项容器模板(ItemsCont ...
- Spring @ Component 的作用
1.@controller 控制器(注入服务) 2.@service 服务(注入dao) 3.@repository dao(实现dao访问) 4.@component (把普通pojo实例化到spr ...
- Unique Binary Search Tree II
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For e ...
- POJ3250Bad Hair Day
http://poj.org/problem?id=3250 题意 : n个牛排成一列向右看,牛 i 能看到牛 j 的头顶,当且仅当牛 j 在牛 i 的右边并且牛 i 与牛 j 之间的所有牛均比牛 ...
- HttpWebRequest和HttpWebResponse
原文:http://blog.csdn.net/haitaofeiyang/article/details/18362225 申公前几日和一个客户做系统对接,以前和客户对接一般采用webservice ...
- python—命名规范(转)
文件名全小写,可使用下划线 包应该是简短的.小写的名字.如果下划线可以改善可读性可以加入.如mypackage. 模块与包的规范同.如mymodule. 类总是使用首字母大写单词串.如MyClass. ...
- java.util.concurrent包API学习笔记
newFixedThreadPool 创建一个固定大小的线程池. shutdown():用于关闭启动线程,如果不调用该语句,jvm不会关闭. awaitTermination():用于等待子线程结束, ...
- lintcode 中等题:Submatrix sum is 0 和为零的子矩阵
和为零的子矩阵 给定一个整数矩阵,请找出一个子矩阵,使得其数字之和等于0.输出答案时,请返回左上数字和右下数字的坐标. 样例 给定矩阵 [ [1 ,5 ,7], [3 ,7 ,-8], [4 ,-8 ...
- leetcode 4 : Median of Two Sorted Arrays 找出两个数组的中位数
题目: There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the ...
- SpringMVC学习总结(四)——基于注解的SpringMVC简单介绍
SpringMVC是一个基于DispatcherServlet的MVC框架,每一个请求最先访问的都是 DispatcherServlet,DispatcherServlet负责转发每一个Request ...