IBM Sterling: Configurando o DB2 como Container no OpenShift

From Wiki

Procedimento

Realizando o Deploy do DB2

1) Crie um novo projeto no OpenShift para o DB2 e defina contas de serviço e permissões.

oc new-project sterling-b2bi-db2
oc create serviceaccount sterling-b2bi-db2-sa

oc adm policy add-scc-to-user privileged -n sterling-b2bi-db2 -z sterling-b2bi-db2-sa

2) Crie o arquivo db2-deploy.yaml para deploy do DB2 no openshift

apiVersion: v1
kind: Service
metadata:
  name: sterling-b2bi-db2-lb
spec:
  selector:
    app: db2
  type: LoadBalancer
  ports:
  - protocol: TCP
    port: 50000
    targetPort: 50000
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: db2
spec:
  selector:
    matchLabels:
      app: db2
  serviceName: sterling-b2bi-db2-lb
  replicas: 1
  template:
    metadata:
      labels:
        app: db2
    spec:
      serviceAccount: sterling-b2bi-db2-sa
      containers:
      - name: db2
        securityContext:
          privileged: true
        image: ibmcom/db2
        env:
        - name: LICENSE 
          value: accept 
        - name: DB2INSTANCE 
          value: db2inst1 
        - name: DB2INST1_PASSWORD 
          value: db2inst1        
        ports:
        - containerPort: 50000
          name: db2
        imagePullPolicy: IfNotPresent
        volumeMounts:
        - mountPath: /database
          name: sterling-b2bi-db2-storage
  volumeClaimTemplates:
  - metadata:
      name: sterling-b2bi-db2-storage
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 20Gi
      storageClassName: ibmc-block-gold

3) Realize o deploy

oc create -f db2-deploy.yaml

Verifique até ficar no status Running.

oc get pods

  NAME    READY   STATUS    RESTARTS   AGE
  db2-0   1/1     Running   0          31m

Espere até ver esta linha como a última entrada no log. Ctrl+C para interromper os logs.

oc logs -f db2-0
  
  ...
  /database/config/db2inst1/sqllib/ctrl/db2strst.lck

Criando a database para o SB2BI

From inside the Db2 container, create B2BIDB database for B2Bi.

1) Conectar ao pod de banco de dados.

oc rsh pod/db2-0

2) Criando a database

su - db2inst1


cat <<EOF >> create_b2bi_db.sql
CREATE DATABASE B2BIDB AUTOMATIC STORAGE YES USING CODESET UTF-8 TERRITORY DEFAULT COLLATE USING SYSTEM PAGESIZE 32768;
CONNECT TO B2BIDB;
UPDATE DATABASE CONFIG FOR B2BIDB USING LOGFILSIZ 65536;
UPDATE DATABASE CONFIG FOR B2BIDB USING LOGPRIMARY 40;
UPDATE DATABASE CONFIG FOR B2BIDB USING NUM_LOG_SPAN 32;
UPDATE DATABASE CONFIG FOR B2BIDB USING AUTO_MAINT ON;
UPDATE DATABASE CONFIG FOR B2BIDB USING AUTO_TBL_MAINT ON;
UPDATE DATABASE CONFIG FOR B2BIDB USING AUTO_RUNSTATS ON;
UPDATE DATABASE CONFIG FOR B2BIDB USING AUTO_REORG ON;
UPDATE DATABASE CONFIG FOR B2BIDB USING AUTO_DB_BACKUP ON;
CREATE USER TEMPORARY TABLESPACE B2BUSERTEMP PAGESIZE 32K BUFFERPOOL IBMDEFAULTBP;
CREATE BUFFERPOOL B2BIDB_04KBP IMMEDIATE SIZE 1000 PAGESIZE 4K;
CREATE REGULAR TABLESPACE TS_REG04_B2BIDB PAGESIZE 4K BUFFERPOOL B2BIDB_04KBP;
CREATE BUFFERPOOL B2BIDB_08KBP IMMEDIATE SIZE 1000 PAGESIZE 8K;
CREATE REGULAR TABLESPACE TS_REG08_B2BIDB PAGESIZE 8K BUFFERPOOL B2BIDB_08KBP;
CREATE BUFFERPOOL B2BIDB_16KBP IMMEDIATE SIZE 1000 PAGESIZE 16K;
CREATE REGULAR TABLESPACE TS_REG16_B2BIDB PAGESIZE 16K BUFFERPOOL B2BIDB_16KBP;
CONNECT RESET;
EOF
[db2inst1@db2-0 ~]$ db2 -stvf create_b2bi_db.sql
[db2inst1@db2-0 ~]$ db2 list database directory

  ...
    Database alias                       = B2BIDB
    Database name                        = B2BIDB
    Local database directory             = /database/data 


[db2inst1@db2-0 ~]$ exit

sh-4.2# exit

3) Teste a conectividade db2 de fora. Use DbVisualizer para testar a conectividade de fora. Identifique o endereço IP do LoadBalancer (porta 50000). Parâmetro EXTERNAL-IP

oc get svc

  NAME                  TYPE           CLUSTER-IP      EXTERNAL-IP        PORT(S)           AGE
  sterling-b2bi-db2-lb  LoadBalancer   172.xx.xx.250   169.xx.xx.83   50000:30707/TCP   43m

Informações de Referência 3

informações do banco de dados (para serem usadas posteriormente).

Ref 3
  • dbVendor: db2
  • dbHost: <EXTERNAL-IP>
  • dbPort: 50000
  • dbUser: db2inst1
  • dbData: B2BIDB


Extraindo o db2jcc4.jar e db2jcc_license_cu.jar do Pod

1) Verifique se o pode está em execução

oc project sterling-b2bi-db

oc get pods

NAME    READY   STATUS    RESTARTS   AGE
db2-0   1/1     Running   0          4h45m

2) Copiando os arquivos de dentro do pod para o filesystem local

oc cp db2-0:/opt/ibm/db2/V11.5/java/db2jcc4.jar db2jcc4.jar
oc cp db2-0:/opt/ibm/db2/V11.5/java/db2jcc_license_cu.jar db2jcc_license_cu.jar

CUIDADO!!! Deletando o Projeto

Em caso de erro ou se quiser refazer o projeto, execute o comando para deletar o projeto

oc delete project sterling-b2bi-db2

See Also