[IBM CLoud] Linux 환경에서 DB2 Client를 이용해서 접속하는 방법

■ DB2클라이언트를 이용하여 IBM DB2 클라우드에 접속하기

기존 DB2 클라이언트를 이용해서 DB2에 접속을 할 수 있습니다. Cloud상의 DB2도 On-premise에 접속하는 것처럼 똑같은 명령어로 접속하고 조회할 수 있습니다. 단. 환경설정은 불가능합니다. DB2 서버 환경설정은 클라우드의 콘솔 상에서만 설정할 수 있습니다. 클라이언트는 단지 클라이언트의 환경만 설정할 수 있습니다. 또한 반드시 SSL로만 접속이 가능합니다(Lite 버전). 그리고 보안상의 이유로도 가능하면 SSL을 이용해서 접속하는 방법을 추천드립니다.

 

 준비사항

1. gskit 설치 및 DB2 Client 설치.

IBM 공식문서를 참고하면 gskit이라는 패키지를 설치해야 한다고 합니다.

gskit은 IBM에서 다음과 같이 소개하고 있습니다.

 

Db2®의 원시(native) 암호화 기능은 IBM® Global Security Kit(GSKit)의 암호화 및 SSL/TLS 기능을 사용합니다. GSKit은 네트워크를 통한 보호된 Db2 통신을 사용 가능하게 하는 SSL 및 TLS 프로토콜을 구현하는 데 사용됩니다.

 

즉 SSL을 이용하기 위해서 반드시 설치해야 하는 패키지입니다. 하지만 이 gskit은 일반 사용자들, 즉 무료 사용자들은 다운로드 받을 수 없습니다. 유료로 가입되어 있는 고객사들만이 다운로드가 가능합니다. 이 얘기는 Linux에 클라이언트를 설치해도 사용을 못할 수도 있습니다. 참고로 DB2 Client버전 gskit이 포함되어 있지 않습니다. 그러나 방법은 찾아보면 역시 있습니다.

바로 DB2 서버를 설치하는 것입니다. DB2 서버 버전은 gskit까지 모두 설치할 수 있습니다. 또한 서버 버전인 만큼 클라이언트까지 모두 포함되어 있습니다. 즉 클라이언트 설치와 gskit 설치가 모두 해결되는 것입니다.

 

2. DB2 서버 설치 방법

http://www.ibm.com/support/pages/download-db2-fix-packs-version-db2-linux-unix-and-windows
 

Download DB2 Fix Packs by version for DB2 for Linux, UNIX and Windows

Download DB2 Fix Packs by version for DB2 for Linux, UNIX and Windows

www.ibm.com

다음의 URL에서 DB2 11.1에서 최신 픽스팩이 적용된 버전을 다운로드 받습니다. 이 글을 작성할 시 최신 버전은 Mod 4 Fix Pack 5 입니다. 클라우드의 11.5의 버전은 이 페이지에서는 0이므로 안정성이 그리 높지는 않을거라 판단됩니다.

클라이언트 버전은 FIXPACK 4까지 나왔지만 위에서 말씀드렸듯이 GSKIT이 제공되지 않기 때문에 클라우드 DB2에 접속할 수 있는 방법이 없습니다. 만약 gskit을 다운로드 받을 수 있는 유료 사용자라면 다음 사이트에서 최신 픽스팩이 적용된 11.5 버전을 다운로드 받으시기 바랍니다.

http://www.ibm.com/support/pages/download-db2-fix-packs-version-db2-linux-unix-and-windows
 

Download DB2 Fix Packs by version for DB2 for Linux, UNIX and Windows

Download DB2 Fix Packs by version for DB2 for Linux, UNIX and Windows

www.ibm.com

■ DB2 설치 방법

1. 서버 설치

모든 설치 작업은 root로 작업합니다. 특정 디렉토리에서 압축된 파일을 풉니다. 압축이 다 풀리면 다음 경로로 이동합니다.

shell> tar -zxvf v11.1.4fp5_linuxx64_server_t.tar.gz

shell> cd server_t/install

shell> ./db2_install

Read the license agreement file in the db2/license directory.

***********************************************************
To accept those terms, enter "yes". Otherwise, enter "no" to cancel the install process. [yes/no]
yes
 
 
Default directory for installation of products - /opt/ibm/db2/V11.1

***********************************************************
Install into default directory (/opt/ibm/db2/V11.1) ? [yes/no] 
yes
 
 
Specify one of the following keywords to install DB2 products.

  SERVER 
  CONSV 
  CLIENT 
  RTCL 
 
Enter "help" to redisplay product names.

Enter "quit" to exit.

***********************************************************

server[root@singledb server_t]# ./db2_install
Read the license agreement file in the db2/license directory.

***********************************************************
To accept those terms, enter "yes". Otherwise, enter "no" to cancel the install process. [yes/no]
yes
 
 
Default directory for installation of products - /opt/ibm/db2/V11.1

***********************************************************
Install into default directory (/opt/ibm/db2/V11.1) ? [yes/no] 
yes
 
 
Specify one of the following keywords to install DB2 products.

  SERVER 
  CONSV 
  CLIENT 
  RTCL 
 
Enter "help" to redisplay product names.

Enter "quit" to exit.

***********************************************************
server
***********************************************************
Do you want to install the DB2 pureScale Feature? [yes/no] 

no

이와 같이 하게 되면 서버 설치가 진행이 됩니다.

 

2. 인스턴스 계정 준비

db2는 OS유저를 이용해서 Database에 접속을 허용합니다. 그러나 클라이언트는 접속유저가 아닌 접속 관리 유저가 됩니다. 그래서 별도로 홈 디렉토리를 만들어 관리를 합니다.

shell> useradd db2inst1

 

3. 인스턴스 준비

설치 디렉토리의 instance디렉토리로 이동합니다.

기본설치를 하였다면 /opt/ibm/db2/V11.1에 엔진이 설치가 되었을 것입니다.

shell> cd /opt/ibm/db2/V11.1/instance
shell> ./db2icrt -u db2inst1 db2inst1

이렇게 하면 인스턴스 계정 생성 과정이 보이고 완료가 됩니다.

 

■ SSL을 이용하여 Cloud DB2에 접속하기.

1. 클라우드 접속환경 확인하기.

클라우드 DB2의 콘솔에 들어가서 왼쪽의 Administoration 항목을 클릭합니다.

위의 탭들중 6번째의 Connection을 클릭합니다.

아래에  Download SSL Certificate를 다운로드 하고 보관합니다.

 

2. 신규 접속 유저 생성하기

User Management로 이동합니다.

User ID : 접속 유저 아이디

Email : 접속 유저 아이디의 이메일

Password : 접속 암호

Confirm password : 위에서 입력한 암호 입력(참고로 암호는 15자 이상 사용해야 합니다.)

User Privilege : 접속유저의 권한. 테스트이기 때문에 Administrator을 선택합니다.

 

3. gskit 설정하기

먼저 GSKIT Library 환경을 먼저 구성합니다. gskit library 추가합니다. 그리고 root 유저로 환경을 설정합니다.

shell > cd /etc/ld.so.conf.d/
shell> vi gskit.conf
/opt/ibm/db2/V11.1/lib64/gskit

 

위의 경로를 저장하고 빠져 나온 후 다음 명령어를 입력합니다.

shell > ldconfig

 

4. gskit SSL 암호화 설정하기

다음 디렉토리로 이동합니다.

shell> cd /opt/ibm/db2/V11.1/gskit

 

다음 명령을 수행합니다.

shell > gsk8capicmd_64 -keydb -create -db "mykeystore.kdb" -pw "mypassw0rd" -stash

참고로 위의 -pw옵션에서 암호는 원하는 암호로 입력합니다.

 

shell> gsk8capicmd_64 -keydb -create -db "mykeystore.kdb" -pw "mypassw0rd" -stash

-pw에서 위에서 사용했던 암호를 입력합니다.

 

shell> gsk8capicmd_64 -cert -add -db "mykeystore.kdb" -pw "mypaswo0rd" -label ACIBLUDB_SSL -file /opt/ibm/db2/V11.1/gskit/DigiCertGlobalRootCA.crt

위에 다운로드 받은 SSL Certtfication(SSL인증서)파일을 위의 -file이란 옵션에 입력합니다.

 

생성된 키 파일에 권한을 설정합니다.

shell > chmod 644 mykeystore.*

 

* 중요사항

반드시 gskit이 설치된 디렉토리인 /opt/ibm/db2/V11.1/gskit에서 반드시 관련 키 파일들을 생성해야 합니다. 다른 디렉토리에서 생성시 이 키 파일들이 인식이 되지 않습니다.

 

 

5. DB2 환경 설정

암호화 키 등록

shell> db2 update dbm cfg using SSL_CLNT_KEYDB /opt/ibm/db2/V11.1/gskit/mykeystore.kdb
shell> db2 update dbm cfg using SSL_CLNT_STASH /opt/ibm/db2/V11.1/gskit/mykeystore.sth

 

접속 환경 등록

shell > db2 catalog tcpip node ACICLD_S remote xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx.xxxxxxxxxxxxxxxxx.databases.appdomain.cloud server 31489 security SSL

remote라는 항목과 server라는 항목이 있는데 이것은 DB2 Console에 정보가 나와 있습니다.

remote는 콘솔정보의 Host name이며 server는 콘솔상의 Port  number입니다.

 

shell > db2 catalog db BLUDB as ACIBLU_S at node ACICLD_S

위와 같이 데이터베이스를 등록합니다.

 

6. 접속테스트

shell > db2 connect to ACIBLU_S user mydb2inst1
Enter current password for mydb2inst1: 

   Database Connection Information

 Database server        = DB2/LINUXX8664 11.5.1.0
 SQL authorization ID   = MYDB2INS...
 Local database alias   = ACIBLU_S

shell > db2 list tables for all
Table/View                      Schema          Type  Creation time             
------------------------------- --------------- ----- --------------------------
AUDIT                           AUDIT           T     2020-08-20-17.10.28.948166
CHECKING                        AUDIT           T     2020-08-20-17.10.29.003366
CONTEXT                         AUDIT           T     2020-08-20-17.10.29.193578
EXECUTE                         AUDIT           T     2020-08-20-17.10.29.290412
OBJMAINT                        AUDIT           T     2020-08-20-17.10.29.041760
SECMAINT                        AUDIT           T     2020-08-20-17.10.29.079989
SYSADMIN                        AUDIT           T     2020-08-20-17.10.29.118923
VALIDATE                        AUDIT           T     2020-08-20-17.10.29.156183
POLICY                          DB2INST1        T     2020-08-20-17.10.26.340947
USER_TABLE                      DB2INST1        T     2020-08-20-17.10.25.373640
ADMIN_EDITOR_RESULT             IBMCONSOLE      T     2020-09-11-13.01.57.312799

 

 

gskit 관련 에러 확인하기.

gskit을 설정하다 보면 몇번의 에러를 거칠수도 있습니다.

제가 만났던 에러들은 다음과 같습니다.

1. SQL10013N  The specified library "GSKit Error: 201" could not be loaded. 
shell> db2 connect to ACIBLU_S user mydb2inst1
Enter current password for i4zelpb0: 
SQL10013N  The specified library "GSKit Error: 201" could not be loaded.

암호화 파일이 다른 디렉토리에 있는 경우.

 

2. SQL10013N  The specified library "GSKit Error: 408" could not be loaded.  

shell> db2 connect to ACIBLU_S user mydb2inst1
Enter current password for i4zelpb0: 
SQL10013N  The specified library "GSKit Error: 408" could not be loaded.  

암호화 파일에 읽기 권한이 없어서 나오는 에러.

mykeystore 파일들에게 읽기 권한을 부여한다.

shell > chmod 644 mykeystore.*

 

3. gsk8capicmd_64: error while loading shared libraries: libgsk8km_64.so: cannot open shared object file: No such file or directory

shell> gsk8capicmd_64 -keydb -create -db "mykeystore.kdb" -pw "mypassw0rd" -stash
gsk8capicmd_64: error while loading shared libraries: libgsk8km_64.so: cannot open shared object file: No such file or directory
gskit library 추가.
cd /etc/ld.so.conf.d/

 

참고 URL :

https://cloud.ibm.com/docs/Db2onCloud?topic=Db2onCloud-ssl_support
https://www.ibm.com/support/knowledgecenter/SSEPGG_9.7.0/com.ibm.db2.luw.admin.sec.doc/doc/r0054271.html
 

IBM Knowledge Center

Please note that DISQUS operates this forum. When you sign in to comment, IBM will provide your email, first name and last name to DISQUS. That information, along with your comments, will be governed by DISQUS’ privacy policy. By commenting, you are acce

www.ibm.com

 

Designed by JB FACTORY