沃梦达 / IT编程 / 服务器 / 正文

基于docker部署Oracle 19c的详细记录

这篇文章主要介绍了基于docker部署Oracle 19c,包括拉取oracle 19c镜像、查看镜像及创建oracle 19c镜像的容器问题,结合示例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

一. 拉取Oracle 19c镜像

[root@node08002 docker]# 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

二. 查看镜像

[root@node08002 docker]# docker images
REPOSITORY                                          TAG       IMAGE ID       CREATED         SIZE
registry.cn-hangzhou.aliyuncs.com/zhuyijun/oracle   19c       7b5eb4597688   20 months ago   6.61GB
[root@node08002 docker]# 

三. 创建Oracle 19c镜像的容器

3.1创建目录

[root@node08002 docker]# mkdir /opt/oradata
[root@node08002 docker]# chmod -R 777 /opt/oradata/
[root@node08002 docker]# 

3.2 创建实例

[root@node08002 docker]# docker run -d -it --name oracle19c -p 1521:1521 -p 5500:5500 -v /opt/oradata:/opt/oracle/oradata registry.cn-hangzhou.aliyuncs.com/zhuyijun/oracle:19c

3.3 查看日志

[root@node08002 ~]# docker logs -f oracle19c
ORACLE EDITION: ENTERPRISE
ORACLE PASSWORD FOR SYS, SYSTEM AND PDBADMIN: CRiP1dWzDHA=1
 
LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 06-APR-2022 10:28:18
Copyright (c) 1991, 2019, Oracle.  All rights reserved.
Starting /opt/oracle/product/19c/dbhome_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 19.0.0.0.0 - Production
System parameter file is /opt/oracle/product/19c/dbhome_1/network/admin/listener.ora
Log messages written to /opt/oracle/diag/tnslsnr/1249a4a7bb32/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 19.0.0.0.0 - Production
Start Date                06-APR-2022 10:28:18
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /opt/oracle/product/19c/dbhome_1/network/admin/listener.ora
Listener Log File         /opt/oracle/diag/tnslsnr/1249a4a7bb32/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
The listener supports no services
The command completed successfully
Prepare for db operation
8% complete
Copying database files
31% complete
Creating and starting Oracle instance
32% complete
36% complete
40% complete
43% complete
46% complete
Completing Database Creation
51% complete
54% complete
Creating Pluggable Databases
58% complete
77% complete
Executing Post Configuration Actions
100% complete
Database creation complete. For details check the logfiles at:
 /opt/oracle/cfgtoollogs/dbca/ORCLCDB.
Database Information:
Global Database Name:ORCLCDB
System Identifier(SID):ORCLCDB
Look at the log file "/opt/oracle/cfgtoollogs/dbca/ORCLCDB/ORCLCDB.log" for further details.
SQL*Plus: Release 19.0.0.0.0 - Production on Wed Apr 6 10:48:37 2022
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle.  All rights reserved.

四、 修改密码

系统默认的system密码修改成oracle

[root@node08002 ~]# docker exec oracle19c ./setPassword.sh oracle

setPassword.sh 脚本如下

[root@node08002 ~]# docker exec -it oracle19c /bin/bash
[oracle@1249a4a7bb32 ~]$ ls
setPassword.sh
[oracle@1249a4a7bb32 ~]$ pwd
/home/oracle
[oracle@1249a4a7bb32 ~]$ cat setPassword.sh 
#!/bin/bash
# LICENSE UPL 1.0
#
# Copyright (c) 1982-2018 Oracle and/or its affiliates. All rights reserved.
# 
# Since: November, 2016
# Author: gerald.venzl@oracle.com
# Description: Sets the password for sys, system and pdb_admin
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
# 
 
ORACLE_PWD=$1
ORACLE_SID="`grep $ORACLE_HOME /etc/oratab | cut -d: -f1`"
ORACLE_PDB="`ls -dl $ORACLE_BASE/oradata/$ORACLE_SID/*/ | grep -v pdbseed | awk '{print $9}' | cut -d/ -f6`"
ORAENV_ASK=NO
source oraenv
 
sqlplus / as sysdba << EOF
      ALTER USER SYS IDENTIFIED BY "$ORACLE_PWD";
      ALTER USER SYSTEM IDENTIFIED BY "$ORACLE_PWD";
      ALTER SESSION SET CONTAINER=$ORACLE_PDB;
      ALTER USER PDBADMIN IDENTIFIED BY "$ORACLE_PWD";
      exit;
EOF
 
[oracle@1249a4a7bb32 ~]$ 

五、连接数据库

sqlplus system/oracle@xxx.xxx.xxx.xxx:1521/ORCLCDB

5.1测试方案一:进入容器内部测试

[root@node08002 ~]# docker exec -it oracle19c /bin/bash
[oracle@1249a4a7bb32 ~]$ sqlplus system/oracle@localhost:1521/ORCLCDB
 
SQL*Plus: Release 19.0.0.0.0 - Production on Thu Apr 7 01:54:17 2022
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle.  All rights reserved.
Last Successful login time: Thu Apr 07 2022 01:53:14 +00:00
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
SQL> Show user;
USER is "SYSTEM"
SQL> exit
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
[oracle@1249a4a7bb32 ~]$ 

5.2测试方案二:用navicat连接测试

[root@node08002 ~]# docker exec -it oracle19c /bin/bash
[oracle@1249a4a7bb32 ~]$ cd /opt/oracle/product/19c/dbhome_1/network/admin/
[oracle@1249a4a7bb32 admin]$ ls
listener.ora  samples  shrept.lst  sqlnet.ora  tnsnames.ora
[oracle@1249a4a7bb32 admin]$ vim sqlnet.ora 
[oracle@1249a4a7bb32 admin]$ cat sqlnet.ora 
NAME.DIRECTORY_PATH= (TNSNAMES, EZCONNECT, HOSTNAME)
[oracle@1249a4a7bb32 admin]$ vim sqlnet.ora 
[oracle@1249a4a7bb32 admin]$ cat sqlnet.ora 
NAME.DIRECTORY_PATH= (TNSNAMES, EZCONNECT, HOSTNAME)
SQLNET.ALLOWED_LOGON_VERSION_CLIENT=8
SQLNET.ALLOWED_LOGON_VERSION_SERVER=8
[oracle@1249a4a7bb32 admin]$ exit
exit
[root@node08002 ~]# docker ps -a
CONTAINER ID   IMAGE                                                   COMMAND                  CREATED        STATUS                  PORTS                                                                                  NAMES
1249a4a7bb32   registry.cn-hangzhou.aliyuncs.com/zhuyijun/oracle:19c   "/bin/sh -c 'exec $O…"   16 hours ago   Up 16 hours (healthy)   0.0.0.0:1521->1521/tcp, :::1521->1521/tcp, 0.0.0.0:5500->5500/tcp, :::5500->5500/tcp   oracle19c
[root@node08002 ~]# docker restart oracle19c
oracle19c
[root@node08002 ~]# 

很奇怪,又要修改一次密码,具体操作步骤如下:

[root@node08002 ~]# docker exec -it oracle19c /bin/bash
[oracle@1249a4a7bb32 ~]$ sqlplus system/oracle@localhost:1521/ORCLCDB
 
SQL*Plus: Release 19.0.0.0.0 - Production on Thu Apr 7 02:59:52 2022
Version 19.3.0.0.0
 
Copyright (c) 1982, 2019, Oracle.  All rights reserved.
 
Last Successful login time: Thu Apr 07 2022 02:59:10 +00:00
 
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
 
SQL> alter user system identified by oracle;
 
User altered.
 
SQL> exit
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

终于可以连接了

到此这篇关于基于docker部署Oracle 19c的文章就介绍到这了,更多相关docker部署Oracle 19c内容请搜索编程学习网以前的文章希望大家以后多多支持编程学习网!

本文标题为:基于docker部署Oracle 19c的详细记录