当前位置: 首页 > news >正文

jdbc 负载均衡连接mysql_关于JDBC客户端如何连接ORACLE数据库RAC的负载均衡

这篇文章主要介绍如何使用jdbc配置连接数据库(oracle的RAC配置的数据库)达到负载均衡的情况.该例子是以2个NODE的情况说明,希望对大家有所帮助.

我的问题是我需要设置oracle9.2.x的thin客户端连接到oracle的RAC环境上.

注:这样连接可以通过RAC自动平衡负载.

--原文如下:

Hi Tom,

I couldn't find this information easily on the net.  So I'm submitting it here

and hope you make it available for anyone else looking for this information.

My problem was I needed to configure the Oracle 9.2.x thin driver (type IV) to

connect to an Oracle Real Application Cluster (RAC) environment.

For example, assuming you have a database called RAC_DB with two nodes - node1

and node2.

You would need to configure your tnsnames.ora with the following information in

the following way:

RAC_DB =

(DESCRIPTION =

(ADDRESS_LIST =

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

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

(LOAD_BALANCE = yes)

(FAILOVER = on)

)

(CONNECT_DATA =

(SERVICE_NAME = RAC_DB)

(FAILOVER_MODE = (TYPE = SELECT)

(METHOD = BASIC)

(RETRIES = 20)

(DELAY = 10)

)

)

)

Now if you start a SQL*PLUS session, then you should see a connection on the

node1 instance.  If you start another SQL*PLUS session, then Oracle should

connect you to the node2 instance (automatic load balancing).  It's actually

pretty cool to see the first time.

To pass this same information to the Oracle's JDBC thin driver, you essentially

concatenate a shorten version of the tnsnames information above and pass this to

the driver.

String userid = "scott";

String password = "tiger";

String tnsnames_info =

"(DESCRIPTION=(ADDRESS_LIST=" +

"(ADDRESS=(PROTOCOL=TCP)(HOST=node1)(PORT=1521))" +

"(ADDRESS=(PROTOCOL=TCP)(HOST=node2)(PORT=1521))" +

"(LOAD_BALANCE=yes)(FAILOVER=on))" +

"(CONNECT_DATA=(SERVICE_NAME=rac_db)))" ;

String url = "jdbc:oracle:thin:@" + tnsnames_info;

DriverManager.registerDriver(new oracle.jdbc.OracleDriver());

Connection dbConnection = DriverManager.getConnection(url, userid, password);

That's it.  If your application creates multiple connection to the database,

then you should see these connections load balance across the two instances.

One last note, Oracle only supports connection to a RAC configuration with the

9i drivers, so you should try to get the latest 9.2.0.4 Oracle JDBC thin driver.

HTH,

-Peter

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

and we said...

you made it really hard.  you just needed the service!  the load balancing and

all could be/should be setup on the listener side!

you have one listener, both databases register with it as a service.

that would be another option.

Reviews

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

I think we tried that and it didn't work...  September 28, 2003

Reviewer:  Peter Tran  from Houston, TX USA

Hi Tom,

I'm pretty sure we tried that but it didn't work with the thin driver.  That

approach will work if you use the OCI driver, but not with the thin driver.

Please send me an example of what you mean or what files I should configure to

test it out.

I'm always opened to easier options.

Thanks,

-Peter

Followup:

you need to set up mts and a single listener, thats it.

pmon on each of the rac instances will tell the listener about the load and away

it goes.  you might not see the round robin right off (both are "not yet

loaded") so it'll be an unbalanced load balance initially but as the system

ramps, it'll balance out.

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

Unknown territory...  September 28, 2003

Reviewer:  Peter Tran  from Houston, TX USA

I'm sorry, but I really lost you with that last recommendation.  Rather than

frustrate you with my ignorance, can you recommend the Oracle documentation that

I should read to brush up on this information?

I'll read this first and come back with questions if I'm still lost.

For example, I don't understand why you want me to setup the database as MTS.

Why can't I use dedicated server mode?

Thanks for the quick response.

-Peter

Followup:

in order for a single listener to service many instances -- on different

machines -- the listener must be servicing shared server connections -- the

listener cannot "fork/exec" a dedicated server since the listener may well not

be running on the machine the instance is on.  it needs to know dispatcher

addresses to redirect the client request to.

it is just inherit in the architecture.

相关文章:

  • 华为最终面试java_最全的华为面试题-java学习
  • mysql 全库 指定字符串_mysql替换数据库中的指定字符串 - YangJunwei
  • JAVA不能调用DESKTOP类_Java awt Desktop 无法调用系统浏览器
  • java返回并继承_Java方法从继承返回类型
  • java输入查找数组中的数_剑指Offer Java版 面试题53:在排序数组中查找数字
  • 插座java适配器模式_Java开发网 - 适配器模式的理解 (我自己写的)
  • java中borderpane_JavaFX BorderPane布局
  • Java如何查行数_如何正确利用Rownum来限制查询所返回的行数?
  • java 3 4_3-4 Java基础第四天
  • php phar 文件使用,PHP如何操作phar文件
  • java使用xpath解析xml,java使用XPath解析xml
  • php脚本防护,PHP的一个EVAL的利用防范
  • php中背景图怎么设置不重复,css怎么让背景图片不重复
  • java标签更改显示,离子选项卡,如何在标签更改上显示微调器?
  • java读写二进制文件 移动指针 seek,《Java大学教程》—第20章 文件处理
  • [PHP内核探索]PHP中的哈希表
  • 【编码】-360实习笔试编程题(二)-2016.03.29
  • Essential Studio for ASP.NET Web Forms 2017 v2,新增自定义树形网格工具栏
  • hadoop集群管理系统搭建规划说明
  • Idea+maven+scala构建包并在spark on yarn 运行
  • Js基础知识(四) - js运行原理与机制
  • js中的正则表达式入门
  • Linux编程学习笔记 | Linux IO学习[1] - 文件IO
  • React+TypeScript入门
  • Storybook 5.0正式发布:有史以来变化最大的版本\n
  • 案例分享〡三拾众筹持续交付开发流程支撑创新业务
  • 分布式任务队列Celery
  • 基于Javascript, Springboot的管理系统报表查询页面代码设计
  • 前端面试题总结
  • 原生Ajax
  • 怎么把视频里的音乐提取出来
  • MyCAT水平分库
  • NLPIR智能语义技术让大数据挖掘更简单
  • Prometheus VS InfluxDB
  • 阿里云移动端播放器高级功能介绍
  • 智能情侣枕Pillow Talk,倾听彼此的心跳
  • ​HTTP与HTTPS:网络通信的安全卫士
  • ​软考-高级-信息系统项目管理师教程 第四版【第23章-组织通用管理-思维导图】​
  • ​什么是bug?bug的源头在哪里?
  • (1)(1.13) SiK无线电高级配置(五)
  • (8)Linux使用C语言读取proc/stat等cpu使用数据
  • (C语言)求出1,2,5三个数不同个数组合为100的组合个数
  • (Pytorch框架)神经网络输出维度调试,做出我们自己的网络来!!(详细教程~)
  • (Repost) Getting Genode with TrustZone on the i.MX
  • (简单) HDU 2612 Find a way,BFS。
  • (免费领源码)Python#MySQL图书馆管理系统071718-计算机毕业设计项目选题推荐
  • (十六)串口UART
  • (已更新)关于Visual Studio 2019安装时VS installer无法下载文件,进度条为0,显示网络有问题的解决办法
  • (转)fock函数详解
  • (转)程序员技术练级攻略
  • *p++,*(p++),*++p,(*p)++区别?
  • .net Application的目录
  • .net2005怎么读string形的xml,不是xml文件。
  • .vollhavhelp-V-XXXXXXXX勒索病毒的最新威胁:如何恢复您的数据?
  • [ Algorithm ] N次方算法 N Square 动态规划解决