简体   繁体   English

如何从远程 Db2 实例连接到 IBM Db2 Event Store 实例?

[英]How do I connect to an IBM Db2 Event Store instance from a remote Db2 instance?

I have a Db2 instance and I am trying to connect it to a remote IBM Db2 Event Store cluster.我有一个 Db2 实例,我正在尝试将它连接到远程 IBM Db2 Event Store 集群。 I have been able to connect the Db2 CLP client, is it possible to have the Db2 instance see the tables in the Db2 Event Store cluster as well like if they were local tables ?我已经能够连接 Db2 CLP 客户端,是否可以让 Db2 实例查看 Db2 事件存储集群中的表,就像它们是本地表一样?

I am using a container that already contains the latest Db2 11.5 instance, and that can be downloaded directly from docker hub .我使用的容器已经包含最新的 Db2 11.5 实例,并且可以直接从docker hub下载。 With this container, I was able to configure the Db2 client to remotely access the IBM Db2 Event Store instance following these steps, so I know I have connectivity.使用这个容器,我能够按照这些步骤配置 Db2 客户端来远程访问 IBM Db2 Event Store 实例,所以我知道我有连接。

First I started the container with the db2 instance首先我用 db2 实例启动了容器

$ docker run -itd --name db2 -e DBNAME=testdb -v ~/:/database -e DB2INST1_PASSWORD=GD1OJfLGG64HV2dtwK -e LICENSE=accept -p 50000:50000 --privileged=true ibmcom/db2

Entered the container进入容器

$ docker exec -it  db2 bash -c "su - db2inst1"

Followed the documentation for Configuring Secure Sockets Layer (SSL) support in non-Java Db2 clients遵循有关在非 Java Db2 客户端中配置安全套接字层 (SSL) 支持文档

For this, I downloaded the GsKit package within the container and installed it and used the GSKCapiCmd tool to create a key database为此, 我下载了容器内的 GsKit 包并安装了它,并使用 GSKCapiCmd 工具创建了一个密钥数据库

[db2inst1@a33d5b29ffa2 ~]$ mkdir /database/config/db2inst1/sqllib/security/keystore
[db2inst1@a33d5b29ffa2 ~]$ cd /database/config/db2inst1/sqllib/security/keystore
[db2inst1@a33d5b29ffa2 ~]$ gsk8capicmd_64 -keydb -create -db "mydbclient.kdb" -pw "myClientPassw0rdpw0" -stash

And then copied the default self-signed certificate from the server然后从服务器复制默认的自签名证书

# kubectl get pods -n dsx | grep eventstore-tenant-engine | head -1
eventstore-tenant-engine-565d74cfd8-64jv4         1/1       Running     0          21h

# kubectl exec -n dsx eventstore-tenant-engine-565d74cfd8-64jv4 -- cat /eventstorefs/eventstore/db2inst1/sqllib_shared/gskit/certs/eventstore_ascii.cert

(if you do not have access to the server, you can also use the REST API ) (如果您无权访问服务器,也可以使用REST API

With this, I created a server-certificate.cert file with it on the client, and then added the certificate to the client key database I created before:有了这个,我在客户端上用它创建了一个 server-certificate.cert 文件,然后将证书添加到我之前创建的客户端密钥数据库中:

[db2inst1@a33d5b29ffa2 ~]$ gsk8capicmd_64 -cert -add -db "mydbclient.kdb" -pw "myClientPassw0rdpw0"  -label "server" -file "server-certificate.cert" -format ascii -fips

And finally updated the configuration on the client to use that client key database I just set up:最后更新客户端上的配置以使用我刚刚设置的客户端密钥数据库:

[db2inst1@a33d5b29ffa2 ~]$ db2 update dbm cfg using 
      SSL_CLNT_KEYDB /database/config/db2inst1/sqllib/security/keystore/clientkey.kdb 
      SSL_CLNT_STASH /database/config/db2inst1/sqllib/security/keystore/clientstore.sth

Then I followed the documentation to catalog a remote TCPIP node using SECURITY SSL , as the Db2 Event Store Enterprise Edition has SSL configured by default:然后我按照文档使用 SECURITY SSL 对远程 TCPIP 节点进行编目,因为 Db2 Event Store Enterprise Edition 默认配置了 SSL:

[db2inst1@a33d5b29ffa2 ~]$ db2 catalog tcpip node nova remote 172.16.197.11 server 18730 SECURITY SSL
DB20000I  The CATALOG TCPIP NODE command completed successfully.
DB21056W  Directory changes may not be effective until the directory cache is
refreshed.

And lastly, I followed the documentation to catalog the database using AUTHENTICATION GSSPLUGIN , which is what Db2 Event Store requires:最后,我按照文档使用 AUTHENTICATION GSSPLUGIN 对数据库进行编目,这正是 Db2 Event Store 所需要的:

[db2inst1@a33d5b29ffa2 ~]$ db2 CATALOG DATABASE eventdb AT NODE  nova AUTHENTICATION GSSPLUGIN
DB20000I  The CATALOG DATABASE command completed successfully.
DB21056W  Directory changes may not be effective until the directory cache is
refreshed.

With all the set up I did, I was able to establish a connection using the user and the password to validate the configuration .通过我所做的所有设置,我能够使用用户和密码建立连接以验证配置

[db2inst1@a33d5b29ffa2 ~]$ db2 CONNECT TO eventdb USER admin USING password

   Database Connection Information

 Database server        = DB2/LINUXX8664 11.1.9.0
 SQL authorization ID   = ADMIN
 Local database alias   = EVENTDB

Now I would like to take one step further and be able to have the db2 instance see both local tables and remote Db2 Event Store tables.现在我想更进一步,能够让 db2 实例同时看到本地表和远程 Db2 事件存储表。 Is this possible ?这可能吗 ?

Yup!是的! You're actually very close.你实际上非常接近。

Given you are connected to your Db2 Event Store database, you can run:鉴于您已连接到 Db2 Event Store 数据库,您可以运行:

db2 list tables for all

or for a given schema:或对于给定的架构:

db2 list tables for schema <>

Now, since you are using Db2 11.5 docker container, you could also create a database inside the container.现在,由于您使用的是Db2 11.5 docker 容器,您还可以在容器内创建一个数据库。 For example:例如:

db2 create db testdb

After which you can connect to the database local to the container and list your "local" tables.之后,您可以连接到容器本地的数据库并列出您的“本地”表。 For example:例如:

> db2 connect to testdb
> db2 list tables for all

The key thing here is your active connection.这里的关键是您的活动连接。 When it's made to your remote Db2 Event Store database, the db2 list tables ... command will show tables for the remote database, and when connection is made on the local database, the db2 list tables ... command will show tables for the the local database.当它来远程DB2事件存储数据库所做的db2 list tables ...命令将显示表远程数据库,并在连接本地数据库上进行,在db2 list tables ...命令将显示为表本地数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM