Docker部署oracle-xe-11g数据持久化的问题解决

Docker部署Oracle数据持久化问题

环境说明


kubernets集群部署 oracle
镜像所采用的是:wnameless/oracle-xe-11g
镜像地址是:https://hub.docker.com/r/oracleinanutshell/oracle-xe-11g
我是先下载到本地了

# 查看本地镜像
[root@k8s-master01 oracle11g]# docker images|grep oracleinanutshell
oracleinanutshell/oracle-xe-11g                                               latest        ad13c30ec346   2 years ago     2.13GB
[root@k8s-master01 oracle11g]# 

数据持久化

现在想要实现数据持久化
这个镜像的oradata目录在这里/u01/app/oracle/oradata/XE
我是这样操作的:
先把容器中的这个路径下的所有文件都拷贝到宿主机
然后再把拷贝出的文件挂载到原先的目录下
操作如下:

先启动服务,生成数据文件

[root@k8s-master01 oracle11g]# docker run -d --name oracle11g -p 1521:1521 -e ORACLE_ALLOW_REMOTE=true oracleinanutshell/oracle-xe-11g
bb62b7f9eb09b976557afed98c7915b53f09d0161d4a9b38337262d9fb036767
[root@k8s-master01 oracle11g]# docker logs -f oracle11g
Starting Oracle Net Listener.
Starting Oracle Database 11g Express Edition instance.


System altered.

^C
[root@k8s-master01 oracle11g]# 

看到 System altered 代表服务启动成功

把数据文件copy到宿主机

[root@k8s-master01 oracle11g]# docker cp oracle11g:/u01/app/oracle/ /data/oracle11g-data/
[root@k8s-master01 oracle11g]# 
[root@k8s-master01 oracle11g]# ls /data/oracle11g-data/oracle/
admin  diag  fast_recovery_area  oradata  oradiag_oracle  product
[root@k8s-master01 oracle11g]# 

那么,oracle的数据文件已经copy到宿主机

清除刚启动的容器 oracle11g

[root@k8s-master01 oracle11g]# docker stop oracle11g
oracle11g
[root@k8s-master01 oracle11g]# docker rm oracle11g
oracle11g
[root@k8s-master01 oracle11g]# 

k8s集群下部署oracle-xe-11g

我的deployment配置

apiVersion: apps/v1
kind: Deployment
metadata:
  name: oracle11g
  namespace: database
spec:
  selector:
    matchLabels:
      app: oracle11g
  replicas: 1 # tells deployment to run 2 pods matching the template
  template:
    metadata:
      labels:
        app: oracle11g
    spec:
      containers:
      - name: oracle11g
        image: oracleinanutshell/oracle-xe-11g:1.0.0
        imagePullPolicy: IfNotPresent
        volumeMounts:
        - mountPath: /u01/app/oracle
          name: data-app-11g
        ports:
        - containerPort: 8080
        - containerPort: 1521
        env:
        - name: ORACLE_ALLOW_REMOTE
          value: "true"
        - name: ORACLE_DISABLE_ASYNCH_IO
          value: "true"
        - name: ORACLE_ENABLE_XDB
          value: "true"
      volumes:
      - name: data-app-11g
        hostPath:
          path: /data/oracle11g-data/oracle  #指定本地存储目录
          type: Directory

配置文件中指定了本地存储路径

启动oracle-xe-11g加载本地数据

[root@k8s-master01 oracle11g]# kubectl apply -f deployment.yaml
deployment.apps/oracle11g created
[root@k8s-master01 oracle11g]# kubectl get pod -n database
NAME                         READY   STATUS    RESTARTS   AGE
oracle11g-6fb478dbc7-n6874   1/1     Running   0          21s
oracle12c-ddd5f54b6-852tb    1/1     Running   1          6d2h
[root@k8s-master01 oracle11g]# 

Oracle11g启动成功

查看日志

[root@k8s-master01 oracle11g]# kubectl logs -f oracle11g-6fb478dbc7-n6874 -n database
Starting Oracle Net Listener.
Starting Oracle Database 11g Express Edition instance.


User altered.


User altered.


System altered.


System altered.

Shutting down Oracle Database 11g Express Edition instance.
Stopping Oracle Net Listener.

Starting Oracle Net Listener.
Starting Oracle Database 11g Express Edition instance.

oracle11g 启动成功

k8s开放nodeport端口 访问oracal数据库

我的service配置如下

apiVersion: v1
kind: Service
metadata:
  namespace: database
  labels:
    app: oracle11g
  name: oracle11g-nodeport
spec:
        #clusterIP: "172.25.42.235"
  externalTrafficPolicy: Cluster
  type: NodePort
  ports:
    - name: manager
      protocol: TCP
      port: 8080
      targetPort: 8080
      nodePort: 28080
    - name: connect
      protocol: TCP
      port: 1521
      targetPort: 1521
      nodePort: 21521
  selector:
    app: oracle11g

应用service配置

[root@k8s-master01 oracle11g]# kubectl get service -n database
NAME                 TYPE       CLUSTER-IP       EXTERNAL-IP   PORT(S)                         AGE
oracle11g-nodeport   NodePort   10.105.188.84    <none>        8080:28080/TCP,1521:21521/TCP   7s
oracle12c-nodeport   NodePort   10.109.195.127   <none>        8080:38080/TCP,1521:31521/TCP   11d
[root@k8s-master01 oracle11g]# 

在宿主机开放端口28080 21521

使用说明

管理数据库连接
Login http://ip:28080/apex/apex_admin
username: ADMIN
password: admin

使用以下设置连接数据库:
hostname: 宿主机ip地址
port: 21521
sid: xe
username: system
password: oracle


已上就是Docker部署oracle-xe-11g数据持久化的问题解决过程,觉得有用就给个赞吧

版权声明:本文为作者原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

原创文章,作者:老C,如若转载,请注明出处:https://www.code404.icu/439.html

发表评论

登录后才能评论