技术开发 频道

Oracle RAC 配置和测试

【IT168 技术文档】
    测试 RAC 配置

    要测试 RAC 配置,请执行以下操作:

    1.启动配置为群集 RAC 成员的 Oracle 节点或 Oracle DB 实例。

   2. 然后使用下面提供的示例代码进行测试(修改用户 URL 和数据源)。

    还可以使用 WLS 控制台的 JDBC 连接池中的 TestPool 工具来测试池。

    备注:从 WLS 的角度来看,RAC 是以单一连接池和单一数据源形式配置的。

    3.测试(执行控制台中的 Testpool)后,关闭一个节点。

    一切应会运行良好。

    4.关闭另一个节点。

    将会发生故障。

    5.开启一个节点。

    一切应会运行良好。

   在 Oracle 端进行 DB 控制。

    请注意,除配置较复杂外,RAC 调试(下文中论述)的执行步骤与任何其它 JDBC 问题的调试步骤均相同。您应该先获得 jdbc.log 和配置信息,在控制台中测试池,然后使用数据源来测试池。

    如果出现错误,请检查 JNDI 树以确认数据源是否可用。

    基本调试

    1.将此问题作为标准 JDBC 连接池问题来对待。

    2.确认 config.xml 。

    以下是配置 JDBC 连接来使用 RAC 的示例代码:
 
<JDBCConnectionPool ConnLeakProfilingEnabled="true" DriverName="oracle.jdbc.driver.OracleDriver" Name="RACTest" Password="{3DES}SnVOJbMRf3M=" Properties="user=mks" Targets="" TestConnectionsOnCreate="true" TestConnectionsOnRelease="true" TestConnectionsOnReserve="true" TestTableName="SQL SELECT 1 FROM DUAL" URL="jdbc:oracle:thin:@(description=(address_list= (address=(host=172.18.137.231) (protocol=tcp)(port=1521))(address=(host=172.18.137.230)(protocol=tcp) (port=1521)) (load_balance=yes)(failover=yes))(connect_data=(service_name= slrac.bea.com)))"/> <JDBCTxDataSource EnableTwoPhaseCommit="true" JNDIName="RACTest1" Name="RACTest1" PoolName="RACTest" Targets=""/>
    3.安装一个简单的、可以对 RAC 数据库进行测试的 Java 应用程序。提供了以下示例。

    使用该示例前的准备:

    a.设置环境(例如 user_projects/domains/myserver) 

   UNIX 系统:>../setEnv.sh

    Windows 系统:setEnv 

     b.将 CLASSPATH 设置为指向 racTest1.class
(例如,设置 CLASSPATH=.;%CLASSPATH%。如果是 UNIX 系统,请设置 export CLASSPATH=.:$CLASSPATH)

    还请注意,本示例只测试基本 sql 语句,不测试事务。
Sample Test Code- Standard Data Source test //package examples.jdbc.datasource; import java.sql.*; import java.util.*; import javax.naming.*; public class racTest1 { public static void main(String argv[]) throws Exception { java.sql.Connection conn = null; java.sql.Statement stmt = null; try { // ============== Make connection to database ================== // Obtain a Datasource connection from the WebLogic JNDI tree. Context ctx = null; // Put connection properties in to a hashtable. Hashtable ht = new Hashtable(); ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); ht.put(Context.PROVIDER_URL, "t3://mks4:6151"); // Get a context for the JNDI look up System.out.println("before init ctx connection...n"); ctx = new InitialContext(ht); System.out.println("after init ctx connection...n"); javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup ("RACTest1"); conn = ds.getConnection(); System.out.println("Making connection...n"); // execute some SQL statements to demonstrate the connection. stmt = conn.createStatement(); try { stmt.execute("drop table empdemo"); System.out.println("Table empdemo dropped."); } catch (SQLException e) { System.out.println("Table empdemo doesn't need to be dropped."); } stmt.execute("create table empdemo (empid int, name varchar(30), dept int)"); System.out.println("Table empdemo created."); int numrows = stmt.executeUpdate("insert into empdemo values (0, 'John Smith', 12)"); System.out.println("Number of rows inserted = " + numrows); numrows = stmt.executeUpdate("delete from empdemo where empid = 0"); System.out.println("Number of rows deleted = " + numrows); } catch (Exception e) { System.out.println("Exception was thrown: " + e.getMessage()); } finally { try { if (stmt != null) stmt.close(); if (conn != null) conn.close(); } catch (SQLException sqle) { System.out.println("SQLException during close(): " + sqle.getMessage()); } } } }

    4.测试池

    树中 JNDI 条目中的数据源 - 注意 RACTest1(本示例中的 RAC 数据源)。

    5.确保数据库已启动并正在运行。

    6.查看启动脚本以确定 JDBC 驱动程序。

    启动脚本中的 CLASSPATH 应指向 JDBC 驱动程序。

    指向的应该是 ojdbc14.jar,它应在 weblogic jar 之前。

0
相关文章