首頁 > 軟體

基於docker部署Oracle 19c的詳細記錄

2022-04-08 16:00:25

一. 拉取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內容請搜尋it145.com以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援it145.com!


IT145.com E-mail:sddin#qq.com