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

相关推荐
watermelonoops1 小时前
Deepin和Windows传文件(Xftp,WinSCP)
linux·ssh·deepin·winscp·xftp
云和数据.ChenGuang1 小时前
Django 应用安装脚本 – 如何将应用添加到 INSTALLED_APPS 设置中 原创
数据库·django·sqlite
woshilys1 小时前
sql server 查询对象的修改时间
运维·数据库·sqlserver
Hacker_LaoYi1 小时前
SQL注入的那些面试题总结
数据库·sql
疯狂飙车的蜗牛2 小时前
从零玩转CanMV-K230(4)-小核Linux驱动开发参考
linux·运维·驱动开发
建投数据2 小时前
建投数据与腾讯云数据库TDSQL完成产品兼容性互认证
数据库·腾讯云
Hacker_LaoYi3 小时前
【渗透技术总结】SQL手工注入总结
数据库·sql
岁月变迁呀3 小时前
Redis梳理
数据库·redis·缓存
独行soc3 小时前
#渗透测试#漏洞挖掘#红蓝攻防#护网#sql注入介绍06-基于子查询的SQL注入(Subquery-Based SQL Injection)
数据库·sql·安全·web安全·漏洞挖掘·hw
你的微笑,乱了夏天4 小时前
linux centos 7 安装 mongodb7
数据库·mongodb