openSUSE 使用docker安装 Oracle 19c 数据库

 

一、需求

因工作需要搭建一套Oracle环境用于远程开发使用,主要是写一些存储过程SQL,存有少量数据用于验证程序是否可以正确运行。为什么选用docker,因为在宿主机(物理机)上安装需要配置的东西实在是太多了,找捷径使用别人做好的镜像少量更改即可使用,这也是本次部署的主要出发点。

CentOS社区关闭后,我就考虑使用openSUSE做代替品了,选用这个操作系统是多年前工作时接触过,感觉还不错。

本文都将以openSUSE15为例,其他操作系统请自行调整代码。

image

二、环境信息

ESXi平台部署的openSUSE 15

内存4GB

磁盘400GB

image

三、安装步骤

3.1.安装docker

操作系统安装略,使用哪家都可以,需要先安装docker。

3.1.1搜索docker包

localhost:~ # zypper search  docker
Loading repository data...
Reading installed packages...

S | Name                                  | Summary                                                   | Type
--+---------------------------------------+-----------------------------------------------------------+-----------
  | containment-rpm-docker                | Wraps OBS/kiwi-built images in rpms                       | package
  | docker                                | The Moby-project Linux container runtime                  | package
  | docker                                | The Moby-project Linux container runtime                  | srcpackage
  | docker-bash-completion                | Bash Completion for docker                                | package
  | docker-bench-security                 | Docker Bench for Security                                 | package
  | docker-distribution-registry          | Registry server for Docker                                | package
  | docker-fish-completion                | Fish completion for docker                                | package
  | docker-img-store-setup                | Setup btrfs or xfs image store for docker                 | package
  | docker-kubic                          | The Moby-project Linux container runtime                  | package
  | docker-kubic                          | The Moby-project Linux container runtime                  | srcpackage
  | docker-kubic-bash-completion          | Bash Completion for docker-kubic                          | package
  | docker-kubic-fish-completion          | Fish completion for docker-kubic                          | package
  | docker-kubic-kubeadm-criconfig        | docker container runtime configuration for kubeadm        | package
  | docker-kubic-zsh-completion           | Zsh Completion for docker-kubic                           | package
  | docker-libnetwork                     | Docker Networking                                         | package
  | docker-libnetwork-kubic               | Docker Networking                                         | package
  | docker-runc                           | Tool for spawning and running OCI containers              | package
  | docker-runc-kubic                     | Tool for spawning and running OCI containers              | package
  | docker-zsh-completion                 | Zsh Completion for docker                                 | package
  | golang-github-docker-libnetwork       | Docker Networking                                         | package
  | golang-github-docker-libnetwork-kubic | Docker Networking                                         | package
  | kiwi-image-docker-requires            | KIWI - buildservice host requirements for docker images   | package
  | obs-service-docker_label_helper       | OBS Service to add prefixed labels in Dockerfile builds   | package
  | openSUSE-release-appliance-docker     | openSUSE Leap 15.4                                        | package
  | ovn-docker                            | Docker network plugins for OVN                            | package
  | pcp-pmda-docker                       | Performance Co-Pilot (PCP) metrics from the Docker daemon | package
  | podman-docker                         | Emulate Docker CLI using podman                           | package
  | python3-avocado-plugins-runner-docker | Avocado Runner for Execution on Docker Containers         | package
  | python3-docker                        | Docker API Client                                         | package
  | python3-docker-compose                | Tool to define and run complex applications using Docker  | package
  | python3-docker-pycreds                | Python bindings for the Docker credentials store API      | package
  | python3-dockerpty                     | Docker API Client                                         | package
  | rubygem-docker-api                    | A simple REST client for the Docker Remote API            | package
  | rubygem-docker-api-doc                | RDoc documentation for docker-api                         | package
  | rubygem-docker-api-testsuite          | Test suite for docker-api                                 | package
  | yast2-docker                          | YaST2 - GUI for docker management                         | package
  | zypper-docker                         | Easy patch and update solution for Docker images          | package

3.1.2安装docker

 

localhost:~ # zypper install docker
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following recommended package was automatically selected:
  criu

The following 9 NEW packages are going to be installed:
  catatonit containerd criu docker docker-bash-completion libnet9 python3-ipaddr python3-protobuf runc

9 new packages to install.
Overall download size: 48.7 MiB. Already cached: 0 B. After the operation, additional 223.6 MiB will be used.
Continue? [y/n/v/...? shows all options] (y): y
Retrieving package catatonit-0.1.5-3.3.2.x86_64                                                                                                    (1/9), 257.2 KiB (696.5 KiB unpacked)
Retrieving: catatonit-0.1.5-3.3.2.x86_64.rpm .....................................................................................................................................[done]
Retrieving package libnet9-1.2~rc3-1.29.x86_64                                                                                                     (2/9),  44.6 KiB (100.2 KiB unpacked)
Retrieving: libnet9-1.2~rc3-1.29.x86_64.rpm ......................................................................................................................................[done]
Retrieving package python3-ipaddr-2.1.11-2.24.noarch                                                                                               (3/9),  38.7 KiB (179.7 KiB unpacked)
Retrieving: python3-ipaddr-2.1.11-2.24.noarch.rpm ....................................................................................................................[done (1.8 KiB/s)]
Retrieving package python3-protobuf-3.9.2-4.12.1.x86_64                                                                                            (4/9), 585.7 KiB (  5.4 MiB unpacked)
Retrieving: python3-protobuf-3.9.2-4.12.1.x86_64.rpm .............................................................................................................................[done]
Retrieving package criu-3.16.1-bp154.1.33.x86_64                                                                                                   (5/9), 681.9 KiB (  2.6 MiB unpacked)
Retrieving: criu-3.16.1-bp154.1.33.x86_64.rpm ........................................................................................................................[done (1.8 KiB/s)]
Retrieving package runc-1.1.3-150000.30.1.x86_64                                                                                                   (6/9),   2.6 MiB (  9.1 MiB unpacked)
Retrieving: runc-1.1.3-150000.30.1.x86_64.rpm ........................................................................................................................[done (1.6 KiB/s)]
Retrieving package containerd-1.6.6-150000.73.2.x86_64                                                                                             (7/9),  17.7 MiB ( 74.2 MiB unpacked)
Retrieving: containerd-1.6.6-150000.73.2.x86_64.rpm .................................................................................................................[done (19.4 MiB/s)]
Retrieving package docker-20.10.17_ce-150000.166.1.x86_64                                                                                          (8/9),  26.6 MiB (131.4 MiB unpacked)
Retrieving: docker-20.10.17_ce-150000.166.1.x86_64.rpm ..............................................................................................................[done (13.5 MiB/s)]
Retrieving package docker-bash-completion-20.10.17_ce-150000.166.1.noarch                                                                          (9/9), 121.3 KiB (113.6 KiB unpacked)
Retrieving: docker-bash-completion-20.10.17_ce-150000.166.1.noarch.rpm ...............................................................................................[done (1.7 KiB/s)]

Checking for file conflicts: .....................................................................................................................................................[done]
(1/9) Installing: catatonit-0.1.5-3.3.2.x86_64 ...................................................................................................................................[done]
(2/9) Installing: libnet9-1.2~rc3-1.29.x86_64 ....................................................................................................................................[done]
(3/9) Installing: python3-ipaddr-2.1.11-2.24.noarch ..............................................................................................................................[done]
(4/9) Installing: python3-protobuf-3.9.2-4.12.1.x86_64 ...........................................................................................................................[done]
(5/9) Installing: criu-3.16.1-bp154.1.33.x86_64 ..................................................................................................................................[done]
(6/9) Installing: runc-1.1.3-150000.30.1.x86_64 ..................................................................................................................................[done]
(7/9) Installing: containerd-1.6.6-150000.73.2.x86_64 ............................................................................................................................[done]
Updating /etc/sysconfig/docker ...
(8/9) Installing: docker-20.10.17_ce-150000.166.1.x86_64 .........................................................................................................................[done]
(9/9) Installing: docker-bash-completion-20.10.17_ce-150000.166.1.noarch .........................................................................................................[done]

3.1.3安装完成后验证

localhost:~ # docker info
Client:
 Context:    default
 Debug Mode: false

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 20.10.17-ce
 Storage Driver: btrfs
  Build Version: Btrfs v4.15
  Library Version: 102
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux oci runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
 runc version: v1.1.3-0-ga916309fff0f
 init version: 
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 5.14.21-150400.24.21-default
 Operating System: openSUSE Leap 15.4
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 3.825GiB
 Name: localhost.localdomain
 ID: MBGH:Z3RA:IAEX:QTNN:VKFO:CQPL:PABA:U4T3:X455:NCQQ:YBGJ:AUK6
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

3.1.4设置docker开机自己启动,并验证

localhost:~ # systemctl enable docker
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.
localhost:~ # systemctl restart docker
localhost:~ # docker info
Client:
 Context:    default
 Debug Mode: false

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 20.10.17-ce
 Storage Driver: btrfs
  Build Version: Btrfs v4.15
  Library Version: 102
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc io.containerd.runc.v2 io.containerd.runtime.v1.linux oci
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
 runc version: v1.1.3-0-ga916309fff0f
 init version: 
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 5.14.21-150400.24.21-default
 Operating System: openSUSE Leap 15.4
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 3.825GiB
 Name: localhost.localdomain
 ID: MBGH:Z3RA:IAEX:QTNN:VKFO:CQPL:PABA:U4T3:X455:NCQQ:YBGJ:AUK6
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

3.1.5拉取Oracle19C的镜像

localhost:~ # docker pull registry.cn-hangzhou.aliyuncs.com/zhuyijun/oracle:19c
19c: Pulling from zhuyijun/oracle
bce8f778fef0: Pull complete 
3fc3fd32c0bc: Pull complete 
02948dd6d654: Pull complete 
67f2dfeb2f1b: Pull complete 
2e42d8039fd9: Pull complete 
b94f01bb60c6: Pull complete 
Digest: sha256:3898a9394720f30ce7f0b83ef2d172f4cd11b958282e0505f83cf2b0e5eaf7d4
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/zhuyijun/oracle:19c
registry.cn-hangzhou.aliyuncs.com/zhuyijun/oracle:19c

并作验证

localhost:~ # docker images
REPOSITORY                                          TAG       IMAGE ID       CREATED       SIZE
registry.cn-hangzhou.aliyuncs.com/zhuyijun/oracle   19c       7b5eb4597688   2 years ago   6.61GB

3.1.6创建Oracle数据文件存放路径,在宿主机创建(物理机),需要授权777,为了省事我是这么写的,如果你对权限较为敏感需要自行研究下权限配置。关于文件路径,例如存在/u01目录下,可以根据自己需求来决定,后面配置时改成对应的路径即可,这个不是强制要求这样写

localhost:~ # mkdir /u01/oracle/oradata -p
localhost:~ # chmod 777 /u01/oracle/oradata/

3.1.7配置Oracle初始化安装脚本,准备进入安装

localhost:~ # docker run -d \
> -p 1521:1521 -p 5500:5500 \
> -e ORACLE_SID:ORCLPDB \
> -e ORACLE_PDB:ORCLPDB1 \
> -e ORACLE_PWD=oracle \
> -e ORACLE_EDITION=standard \
> -e ORACLE_CHARACTERSET=AL32UTF8 \
> -v /u01/oracle/oradata:/opt/oracle/oradata \
> --name oracle19c \
> registry.cn-hangzhou.aliyuncs.com/zhuyijun/oracle:19c
b5afbb001c0b8fee8505efd1ae505129f0d8bac8ceebe39736d29f81c00ab644

最后一行代码即是docker运行的进程

 -p 1521:1521 -p 5500:5500 \  //配置Oracle服务端口
 -e ORACLE_SID:ORCLPDB \  //配置ORACLEPDB,似乎是12C的新特性有别于11g
 -e ORACLE_PDB:ORCLPDB1 \
 -e ORACLE_PWD=oracle \  //配置Oracle的管理用户密码,可自行调整设置
 -e ORACLE_EDITION=standard \  //配置Oracle的版本,standard即为标准版,可满足大多数需求
 -e ORACLE_CHARACTERSET=AL32UTF8 \  //配置Oracle实例的字符集,这里设置的是UTF8,如果需要gbk则配置为zhs16gbk
 -v /u01/oracle/oradata:/opt/oracle/oradata \  //配置Oracle数据文件的存储路径,上述命令mkdir那一段你配置的什么这里就写什么
 --name oracle19c \  //给容器起了个名字,你想叫什么都可以

上述代码配置好以后,回车即可进入安装,安装的过程可以使用下述命令来观察,直到出现“DATABASE IS READY TO USE!”则安装结束

localhost:~ # docker logs -ft oracle19c 2022-09-27T17:04:43.575564431Z Relinking oracle binary for edition: standard 2022-09-27T17:04:43.575594872Z make -f /opt/oracle/product/19c/dbhome_1/rdbms/lib/ins_rdbms.mk edition_standard ioracle 2022-09-27T17:04:43.605310381Z Deploying Oracle Database Standard Edition 2022-09-27T17:04:43.606338466Z mv -f /opt/oracle/product/19c/dbhome_1/lib/libedtn19.a /opt/oracle/product/19c/dbhome_1/lib/libedtn19_backup.a 2022-09-27T17:04:43.639200887Z cp /opt/oracle/product/19c/dbhome_1/lib/libedtn19_std.a /opt/oracle/product/19c/dbhome_1/lib/libedtn19.a 2022-09-27T17:04:43.653293476Z chmod 755 /opt/oracle/product/19c/dbhome_1/bin 2022-09-27T17:04:43.671867296Z 2022-09-27T17:04:43.673400646Z - Linking Oracle

内容较多,此处省略

2022-09-27T17:30:16.342415712Z Pluggable database altered.
2022-09-27T17:30:16.342450623Z
2022-09-27T17:30:19.489645247Z SQL>
2022-09-27T17:30:19.489934088Z PL/SQL procedure successfully completed.
2022-09-27T17:30:19.489947739Z
2022-09-27T17:30:19.491761146Z SQL> Disconnected from Oracle Database 19c Standard Edition 2 Release 19.0.0.0.0 - Production
2022-09-27T17:30:19.491780679Z Version 19.3.0.0.0
2022-09-27T17:30:21.684442655Z The Oracle base remains unchanged with value /opt/oracle
2022-09-27T17:30:22.811238083Z #########################
2022-09-27T17:30:22.811280997Z DATABASE IS READY TO USE!
2022-09-27T17:30:22.811293213Z #########################
2022-09-27T17:30:22.816476715Z The following output is now a tail of the alert.log:
2022-09-27T17:30:22.825296778Z 2022-09-27T17:30:15.157556+00:00
2022-09-27T17:30:22.825329071Z ALTER SYSTEM SET control_files='/opt/oracle/oradata/ORCLCDB/control01.ctl' SCOPE=SPFILE;
2022-09-27T17:30:22.825347962Z 2022-09-27T17:30:15.198890+00:00
2022-09-27T17:30:22.825355700Z ALTER SYSTEM SET local_listener='' SCOPE=BOTH;
2022-09-27T17:30:22.825361934Z    ALTER PLUGGABLE DATABASE ORCLPDB1 SAVE STATE
2022-09-27T17:30:22.825368031Z 2022-09-27T17:30:16.329977+00:00
2022-09-27T17:30:22.825374193Z Completed:    ALTER PLUGGABLE DATABASE ORCLPDB1 SAVE STATE
2022-09-27T17:30:22.825380155Z 2022-09-27T17:30:16.840766+00:00
2022-09-27T17:30:22.825385694Z
2022-09-27T17:30:22.825391198Z XDB initialized.

首先使用zypper命令安装docker

四、验证成果

4.1登录到docker容器内,验证Oracle服务

localhost:~ # docker exec -it oracle19c /bin/bash
[oracle@b5afbb001c0b ~]$ ls
setPassword.sh
[oracle@b5afbb001c0b ~]$ sqlplus / as sysdba

SQL*Plus: Release 19.0.0.0.0 - Production on Tue Sep 27 18:16:35 2022
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle.  All rights reserved.

ERROR:
ORA-12162: TNS:net service name is incorrectly specified


Enter user-name: ^C

报错了,服务名不正确,我们查看一下Oracle SID的变量是什么

[oracle@b5afbb001c0b ~]$ echo $ORACLE_SID  //查看SID值显示为空,我们需要设置一下

[oracle@b5afbb001c0b ~]$ export ORACLE_SID=ORCLCDB    //设置SID,此处回到上面3.1.7,你配置的是什么就写什么,否则无法登陆到数据库内
[oracle@b5afbb001c0b ~]$ sqlplus / as sysdba  //使用数据库管理员登录,因为是Oracle用户,所以可以不输入密码

SQL*Plus: Release 19.0.0.0.0 - Production on Tue Sep 27 18:17:45 2022
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle.  All rights reserved.


Connected to:
Oracle Database 19c Standard Edition 2 Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

SQL> show pdbs;  //正确登录,可以查看一下数据库的实例名

    CON_ID CON_NAME              OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
     2 PDB$SEED              READ ONLY  NO
     3 ORCLPDB1              READ WRITE NO
SQL> select 1 from dual;

     1
----------
     1

SQL>

4.2使用sqlplus登录验证

C:\Users\tonka>sqlplus sys/oracle@172.16.1.42/ORCLPDB1 as sysdba //根据配置的用户密码进行登录

SQL*Plus: Release 19.0.0.0.0 - Production on 星期三 9月 28 02:35:00 2022
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle.  All rights reserved.

ERROR:
ORA-28040: No matching authentication protocol   //提示错误,认证协议不匹配导致的

认证协议不匹配一般情况下是Oracle客户端与服务器不一致,需要做一些调整才可以正常登录

4.3调整Oracle服务器配置

[oracle@b5afbb001c0b ~]$ echo $ORACLE_HOME  //显示Oracle主目录
/opt/oracle/product/19c/dbhome_1
[oracle@b5afbb001c0b ~]$ vi /opt/oracle/product/19c/dbhome_1/network/admin/sqlnet.ora   //编辑sqlnet文件

sqlnet文件内容新增如下

NAME.DIRECTORY_PATH= (TNSNAMES, EZCONNECT, HOSTNAME)  //原有的不动
#add  //新增的内容
SQLNET.ALLOWED_LOGON_VERSION_SERVER=10  
SQLNET.ALLOWED_LOGON_VERSION_CLIENT=10  //版本可以更小,取决你客户端是什么,如果是11g就写10就可以,否则写 9 8 都可以

4.4再次验证

C:\Users\tonka>sqlplus sys/oracle@172.16.1.42/ORCLPDB1 as sysdba

SQL*Plus: Release 19.0.0.0.0 - Production on 星期三 9月 28 02:39:10 2022
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle.  All rights reserved.


连接到:
Oracle Database 19c Standard Edition 2 Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

SQL> select 1 from dual;

         1
----------
         1

SQL>

 

image

可以正确连接使用了。

五、写在最后

docker的性能不如物理机安装,不过可以应付一下了。

posted on 2022-09-28 02:51  tonkai  阅读(503)  评论(1编辑  收藏  举报

导航

tonkai