oracle_rac_0">1、app连接oracle rac集群
连接到 Oracle RAC(Real Application Clusters)的多种配置方式
1. 使用 JDBC 连接字符串:
使用 JDBC 连接字符串是连接 Oracle RAC 的常见方式。连接字符串的格式如下:
jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(LOAD_BALANCE=on)(FAILOVER=on)(ADDRESS=(PROTOCOL=TCP)(HOST=<hostname1>)(PORT=<port1>))(ADDRESS=(PROTOCOL=TCP)(HOST=<hostname2>)(PORT=<port2>))(ADDRESS=(PROTOCOL=TCP)(HOST=<hostname3>)(PORT=<port3>)))(CONNECT_DATA=(SERVICE_NAME=<service_name>)(FAILOVER_MODE=(TYPE=select)(METHOD=basic))))
<hostname1>, <hostname2>, <hostname3>是 Oracle RAC 集群中不同节点的主机名。<port1>,<port2>, <port3>是 Oracle 监听器的端口号。<service_name> 是 RAC 数据库的服务名称。
2. 使用 TNSNAMES.ORA 文件:
在客户端计算机上配置 TNSAMES.ORA 文件,该文件包含与 Oracle RAC 集群的连接信息。在文件中定义数据库连接别名和连接描述符。然后,在客户端应用程序中使用别名作为数据库连接的目标。
ORACLERAC =(DESCRIPTION =(ADDRESS_LIST =(LOAD_BALANCEon)(FAILOVER=on)(ADDRESS = (PROTOCOL = TCP)(HOST = <hostname1>)(PORT = <port1>))(ADDRESS = (PROTOCOL = TCP)(HOST = <hostname2>)(PORT = <port2>))(ADDRESS = (PROTOCOL = TCP)(HOST = <hostname3>)(PORT = <port3>)))(CONNECT_DATA =(SERVICE_NAME = <service_name>)(FAILOVER_MODE =(TYPE=select)(METHOD=basic))))
3. 使用扫描监听器(SCAN Listener):
扫描监听器是 Oracle RAC 中的虚拟监听器,用于提供集群级别的入口。通过使用扫描监听器,客户端应用程序可以连接到 Oracle RAC 集群,而不需要了解底层的详细信息。扫描监听器会根据负载均衡策略将连接转发到适当的节点。
jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=<scan_name>)(PORT=<port>)))(CONNECT_DATA=(SERVICE_NAME=<service_name>)))
<scan_name> 是扫描监听器的名称,它提供了连接到集群的虚拟化服务名称。<port> 是监听器的端口号。<service_name>是 RAC 数据库的服务名称,用于标识需要连接的数据库。
4、java.properties
# 数据库连接信息
spring.datasource.url=jdbc:oracle:thin:@(description=(address_list= (address=(host=RAC1)(protocol=TCP)(port=1521))(address=(host=RAC2)(protocol=TCP)(port=1521)) (load_balance=yes)(failover=yes))(connect_data=(service_name=service_name)(server=DEDICATED)))
spring.datasource.username=your_username
spring.datasource.password=your_password
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
Oracle11g rac
jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = 10.24.227.35)(PORT = 1521))(CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = bjcrmdb)))
Oracle10g rac
jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=ip)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=ip)(PORT=1521))(LOAD_BALANCE=yes)(FAILOVER=on))(CONNECT_DATA=(SERVICE_NAME=)))