Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1018154
  • 博文数量: 297
  • 博客积分: 11721
  • 博客等级: 上将
  • 技术积分: 3431
  • 用 户 组: 普通用户
  • 注册时间: 2009-05-25 10:21
文章分类

全部博文(297)

文章存档

2016年(9)

2011年(71)

2010年(137)

2009年(80)

分类: C/C++

2010-07-20 11:42:11

Obtaining the IBM DB2 Driver for ODBC and CLI

The IBM® DB2® Driver for ODBC and CLI is not part of the DB2 Client or the DB2 Runtime Client. It is available to download from the internet, and it is on the DB2 Version 9 install CD.

To obtain the IBM DB2 Driver for ODBC and CLI, you need:
  • internet access, so you can download the driver; or
  • a DB2 Version 9 installation CD.
You can obtain the IBM DB2 Driver for ODBC and CLI by doing either of the following:
  • Search for the IBM DB2 Driver for ODBC and CLI driver on the IBM Fix Central Web site at: . Data Server clients and drivers are found under the Information Management Product Group and IBM Data Server Client Packages Product selection. Select the appropriate Installed Version and Platform and click Continue. Click Continue again on the next screen and you will be presented with a list of all client and driver packages available for your platform.

    or

  • Copy the driver from the DB2 Version 9.1 install CD.

The driver is in a compressed file called “ibm_data_server_driver_for_odbc_cli.zip” on Windows® operating systems, and “ibm_data_server_driver_for_odbc_cli.tar.Z” on other operating systems.

The compressed file is located on the CD at:
\db2\\clidriver
where is one of:
aix
hpipf
hpux
linux
linux390
linux64
linuxamd64
linuxppc
sunos
Windows
For example,
  • on Windows the driver is located at:
    /db2/Windows/clidriver/ibm_data_server_driver_for_odbc_cli.zip
  • on AIX the driver is located at:
    /db2/aix/clidriver/ibm_data_server_driver_for_odbc_cli.tar.Z
  • on Linux the driver is located at:
    /db2/linux/clidriver/ibm_data_server_driver_for_odbc_cli.tar.Z
DB2 数据库的客户机连通性选项在 DB2 V9 之后引入了新的轻量级驱动程序 DB2 CLI Driver(有时被称为 Thin Client),它为使用 CLI API 的应用程序提供运行时环境,降低了分布式企业应用中 DB2 客户机维护成本。本文详细给出了 DB2 CLI Driver 的工作原理,并通过对比新旧客户机在 SAP 系统中的使用方法,进一步说明了采用 DB2 CLI Driver 在大规模企业应用中的优势。

IBM DB2 for Linux, Unix, and Windows 已经广泛应用在企业生产和管理的各个领域。由于连接 DB2 数据库的应用程序的需求不同,因此,DB2 提供了一系列不同的 DB2 客户机,它允许 DB2 客户端应用程序连接到 DB2 数据库服务器。

随着 DB2 版本从 V8 发展到 V9,DB2 客户机也不断的进行演变。 DB2 客户机提供了从标准部署,轻量级内核,以及指纹(fingerprint)级别的不同的连接方案。表 1 中列出了 IBM DB2 for Linux, Unix, and Windows 在 V8,V9.1,V9.5 所具有的不同连接方式。



DB2 V8 DB2 V9.1 DB2 V9.5 SAP Term
Application Development Client /
Administration Client
DB2 ClientIBM Data Server ClientDB2 Client
Run-Time ClientDB2 Runtime ClientIBM Data Server Runtime ClientDB2 Runtime Client
N/AIBM DB2 Driver for ODBC and CLIIBM Data Server Driver for ODBC and CLIDB2 CLI Driver
Universal Driver for SQLJ and JDBCIBM DB2 Driver for JDBC and SQLJIBM Data Server Driver for JDBC and SQLJDB2 JDBC Driver





回页首


在 DB2 V8 的所有客户机中,尽管 Run-Time Client 占用资源较少。但是实际运行时仍然会占用较大的内存资源和磁盘空间。并且,当客户期望连接到 DB2 数据库时,他需要在其不同的客户机上分别安装 DB2 Run-Time Client 。因此,Run-Time Client 并不能满足那些移动用户的需要,并且它不易于应用程序的灵活部署。

虽然在 DB2 V8.2 版本中引入了基于 Windows 平台的 Run-Time Client Lite 。 Run-Time Client Lite 比 Run-Time Client 占用的内存资源要小,但是它不支持客户机迁移,也不能和其他的 DB2 客户机并存,影响了它的应用范围。

因此,在 DB2 V9 中引入了一种新的客户机驱动程序— DB2 Driver for ODBC and CLI,它是为 ODBC(Open Database Connectivity)和 CLI(Call Level Interface)应用程序添加的一个轻量级的驱动程序。

与其他的客户机相比,它占用更小的系统资源,并且具有更加灵活的部署方式。





回页首


DB2 CLI Driver 在 DB2 V9.1 版本中的全称是 DB2 Driver for ODBC and CLI 。顾名思义,其为使用它的应用程序提供了 2 种不同形式的数据库连接方式。

  • 通过 ODBC 间接访问 DB2 数据库
  • 通过 DB2 CLI 提供的接口函数来直接访问 DB2 数据库

不同的是,在 DB2 V9.5 版本中,这种通过 ODBC 或 CLI 方式访问的驱动被称作 Data Server Driver for ODBC and CLI 。

由于本文的重点在于阐述 DB2 CLI 方式在大规模企业应用中的优势,为下文表述清晰,因此将通过 CLI 客户机进行连接的方式称为 DB2 CLI Driver 连接方式,而通过 ODBC 进行连接的方式称为 DB2 ODBC Driver 连接方式。

DB2 CLI Driver 作为一种连接 DB2 数据库的轻量级的可调用 SQL 接口,为 C/C++ 的应用程序访问 DB2 数据库提供了执行 SQL 语句的功能接口。 DB2 CLI 是基于 Microsoft ODBC 和 X/Open 以及 ISO 调用接口标准创建的。


图 1. DB2 Driver for ODBC and CLI 
连接方式示意图

下面我们将重点介绍 DB2 Driver for ODBC and CLI 中的第二种方式,即通过 DB2 CLI Driver 来直接访问 DB2 数据库。以 Unix 平台下的 DB2 CLI Driver 为例,其目录结构如下表 2 所示。从目录结构中可以看出,DB2 CLI Driver 是一个轻量级的客户机驱动程序。它仅包括 DB2 跟踪工具,DB2 服务级别显示工具和问题分析和环境收集工具,以及开发 CLI 的 include 文件和 CLI 动态加载库等。 Windows 平台的目录结构略有不同。





| - - [adm]
` - - db2trc · DB2 跟踪工具
| - - [bin]
| - - db2level · DB2 服务级别显示工具
` - - db2support ·问题分析和环境收集工具
| - - [bnd]
| - - [cfg]
| - - [conv]
| - - [db2dump]
| - - [include] ·开发 CLI 的 include 文件
| - - sqlca.h
| - - sqlcli.h

` - - sqlsystem.h
| - - [lib]
` - - libdb2.so · CLI driver 的动态加载库

| - - [license]
| - - [msg]
| - - [security64]


应用程序可以简单的通过 CLI Driver 提供的 C/C++ 的库函数来初始化环境,连接数据库,调用 SQL 语句,最后释放数据库连接和环境。其通过 CLI Driver 来访问数据的流程如图 2 所示。通过 DB2 CLI Driver 提供的 API 函数,开发人员可以轻松的通过 CLI 实现对数据库的访问操作。



图 2. DB2 CLI Driver 访问数据库流程图

DB2 CLI Driver 在应用中具有以下特点:


DB2客户机占用的磁盘空间
DB2 CLI Driver50 MB*
DB2 Run-Time Client50 - 60 MB
注:需要额外的 20 MB 来存储 DB2 实例
DB2 Administration Client125 MB
注:不包括 JRE,并且需要额外的 20 MB 来存储 DB2 实例
DB2 Application Development Client130 – 160 MB
注:不包括 JDK,并且需要额外的 20 MB 来存储 DB2 实例

* 数据来源 SAP Note 1091801,其建议为 DB2 CLI Driver 保留 50 MB 的空间




回页首

SAP NetWeaver 7.0 SR3 之前的 SAP 版本默认使用 DB2 Runtime Client,也被称为旧客户机连通方式。这种方式需要在每个 SAP 应用服务器上具有一个本地 DB2 实例为其提供 DB2 CLI 库。如果 SAP 应用服务器与数据库是同一个主机,那它可以使用已有的 DB2 实例。如果是远程应用服务器,那就需要有一个本地 DB2 Runtime Client 实例。这就造成在每个应用服务器上都需要维护一个 DB2 Runtime Client,每次安装 DB2 补丁或升级到一个更高的数据库版本需要在每个应用服务器上执行手工升级操作。

从 SAP NetWeaver 7.0 SR3 版本开始引入了 DB2 CLI Driver(DB2 版本是 V9.1 或更高)替代 DB2 Runtime Client,它被称为新客户机连通方式。这种 CLI 驱动程序存储在一个可供所有 SAP 应用服务器共享的目录上。当 SAP ABAP 应用服务器启动时,CLI 驱动程序会从共享目录拷贝到本地目录。同样的机制也适用于 Java 应用服务器的 JDBC 驱动程序。这样带来的好处是:

  • CLI 驱动程序不需要在应用服务器上安装本地副本
  • 大大简化了 DB2 客户机的维护。由于应用服务器使用共享的 CLI 驱动程序,你只需要维护连接到 DB2 数据库服务器的连接数据。当需要安装 DB2 补丁或数据库移植时,该客户机程序仅需要在共享目录中安装一次。当所有应用服务器重新启动时,它们就会自动使用新版本的 DB2 CLI 驱动程序。

通常我们所处的都是分布式 SAP 环境,即由一个 SAP Central instance 和多个 SAP Dialog instance 组成。图 3 是一个典型的 SAP 系统,包括一个 Central instance 和两个 Dialog instance,其中 Central instance 安装在数据库服务器上。我们会比较在该环境中安装和配置新旧客户机的区别。



图 3. 典型的 SAP 系统


目录文件内容
$(DIR_GLOBAL)/db6db2cli.iniCLI 配置文件
$(DIR_GLOBAL)/db6/jdbcdb2jcc.jar
db2jcc_license_cu.jar
jdbcdriver.lst
JDBC 连接
$(DIR_GLOBAL)/db6/db2dumpdb2diag.logCLI 驱动诊断日志
$(DIR_GLOBAL)/db6/<(OS-DB2>clidriver.lst
db2_clidriver
某 操作平台的 CLI 驱动

修改 db2cli.ini 文件,配置 DB2 连接和 db2diag.log 路径。

[] 
Database=
Protocol=tcpip
Hostname=

Servicename=
[COMMON]
Diagpath=/usr/sap//SYS/global/db6/db2dump


步骤 2 .在 Dialog instance 所在服务器上加载 Central instance 的 /sapmnt//global 和 /sapmnt//profile 目录。具体步骤如下:

在 Central instance 上:

Export /sapmnt//global 
Export /sapmnt//profile
Export /sapmnt//exe (ONLY IF HOMOGENOUS SYSTEM)

在 Dialog instance 上以 root 用户登陆:

 mkdir – p /sapmnt//global 
mkdir – p /sapmnt//profile
mkdir – p /sapmnt//exe
mount :/sapmnt//global /sapmnt//global
mount :/sapmnt//profile /sapmnt//profile
mount :/sapmnt//exe /sapmnt//exe

步骤 3 .安装 Dialog instance 。新安装的 Dialog instance 会采用 DB2 CLI 方式连接数据库。


图 4. DB2 Runtime Client 维护


图 5. DB2 CLI Driver 维护

更让人欣喜的是,SAP 7.00 及以上版本,采用一种“自动同步”机制。当应用服务器启动时,使用 sapcpe 拷贝 SAP kernel 到应用服务器本地 kernel 目录,该机制也适用于 DB2 CLI Driver 。当 Dialog instance 启动时,系统会检查 /usr/sap//SYS/global 下的 DB2 CLI Driver 文件是否比 /usr/sap//D[VEBMGS]/exe/db6_clidriver 有更新,如果有,就将其拷贝至本地目录。这样使得更新 CLI 驱动变得十分容易,而且可以在应用服务器运行期间替换 DB2 CLI Driver,当应用服务器下次启动时就会使用最新的 DB2 CLI Driver 。

如果想确认 Dialog instance 使用哪种类型的 DB2 客户机,可以用 adm 用户登陆到想检查的应用服务器,执行 R3trans -x 命令。 R3trans 会加载 DB2 库并连接到数据库,在当前目录下生成日志文件 trans.log 。在该日志中搜索条目“ DB2 library ”。

1 .如果使用 DB2 CLI driver,DB2 库应当从 /usr/sap//SYS/global/db6//db6_clidriver/lib 目录加载,并且在日志中出现“ Running with CLI driver ”。下面是一个示例输出:


4 ETW000 [dev trc, 00000] DB2 library successfully loaded DB2 library
'/usr/sap/LR1/SYS/global/db6/SUNOS_64/db6_clidriver/lib/libdb2.so' successfully loaded

4 ETW000 [dev trc, 00000] Running with CLI driver 23907 0.188782

2 .如果使用 DB2 Runtime Client,DB2 库应当从 /db2/db2/sqllib/lib64 目录加载。下面是一个示例输出:


4 ETW000 [dev trc, 00000] DB2 library successfully loaded DB2 library
'/db2/db2ax3/sqllib/lib64/libdb2.so' successfully loaded

如果 SAP 系统满足下列条件:

  • SAP Basis 版本 7.00,Basis Support Package 14 或以上,DB2 9.1 或以上版本
  • SAP 7.00 系统使用 DB2 runtime client,是由于系统由 SAP 升级或从 SAP Basis 7.0 SR2 或是更低版本安装而来

我们就可以将其从旧客户机 DB2 runtime client 方式转向新客户机 DB2 CLI Driver 方式,具体步骤请参考 SAP note 1091801 。





回页首


本文介绍了 DB2 不同的连通方式,阐述 DB2 CLI Driver 的工作原理和优势,并通过对比新旧客户机在 SAP 系统中的使用特点,进一步说明了采用 DB2 CLI Driver 在大规模企业应用中的优势。

阅读(3355) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~