背景:

因业务上线需要,研发中心要求在kubernetes测试集群部署一个oracle 11g的数据库,用于业务功能调试。

一、实施部署oracle 11g数据库: 

1、拉取oracle 11g的镜像:

[root@harbor-02 ~]# docker pull registry.cn-hangzhou.aliyuncs.com/images-speed-up/oracle_11g
2017-latest: Pulling from images-speed-up/oracle_11g
699451820735: Pull complete 
861e6e6e8e5e: Pull complete 
4403d783b046: Pull complete 
Digest: sha256:3b913841850a4d57fcfcb798be86acc88ea0f2acc5478bc0c140a43e91c4a545
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/images-speed-up/oracle_11g:latest

2、上传oracle 11g镜像到私库:

先tag处理一下

[root@harbor-02 ~]# docker tag registry.cn-hangzhou.aliyuncs.com/images-speed-up/oracle_11g dockerhub.jiang.com/jiang-public/oracle:iatebes-11g

再上传到私有harbor库

[root@harbor-02 ~]# docker push dockerhub.jiang.com/jiang-public/oracle:iatebes-11g
The push refers to repository [dockerhub.jiang.com/jiang-public/oracle]
fdfec26b634f: Pushed 
ef3ecb9d5e46: Pushed 
548a79621a42: Pushed 
2017-latest: digest: sha256:ff8a63a2c900cf3201b9485267ff804db58fbeaed83287c94edd3b3359708854 size: 954

3、创建PersistentVolume、PersistentVolumeClaim存储:

因kubernetes集群环境是对接了hpe(华三)的iscsi存储,所以直接通过stoageclass创建pvc存储即可。不过这里会展示pvc存储的yml配置内容。

pvc存储yml配置:

apiVersion: storage.k8s.io/v1
kind: PersistentVolumeClaim
metadata:
  name: oracle-11g-pvc
  namespace: main-data-test
  annotations:
    boundinfo: >-
      [{"podName":"oracle-db-zmbuy-75f497f78d-gdjr5","containerName":"oracle","volumeMount":{"name":"oracle-11g-pvc","mountPath":"/opt/oracle/app/oradata/"}}]
    pv.kubernetes.io/bind-completed: 'yes'
    pv.kubernetes.io/bound-by-controller: 'yes'
    system/support-expansion: 'true'
    volume.beta.kubernetes.io/storage-provisioner: csi.hpe.com
  finalizers:
    - kubernetes.io/pvc-protection
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  volumeName: pvc-284a18aa-e560-44fb-8fa2-a19854b657bf
  storageClassName: hpe-san
  volumeMode: Filesystem

4、创建无状态的postgre数据库:

这里的无状态就是deployment控制器的配置。

1、先不要挂载存储,因为需要复制orcl数据库的内容到pvc存储里 

kind: Deployment
metadata:
  name: oracle-db-zmbuy
  namespace: main-data-test
  labels:
    app: oracle-db-zmbuy
    name: oracle-db
    version: 11.2.0
  annotations:
    deployment.kubernetes.io/revision: '3'
    sidecar.istio.io/inject: 'false'
spec:
  replicas: 1
  selector:
    matchLabels:
      app: oracle-db-zmbuy
      name: oracle-db
  template:
    metadata:
      labels:
        app: oracle-db-zmbuy
        name: oracle-db
        version: 11.2.0
      annotations:
        cni.projectcalico.org/ipv4pools: '["172.25.0.0/16"]'
        sidecar.istio.io/inject: 'false'
        system/container-registry-map: '{"oracle":"default"}'
        system/registry: default
        v1.multus-cni.io/default-network: kube-system/calico@eth0
    spec:
      containers:
        - name: oracle
          image: 'dockerhub.jxstjh.com/jxstjh-public/oracle:iatebes-11g'
          ports:
            - containerPort: 1521
              protocol: TCP
          resources:
            limits:
              cpu: '2'
              memory: 4Gi
            requests:
              cpu: '1'
              memory: 1Gi
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: IfNotPresent
          securityContext:
            privileged: false
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
      dnsPolicy: ClusterFirst
      serviceAccountName: default
      serviceAccount: default
      securityContext: {}
  strategy:
    type: Recreate
  minReadySeconds: 10
  revisionHistoryLimit: 10
  progressDeadlineSeconds: 600

生效oracle到deployment配置:

# kubectl apply -f oracle-11g.yml

2、将没有挂载存储里的orcl数据库的内容复制文件到本地

kubectl cp oracle-db-zmbuy-7f59695454-fwcnp:/opt/oracle/app/oradata/orcl ./orcl

注:这时候在本地有一个orcl的文件夹

3、修改oracle到deployment配置内容,挂载pvc存储:

kind: Deployment
metadata:
  name: oracle-db-zmbuy
  namespace: main-data-test
  labels:
    app: oracle-db-zmbuy
    name: oracle-db
    version: 11.2.0
  annotations:
    deployment.kubernetes.io/revision: '3'
    sidecar.istio.io/inject: 'false'
spec:
  replicas: 1
  selector:
    matchLabels:
      app: oracle-db-zmbuy
      name: oracle-db
  template:
    metadata:
      labels:
        app: oracle-db-zmbuy
        name: oracle-db
        version: 11.2.0
      annotations:
        cni.projectcalico.org/ipv4pools: '["172.25.0.0/16"]'
        sidecar.istio.io/inject: 'false'
        system/container-registry-map: '{"oracle":"default"}'
        system/registry: default
        v1.multus-cni.io/default-network: kube-system/calico@eth0
    spec:
      volumes:
        - name: oracle-11g-pvc
          persistentVolumeClaim:
            claimName: oracle-11g-pvc
      containers:
        - name: oracle
          image: 'dockerhub.jxstjh.com/jxstjh-public/oracle:iatebes-11g'
          ports:
            - containerPort: 1521
              protocol: TCP
          resources:
            limits:
              cpu: '2'
              memory: 4Gi
            requests:
              cpu: '1'
              memory: 1Gi
          volumeMounts:
            - name: oracle-11g-pvc
              mountPath: /opt/oracle/app/oradata/
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: IfNotPresent
          securityContext:
            privileged: false
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
      dnsPolicy: ClusterFirst
      serviceAccountName: default
      serviceAccount: default
      securityContext: {}
  strategy:
    type: Recreate
  minReadySeconds: 10
  revisionHistoryLimit: 10
  progressDeadlineSeconds: 600

生效deplyment控制器

# kubectl apply -f oracle-11g.yml

4、替换control02.ctl文件:

进入到oracle到pod容器中

# kubectl exec -it oracle-db-zmbuy-75f497f78d-gdjr5 bash

删除oracle的机制文件
 

# rm -rf /opt/oracle/app/flash_recovery_area/helowin/control02.ctl 

复制新的oracle的机制文件

# cp /opt/oracle/app/oradata/orcl/control01.ctl /home/oracle/app/flash_recovery_area/orcl/control02.ctl 

修改属性 control02.ctl文件的属性

# chown oracle:oinstall /opt/oracle/app/flash_recovery_area/control02.ctl

5、重启oracle数据库:

# su - oracle

$ source ~/.bash_profile

$ sqlplus / as sysdba

SQL> shutdown immediate;

SQL> startup;

5、设置oracle登入配置:

#登录sqlplus
SQL> sqlplus / as sysdba   

#修改system用户账号密码
SQL> alter user system identified by system; 

#修改sys用户账号密码 
SQL> alter user sys identified by system;  

#创建内部管理员账号密码都是test  
SQL> create user test identified by test;  

#将dba权限授权给内部管理员账号和密码
SQL> grant connect,resource,dba to test;  

#修改密码规则策略为密码永不过期 
SQL> ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED; 

#修改数据库最大连接数据
SQL> alter system set processes=1000 scope=spfile;  #修改数据库最大连接数据

6、使用连接工具进行验证:

注:到此就完成了oracle 11g的部署,但是这里目前无法自定义sid的值,等我研究好了,再分析給大家。 

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐