kubernetes集群部署oracle 11g数据库服务

背景:

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

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

1、拉取oracle 11g的镜像:

cs 复制代码
[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、上传postgre 12.6镜像到私库:

先tag处理一下

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

再上传到私有harbor库

cs 复制代码
[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配置:

cs 复制代码
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存储里

cs 复制代码
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配置:

cs 复制代码
# kubectl apply -f oracle-11g.yml

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

cs 复制代码
kubectl cp oracle-db-zmbuy-7f59695454-fwcnp:/opt/oracle/app/oradata/orcl ./orcl

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

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

cs 复制代码
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控制器

cs 复制代码
# kubectl apply -f oracle-11g.yml

4、替换control02.ctl文件:

进入到oracle到pod容器中

cs 复制代码
# kubectl exec -it oracle-db-zmbuy-75f497f78d-gdjr5 bash

删除oracle的机制文件

cs 复制代码
# rm -rf /opt/oracle/app/flash_recovery_area/helowin/control02.ctl 

复制新的oracle的机制文件

cs 复制代码
# cp /opt/oracle/app/oradata/orcl/control01.ctl /home/oracle/app/flash_recovery_area/orcl/control02.ctl 

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

cs 复制代码
# chown oracle:oinstall /opt/oracle/app/flash_recovery_area/control02.ctl

5、重启oracle数据库:

cs 复制代码
# su - oracle

$ source ~/.bash_profile

$ sqlplus / as sysdba

SQL> shutdown immediate;

SQL> startup;

5、设置oracle登入配置:

cs 复制代码
#登录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的值,等我研究好了,再分析給大家。

相关推荐
pk_xz12345631 分钟前
Shell 脚本中变量和字符串的入门介绍
linux·运维·服务器
小珑也要变强34 分钟前
Linux之sed命令详解
linux·运维·服务器
瓜牛_gn35 分钟前
mysql特性
数据库·mysql
奶糖趣多多2 小时前
Redis知识点
数据库·redis·缓存
Lary_Rock3 小时前
RK3576 LINUX RKNN SDK 测试
linux·运维·服务器
CoderIsArt3 小时前
Redis的三种模式:主从模式,哨兵与集群模式
数据库·redis·缓存
云飞云共享云桌面5 小时前
8位机械工程师如何共享一台图形工作站算力?
linux·服务器·网络
师太,答应老衲吧5 小时前
SQL实战训练之,力扣:2020. 无流量的帐户数(递归)
数据库·sql·leetcode
昌sit!5 小时前
K8S node节点没有相应的pod镜像运行故障处理办法
云原生·容器·kubernetes
Peter_chq5 小时前
【操作系统】基于环形队列的生产消费模型
linux·c语言·开发语言·c++·后端