`

jdbc连接rac

 
阅读更多

1、按顺序尝试每个地址,直到有一个成功
tnsnames.ora 里面的配置是这样的
RAC =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.102.202)(PORT = 1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.102.200)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = sun)
    )
  )
默认情况下,LOAD_BALANCE=no,FAILOVER=true,SOURCE_ROUTE=no

 

2、随机尝试每个地址,直到成功
tnsnames.ora 里面的配置是这样的
RAC =
  (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.102.202)(PORT = 1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.102.200)(PORT = 1521))
      (LOAD_BALANCE = yes)
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = sun)
    )
  )
 

3、随机选择尝试一个地址
tnsnames.ora 里面的配置是这样的
RAC =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.102.202)(PORT = 1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.102.200)(PORT = 1521)))
      (LOAD_BALANCE = yes)
      (FAILOVER = false)
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = sun)
    )
  )

4、按顺序使用每个地址,直到到达目标
tnsnames.ora 里面的配置是这样的
RAC =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.102.202)(PORT = 1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.102.200)(PORT = 1521))
      (SOURCE_ROUTE = yes)
      (FAILOVER = false)
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = sun)
    )
  )

5、只使用第一个地址
RAC =
  (DESCRIPTION =
    (ADDRESS_LIST =
     (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.102.202)(PORT = 1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.102.200)(PORT = 1521))
      (FAILOVER = false)
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = sun)
    )
  )


根据网上的提示
jdbc:oracle:thin@(DESCRIPTION =(ADDRESS_LIST=(ADDRESS=(PROTOCOL = TCP)(HOST = 192.168.102.202)(PORT = 1521))(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.102.200)(PORT = 1521))(LOAD_BALANCE = no)(FAILOVER=YES))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = jrtdbtest)))

或者
core.db.url=jdbc:oracle:thin@(DESCRIPTION =(ADDRESS_LIST=(ADDRESS=(PROTOCOL = TCP)(HOST = dbserver1-vip)(PORT = 1521))(ADDRESS = (PROTOCOL = TCP)(HOST = dbserver2-vip)(PORT = 1521))(LOAD_BALANCE = no)(FAILOVER=YES))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = jrtdbtest)))
报错:java.sql.SQLException: Io exception: NL Exception was generated
根据实验,居然是url中的空格引起的



通过网络查找及查询数据库,数据库的rac信息如下:
"./10g/db/network/admin/tnsnames.ora" 40 lines, 1003 characters 
# tnsnames.ora Network Configuration File: /oracle/10g/db/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

LISTENERS_JRTDB =
  (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = dbserver1-vip)(PORT = 1521))
    (ADDRESS = (PROTOCOL = TCP)(HOST = dbserver2-vip)(PORT = 1521))
  )

JRTDB2 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = dbserver2-vip)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = jrtdb)
      (INSTANCE_NAME = jrtdb2)
    )
  )

JRTDB1 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = dbserver1-vip)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = jrtdb)
      (INSTANCE_NAME = jrtdb1)
    )
  )

JRTDB =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = dbserver1-vip)(PORT = 1521))
    (ADDRESS = (PROTOCOL = TCP)(HOST = dbserver2-vip)(PORT = 1521))
    (LOAD_BALANCE = yes)
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = jrtdb)
    )
  )

:q
[jrtdb2]@dbserver2[/oracle]$ping dbserver1-vip
PING dbserver1-vip: (192.168.102.201): 56 data bytes
64 bytes from 192.168.102.201: icmp_seq=0 ttl=255 time=0 ms
64 bytes from 192.168.102.201: icmp_seq=1 ttl=255 time=0 ms

----dbserver1-vip PING Statistics----
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 0/0/0 ms
[jrtdb2]@dbserver2[/oracle]$vi /etc/hosts
"/etc/hosts" [Read only] 61 lines, 2096 characters 
# @(#)47        1.1  src/bos/usr/sbin/netstart/hosts, cmdnet, bos530 7/24/91 10:00:46
# IBM_PROLOG_BEGIN_TAG
# This is an automatically generated prolog.
#
# bos530 src/bos/usr/sbin/netstart/hosts 1.1
#
# Licensed Materials - Property of IBM
#
# (C) COPYRIGHT International Business Machines Corp. 1985,1989
# All Rights Reserved
#
# US Government Users Restricted Rights - Use, duplication or
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
#
# IBM_PROLOG_END_TAG
#
# COMPONENT_NAME: TCPIP hosts
#
# FUNCTIONS: loopback
#
# ORIGINS: 26  27
#
# (C) COPYRIGHT International Business Machines Corp. 1985, 1989
# All Rights Reserved
# Licensed Materials - Property of IBM
#
# US Government Users Restricted Rights - Use, duplication or
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
#
#  /etc/hosts
#
# This file contains the hostnames and their address for hosts in the
# network.  This file is used to resolve a hostname into an Internet
# address.
#
# At minimum, this file must contain the name and address for each
# device defined for TCP in your /etc/net file.  It may also contain
# entries for well-known (reserved) names such as timeserver
# and printserver as well as any other host name and address.
#
# The format of this file is:
# Internet Address      Hostname        # Comments
# Items are separated by any number of blanks and/or tabs.  A '#'
# indicates the beginning of a comment; characters up to the end of the
# line are not interpreted by routines which search this file.  Blank
# lines are allowed.

# Internet Address      Hostname        # Comments
# 192.9.200.1           net0sample      # ethernet name/address
# 128.100.0.1           token0sample    # token ring name/address
# 10.2.0.2              x25sample       # x.25 name/address
127.0.0.1               loopback localhost      # loopback (lo0) name/address
# Public Network - (eth0)
192.168.102.200 dbserver1
192.168.102.202 dbserver2
# Private Interconnect - (eth1)
192.168.103.200 dbserver1-priv
192.168.103.202 dbserver2-priv
# Public Virtual IP (VIP) addresses
192.168.102.201 dbserver1-vip
192.168.102.203 dbserver2-vip


最终修改如下,网上还说不能用ip,但是测试用ip通过,如果用主机名的话,需要在etc/host下添加

jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS_LIST =(ADDRESS=(PROTOCOL=TCP)(HOST=dbserver1-vip)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=dbserver2-vip)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=jrtdb))) 
jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS_LIST =(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.102.200)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.102.202)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=jrtdb)))





LOAD_BALANCE
 FAILOVER
 

ON
 ON
 客户端新建连接随机尝试ADDRESS_LIST中的监听,直到连接到一个可用监听,或者连完列表中的所有监听,如没有一个监听可用,则返回错误信息
 
ON
 OFF
 客户端新建连接随机尝试ADDRESS_LIST中的任一监听,无论这个监听是否可用,如不可用直接返回错误。
 
OFF
 ON
 客户端新建连接按顺序尝试ADDRESS_LIST中的监听,直到连接到一个可用监听,或者连完列表中的所有监听如没有一个监听可用,则返回错误信息
 
OFF
 OFF
 客户端新建连接仅连接ADDRESS_LIST中第一个监听,无论这个监听是否可用,如不可用直接返回错误。


数据源连接数据库问题
最开始用的是dbcp连接数据库的,如下:
	<bean id="coreDataSource" class="org.apache.commons.dbcp.BasicDataSource"
		destroy-method="close">
		<property name="driverClassName" value="${core.db.driver}" />
		<property name="url" value="${core.db.url}"/>
		<property name="username" value="${core.db.username}" />
		<property name="password" value="${core.db.password}" />
		<property name="maxActive"><value>200</value></property>   
        <property name="initialSize"><value>20</value></property>   
        <property name="maxWait"><value>600</value></property>   
        <property name="maxIdle"><value>20</value></property>   
        <property name="minIdle"><value>3</value></property>  
        <property name="removeAbandoned"><value>true</value></property> 
        <property name="removeAbandonedTimeout"><value>180</value></property>   
        <property name="validationQuery"><value>select 1 from dual</value></property>


但是换了之后第一次连接失败,往后连接正出常,换了驱动也是一样,不知道怎么回事,是否是dbcp的bug,换了数据源后,该问题解决,如下Bonecp
		<!-- BoneCP数据源配置 -->
		<bean id="coreDataSource" class="com.jolbox.bonecp.BoneCPDataSource"
		destroy-method="close">
		<property name="driverClass" value="${core.db.driver}" />
		<property name="jdbcUrl" value="${core.db.url}"/>
		<property name="username" value="${core.db.username}" />
		<property name="password" value="${core.db.password}" />
		<!-- 检查数据库连接池中空闲连接的间隔时间,单位是分,默认值:240,如果要取消则设置为0 -->
		<property name="idleConnectionTestPeriod" value="60" />
		<!-- 连接池中未使用的链接最大存活时间,单位是分,默认值:60,如果要永远存活设置为0 -->
		<property name="idleMaxAge" value="240" />
		
		<!-- 每个分区最大的连接数 -->
		<property name="maxConnectionsPerPartition" value="20" />
		<!-- 每个分区最小的连接数 -->  
		<property name="minConnectionsPerPartition" value="3" />
		<!-- 分区数 ,默认值2,最小1,推荐3-4,视应用而定-->  
		<property name="partitionCount" value="3" />
		<!-- 每次去拿数据库连接的时候一次性要拿几个,默认值:2 -->  
		<property name="acquireIncrement" value="5" />
		<!-- 缓存prepared statements的大小,默认值:0 -->       
		<property name="statementsCacheSize" value="10" />
		<!-- 每个分区释放链接助理进程的数量,默认值:3,除非你的一个数据库连接的时间内做了很多工作,不然过多的助理进程会影响你的性能 -->    
		<property name="releaseHelperThreads" value="3" />


经测试发现,所有的参数应该是off,on如下:
jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS_LIST =(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.150.203)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.150.201)(PORT=1521)))(SOURCE_ROUTE = off)(FAILOVER = on)(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=jrtdb)))

注:ip地址是rac虚拟地址
分享到:
评论

相关推荐

    weblogic连接oracle RAC数据源配置

    而"jdbc_admin.pdf"可能是关于JDBC管理和配置的文档,对理解JDBC连接和配置数据源会有帮助。 总结来说,配置WebLogic连接Oracle RAC数据源是一个涉及多个层面的过程,包括JDBC驱动的管理、数据源的创建和配置、高...

    可用于oracle19c的jdbc驱动

    标题提到的"可用于Oracle19c的JDBC驱动"指的是Oracle公司为19c版本数据库提供的Java Database Connectivity (JDBC)驱动程序,它允许Java应用程序通过网络连接到Oracle数据库,执行SQL语句、处理结果集等操作。...

    rac java jdbc配置.txt

    ### RAC Oracle JDBC 配置详解 #### 一、引言 在当今的企业级应用环境中,Oracle RAC(Real Application Clusters)作为一种高可用性和高性能的解决方案被广泛采用。RAC通过在一个集群中运行多个数据库实例来实现...

    Spring boot连接oracle数据库JDBC配置步骤

    Spring Boot 连接 Oracle 数据库 JDBC 配置步骤 在本文中,我们将详细介绍如何使用 Spring Boot 连接 Oracle 数据库,配置 JDBC 驱动程序,并实现数据库的基本操作。 Step 1: 添加依赖项 在 Spring Boot 项目中,...

    ORACLE-10g-RAC-负载均衡配置

    在 RAC 中,负载均衡分为两种,一种是基于客户端连接的,另外一种是基于服务器端的。下面将详细介绍基于客户端连接的负载均衡配置。 一、客户端负载均衡的配置 在客户端配置 TNS 时,需要在 tnsnames.ora 中添加 ...

    rac weblogic(txt简写)

    在WebLogic环境中配置Oracle RAC数据库连接时,正确设置JDBC连接字符串和TNSNAMES.ORA文件是非常重要的。这些配置确保了WebLogic Server能够高效地与Oracle RAC数据库进行交互,并充分利用其提供的高级特性。

    jdbc连接驱动

    本篇将深入讲解如何使用JDBC连接驱动,以及涉及到的MySQL和Oracle数据库的相关知识。 首先,我们关注的是两个具体的JDBC驱动文件:“mysql-connector-java-5.1.38-bin.jar”和“ojdbc6.jar”。这两个文件是数据库...

    使用JDBC连接ORACLE的三种URL格式

    本文将详细介绍使用JDBC连接Oracle数据库的三种URL格式,并通过示例代码解释它们的工作原理。 首先,我们需要理解JDBC URL的基本结构,它通常遵循这样的模式:`jdbc:driver_type:connection_protocol:@server[:port...

    jdbc_oracle

    本篇文章将深入探讨Oracle 11g JDBC连接的相关知识。 一、Oracle 11g JDBC驱动 Oracle 11g提供了多种JDBC驱动,主要包括以下几种: 1. JDBC Thin Driver:这是一个轻量级的纯Java驱动,不依赖于任何Oracle客户端库...

    通过JDBC连接oracle数据库的十大技巧

    Java数据库连接(JDBC)API是一系列能够让Java编程人员访问数据库的接口,各个开发商的接口并不完全相同。在使用多年的Oracle公司的JDBC后,我积累了许多技巧,这些技巧能够使我们更好地发挥系统的性能和实现更多的...

    Oracle 11g RAC 基本概念

    为了确保高可用性,Oracle 11g RAC 提供了两种连接失败转移机制:TAF (Transparent Application Failover) 和 FCF (Fast Connect Failover)。 ##### 1. TAF (透明应用程序故障转移) TAF 允许 Oracle Net 自动将...

    Oracle SOA 套件和 RAC 数据库事务一致性配置指南

    - **JDBC 驱动程序**:确保使用的 JDBC 驱动程序支持 XA 事务处理,并且与 Oracle RAC 数据库兼容。正确的驱动程序版本是实现稳定、高效数据访问的关键。 - **Oracle RAC 数据库**:Oracle Real Application ...

    关于WebLogic JDBC的基本配置知识以及常见问题的解

    1. **JDBC连接池配置** - **配置连接池 FOR WEBLOGIC 8.1**:在WebLogic 8.1中,管理员可以通过管理控制台或XML配置文件来创建和配置JDBC数据源,设置连接池大小、超时参数、验证机制等。配置步骤包括定义JDBC数据...

    oracle12c-jdbc全量包

    4. ** JDBC Universal Driver**:Oracle JDBC Universal Driver是一个多协议驱动,能够与Oracle数据库的不同版本和部署模式(例如,RAC、Dataguard等)兼容。 在Oracle 12c的JDBC全量包中,你会找到适用于不同JDK...

    构建最高可用Oracle数据库系统 Oracle 11gR2 RAC管理、维护与性能优化

    第6章 RAC的高可用性连接 6.1 Oracle Net Service 6.1.1 Oracle Net结构 6.1.2 Oracle Net命名方法 6.1.3 Oracle Net工作原理 6.1.4 Oracle Net Listener工作原理 6.1.5 JDBC工作原理 6.2 Oracle高可用性连接...

    Oracle 19c RAC on Linux安装手册.zip

    Oracle JDBC驱动支持连接池和RAC的负载均衡,使得应用能够透明地利用RAC的特性。 总之,部署Oracle 19c RAC on Linux是一项涉及多个层面的工作,需要对Linux系统、网络配置、Oracle数据库及Java应用有深入理解。每...

Global site tag (gtag.js) - Google Analytics