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 db2
oc adm policy add-scc-to-user privileged -n sterling-b2bi-db2 -z db2

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

apiVersion: v1
kind: Service
metadata:
  name: 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: "db2"
  replicas: 1
  template:
    metadata:
      labels:
        app: db2
    spec:
      serviceAccount: db2
      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: db2vol
  volumeClaimTemplates:
  - metadata:
      name: db2vol
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 20Gi
      storageClassName: ibmc-block-gold

3) Realize o deploy

oc create -f db2deploy.yaml

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

oc get pods
oc logs -f db2-0

/database/config/db2inst1/sqllib/ctrl/db2strst.lck

Verifique se você consegue se conectar ao pod de banco de dados.

oc rsh pod/db2-0

Verifique se a instalação do DB2

su - db2inst1
db2 list database directory
exit
exit

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_scc_db_b2bidb.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
db2 -stvf create_scc_db_b2bidb.sql
db2 list database directory
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)

oc get svc

EXTERNAL-IP

Nota: Alguns comandos úteis do DB2 (apenas se necessário)=

db2 connect reset force applications all deactivate db <dbname> db2stop db2start db2_kill


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


See Also