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的值,等我研究好了,再分析給大家。

相关推荐
ac.char4 分钟前
在 Ubuntu 上安装 Yarn 环境
linux·运维·服务器·ubuntu
敲上瘾4 分钟前
操作系统的理解
linux·运维·服务器·c++·大模型·操作系统·aigc
tatasix21 分钟前
MySQL UPDATE语句执行链路解析
数据库·mysql
长弓聊编程22 分钟前
Linux系统使用valgrind分析C++程序内存资源使用情况
linux·c++
cherub.30 分钟前
深入解析信号量:定义与环形队列生产消费模型剖析
linux·c++
南城花随雪。34 分钟前
硬盘(HDD)与固态硬盘(SSD)详细解读
数据库
儿时可乖了35 分钟前
使用 Java 操作 SQLite 数据库
java·数据库·sqlite
懒是一种态度37 分钟前
Golang 调用 mongodb 的函数
数据库·mongodb·golang
天海华兮39 分钟前
mysql 去重 补全 取出重复 变量 函数 和存储过程
数据库·mysql
梅见十柒1 小时前
wsl2中kali linux下的docker使用教程(教程总结)
linux·经验分享·docker·云原生