当前位置:IT教程网教程中心其他整理WebSphere → 教程内容

了解 Cloudscape Network Server

减小字体 增大字体 作者:佚名  来源:不详  发布时间:2007-1-8 17:38:00

级别: 初级

Soloman Barghouthi, 咨询软件工程师, IBM WebSphere Connection Management Development
Jeff Gerboth, 助理软件工程师, IBM WebSphere Product Integration

2004 年 8 月

为了帮助您使用 Cloudscape™ Network Server 和 WebSphere® Application Server,本文根据 WebSphere 的观点比较和对照了 Cloudscape 的网络服务器框架和它嵌入式框架,并且从高层次讨论了 Cloudscape 的要点和可用的 WebSphere 选项。

引言
IBM Cloudscape 是 IBM WebSphere Application Server 包含的纯 Java™、对象关系型数据库管理系统。Cloudscape Network Server 是 Cloudscape 数据库支持的两个框架中的一个。它提供了在单一系统或网络中使用 IBM DB2 JDBC Universal Driver 实现对 Cloudscape 数据库的多用户连接性,并且使用标准的分布式数据库体系结构(Distributed Database Architecture,DRDA)协议与客户查询通信。

如果您在正开发访问数据库的应用程序,本文提供的信息将会帮助您更清楚地理解 Cloudscape 选项、配置和使用 Cloudscape Network Server 和 WebSphere Application Server 的方法以及在很短的一段时间内掌握它的大多数优势的方法。

Cloudscape Network Server(以下简称 Network Server)与嵌入式框架相比较提供了不同的优势。尤其重要的是 Network Server 允许多个 JVM 并发访问数据库实例,该功能是嵌入式框架所不具有的。在 WebSphere 方面,这意味着多个 WebSphere Application Server 可以访问同一个 Cloudscape 数据库实例,例如在集群(cluster)或共存(coexistence)环境中运行。

不像嵌入式 Cloudscape,Network Server 允许您通过管理负载量使得运行在不同系统上的不同版本的 Websphere Application Server 都可以访问相同的数据库实例(图 1)。

图 1. WebSphere 环境中的 Cloudscape
图 1. WebSphere 环境中的 Cloudscape

两个框架之间其它重要的比较还包括:

  • Network Server 允许客户远程访问 Cloudscape 实例,在嵌入式框架中不具备该功能。
  • Network Server 安装时比嵌入式框架需要更多的步骤。
  • Network Server 不支持 XA 协议(到写该文章时为止)。

本文剩余部分将帮助您安装、配置和开始使用 Cloudscape Network Server 和 WebSphere Application Server。

如果您拥有 WebSphere Application Server V5.0.2 或更高版本,您已经可以使用 Network Server 开发应用和测试。如果您想使用 Netwrok Server 产品,您需要 购买许可。

在 WebSphere 环境中安装 Cloudscape
在 WebSphere Application Server V5.1.x 中,你不需要专门安装 Cloudscape Network Server Version 5.1.xx,因为适用于多平台的 Cloudscape V5.1.xx 已经被默认安装了,它包含由新近的 Network Server 框架。

然而,在 WebSphere Application Server V5.0.x 中,默认情况下,不安装 Cloudscape。用户可以选择安装 Cloudscape V5.1.xx,只需要简单地运行 WAS_HOME/cloudscape51 目录中的 installCloudscape51.bat/sh ,就可以安装 Network Server 框架。

配置 Network Server
在安装 Network Server 后配置 Network Server:

  1. 创建 Cloudscape 提供者:
    1. 在 WebSphere 管理控制台,选择 Resources => JDBC Provider => Server => New
    2. 在下拉式列表框中选择 Cloudscape Network Server Using Universal JDBC Driver,然后点击 Apply。(图 1)

      图 2. Cloudscape 配置
      图 2. Cloudscape 配置

    3. Network Server 提供者配置屏幕将会显示。该面板包含 Cloudscape Network Server 实现的类名以及装载 Cloudscape JAR 文件所需要的 classpath 等信息。classpath 需要事先填写且包含如下数据:

                          ${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc.jar                    ${CLOUDSCAPE_JDBC_DRIVER_PATH}/otherJars/db2jcc.jar                    ${CLOUDSCAPE_JDBC_DRIVER_PATH}/db2j.jar                    ${UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc_license_cu.jar

      在 classpath 中 DB2 JDBC 通用驱动程序 db2jcc.jar 文件有两个入口。因为如果在 WebSphere 环境中碰巧已经存在 DB2,那么 DB2 加载 db2jcc.jar 文件必须比 WebSphere 提供的优先级高,特别是同时在 WebSphere Application Server 中定义了 DB2 和 Network Server providers,所以需要从两个不同的目录加载该文件。
  2. 定义数据源。
    1. 选择 Data Sources(图 3),然后选择 New

      图 3. 配置 Network server 提供者
      图 3. 配置 Network server 提供者

    2. 给如下字段(field)输入值,如图 4 所示:
      • 名称(必须的)。例如, CloudscapeDataSource
      • JNDI 名称。例如, jdbc/CloudscapeDataSource 。该值在 JNDI 名称空间标识数据源。
      • Datasource Helper Classname; 如果该字段包含值:

                                com.ibm.websphere.rsadapter.DB2UniversalDataStoreHelper

        更改为

                                com.ibm.websphere.rsadapter.CloudscapeNetworkServerDataStoreHelper

        (不正确的值是由 WebSphere 管理控制台一个已知 bug 造成的。)
      • 认证别名(不显示):您可以在这里输入任何您想输入的值。默认情况下,Cloudscape 建立连接不需要 userID 和口令,因为它依靠操作系统身份验证。然而 DB2 通用驱动程序需要 userID 和口令,因为必须通过 DB2 通用驱动程序的初始身份验证,所以需要这些值。

      图 4. 配置数据源
      图 4. 配置数据源

    3. 单击 OK
  3. 配置数据源
    1. 选择步骤 2 创建的数据源。
    2. 选择 Custom Properties显示数据源定义的完整的属性列表。由于早先时候提到的管理控制台的 bug,完整的列表显示的可能是 DB2 JDBC 提供者的属性,而不是数据源的属性。出于调试目的,除以下的之外删除其它所有的属性:
      • databaseName
      • serverName
      • portNumber
      • retrieveMessagesFromServerOnGetMessage
      例如:

                          databaseName = /opt/WebSphere/AppServer50/cloudscape51/databases/cloudscapeDB                    serverName = myserver.rchland.ibm.com                    portNumber = 1527                    retrieveMessagesFromServerOnGetMessage = true                    

    3. 单击 OK
  4. 保存和重新启动服务器
  5. 在运行应用程序之前执行下面的文件启动 Network Server 进程:

                    WAS_HOME/cloudscape/bin/networkserver/startNetworkServer.bat/sh

这里是一些需要记忆的有关 Network Server 进程的要点:

  • 默认情况下,Network Server 仅仅在本地主机上监听,因此来自其它主机的客户不能访问 Network Server。为了允许来自其它主机的连接,在 ${Cloudscape_Home}/db2j.properties 文件中取消对 db2j.drda.host 属性的注释,并使 0.0.0.0 生效。
  • 0.0.0.0 在主机有多个 IP 地址的情况下表示属于主机的所有 IP 地址,因此如果只想要一个 IP 地址接受连接,用该 IP 地址替换 0.0.0.0。
  • Network Server 管理命令(如, sysinfo , stopNetworkServer )仅仅只能在服务器被启动的主机上执行,而不管 db2j.drda.host 属性的设置。
  • 在运行接受远程主机连接的 Network Server 时,为了避免安全性暴露,您必须在安全管理器(如 Java 安全管理器)下运行 Network Server。该策略的示例如下:

                    //Example set of permissions to start & use the network server, assuming the                // 'd:/WebSphere/AppServer/cloudscape/lib' directory has been secured.                grant codeBase "file:d:/WebSphere/AppServer/cloudscape/lib/-" {                permission java.io.FilePermission "${db2j.system.home}${/}-", "read, write, delete";                permission java.io.FilePermission "${user.dir}${/}-", "read, write, delete";                permission java.util.PropertyPermission "db2j.*", "read";                permission java.util.PropertyPermission "user.dir", "read";                permission java.lang.RuntimePermission "createClassLoader";                // add a permission to allow the client machines to connect                permission java.net.SocketPermission "myclientmachine.ibm.com", "accept";                };                //Required set of permissions to stop the network server, assuming you have                // secured the 'd:/WebSphere/AppServer/cloudscape/lib' directory                //Remember to fine tune this as per your environment.                grant codeBase "file:d:/WebSphere/AppServer/cloudscape/lib/-"  {                //Following is required to shutdown when server is started with -h 0.0.0.0. Note that shutdown                // can be given in this case either with -h 0.0.0.0, -h <hostname on which svr is started>                //  or without -h option                permission java.net.SocketPermission "127.0.0.1", "accept, connect, resolve";                //The Following are required when server is started with "-h localhost" or without the -h option                //permission java.net.SocketPermission "localhost", "accept, connect, resolve";                //permission java.net.SocketPermission "127.0.0.1", "accept, connect, resolve";                //The following is only required if the server is started with the -h <hostname> option                // (else shutdown access will be denied) where hostname is not 0.0.0.0.                //permission java.net.SocketPermission "<hostname>:*", "accept, connect, resolve";                };

  • 假定策略(policy)文件在 d:/nwsvr.policy 中,为了在默认的安全管理器(仅仅在本地主机上监听)中启动 Network Server,运行以下步骤:

                    java -Djava.security.manager -Djava.security.policy=d:/nwsvr.policy                com.ibm.db2j.drda.DB2jServer start

创建 Network Server 数据库
在创建数据库时,您有三个选项:

  1. 使用 Cloudview
    1. 执行 startNetworkServer 命令。例如:

                          /opt/WebSphere/AppServer50/cloudscape51/bin/networkServer/startNetworkServer.sh

    2. 启动 cview(位于 WAS_HOME/cloudscape/bin/networkserver/cview.bat/sh )。
    3. 在 cview 对话框的连接选项卡,为下列项指定值:
      • 前缀: jdbc:db2j:net:
      • 主机
      • 端口
      • 用户名、口令:这些是任意值(如前面提到的,需要通过 DB2 通用驱动程序安全性)。

      图 5. 使用 Cloudview 创建数据库
      图 5. 使用 Cloudview 创建数据库

    4. 选择 File => New => Database.
    5. 指定名称,然后点击 OK
  2. 使用 ij.sh/bat

    该命令行处理器工具 ij.sh/bat 位于 WAS_HOME/cloudscape/bin/networkServer/ 目录中。使用该工具:
    1. 执行 startNetworkServer 命令。例如:
      
      										

      /opt/WebSphere/AppServer50/cloudscape51/bin/networkServer/startNetworkServer.sh

    2. 执行 ij.bat/sh
    3. 执行命令(包括单引号和双引号): connect '"path to DB;create=true"' . For example:

                          ij> connect '"/opt/WebSphere/AppServer50/cloudscape51/databases/cloudscapeDB;create=true"';                    Ij>exit;

  3. 使用 WebSphere 管理控制台

    在 WebSphere 管理控制台的 databaseName 数据源自定义属性中,把 ";create=true" 增加到数据库名称中。例如,如果想连接名称为 mydatabase 的数据库,那么您需要在 WebSphere Application Server 的数据库名称自定义属性中指定如下内容:

                    <PATH_TO_DATABASE>/mydatabase;create=true

    如果 mydatabase 还不存在,该命令使得 Network Server 在指定的路径中创建 mydatabase。如果数据库已经存在了,将忽略 create=true 语句。

调试和跟踪
为了获得易读的错误消息,配置您的数据源并且设置 retrieveMessagesFromServerOnGetMessage 自定义属性为 true。该属性把对标准的 JDBC SQLException.getMessage() 的所有调用定向到调用服务器端的存储过程,该过程重新得到易读的错误消息文本。

为了启用 Network Server 驱动程序活动,设置 WAS.database=all=enabled 跟踪字符串。用户同样可以跟踪 Cloudscape 服务器活动通过设置如下的 Cloudscape 属性(位于 CLOUDSCAPE_HOME/db2j.properties ):

            db2j.infolog.append=true            db2j.language.logStatementText=true            db2j.stream.error.logSeverityLevel=0            db2j.language.logStatementText=true // used for logging statements that get executed against the database.

结束语
本文提供的信息帮助您理解一般的 Cloudscape Network Server 安装选项、创建和配置 Cloudscape 数据库的方法以及配置 Network Server 的方法,以便您可以在 WebSphere Application Server 环境中开始使用 Cloudscape Network Server 增强的功能,这样可以减少数据库应用程序开发的时间和费用。

广告位置