在Docker中部署Oracle 12cR2(12.2.0.1)企业版环境 - ITB运维部落—http://www.itbcn.cn—ITB运维技术交流之家平台-ITB运维部落—http://www.itbcn.cn—ITB运维技术交流之家平台
记录工作点滴
分享运维知识

在Docker中部署Oracle 12cR2(12.2.0.1)企业版环境

目录

一、从Docker Hub或阿里云镜像下载小麦苗上传的镜像文件
二、创建容器并启动数据库
三、尽情使用吧
  3.1 数据库使用
  3.2 创建数据库
  3.3 EMDE的使用
  3.4 使用ssh连接到容器内
  3.5 外部客户端连接容器内的数据库

一、从Docker Hub或阿里云镜像下载小麦苗上传的镜像文件

  • 小麦苗的Docker Hub的地址:https://hub.docker.com/u/lhrbest
  • 小麦苗的Oracle 12cR2(12.2.0.1)的Docker Hub地址:https://hub.docker.com/r/lhrbest/oracle_12cr2_ee_lhr_12.2.0.1/tags
# 从Docker hub下载,网络不好时,一般比较慢
docker pull lhrbest/oracle_12cr2_ee_lhr_12.2.0.1:1.0
# 推荐从阿里云下载
docker pull registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_12cr2_ee_lhr_12.2.0.1:1.0
# 从阿里云下载后可以tag成如下形式
docker tag registry.cn-registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_12cr2_ee_lhr_12.2.0.1:1.0  lhrbest/oracle_12cr2_ee_lhr_12.2.0.1:1.0

镜像大概4.79G左右,解压后大约15G左右,所以请保留充足的空间。执行过程如下:

 [[email protected]~]# docker search 12cR2 --no-trunc 
 NAME                  DESCRIPTION        STARS               OFFICIAL            AUTOMATED
 lhrbest/oracle_12cr2_ee_lhr_12.2.0.1   Oracle 12cR2 企业版, 12.2.0.1 ,QQ:646634621,微信公众号:DB宝,CentOS 7.6,包含一个cdb,sid为lhrcdb1,一个非cdb,sid为lhrsdb    0                                       
 [[email protected]~]# docker pull registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_12cr2_ee_lhr_12.2.0.1:1.0
 1.0: Pulling from lhrbest/oracle_12cr2_ee_lhr_12.2.0.1
 ac9208207ada: Already exists 
 3f87d8dbb1ef: Already exists 
 512a15c4c83e: Already exists 
 ce417a4cad38: Pull complete 
Digest: sha256:5b2924030665688c2dbd5722b0bf21fbf4fcc69efbac8f113dd43c43b6241341
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_12cr2_ee_lhr_12.2.0.1:1.0
registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_12cr2_ee_lhr_12.2.0.1:1.0
[[email protected]~]# docker tag registry.cn-registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_12cr2_ee_lhr_12.2.0.1:1.0  lhrbest/oracle_12cr2_ee_lhr_12.2.0.1:1.0
[[email protected]~]# docker images | grep 12.2
lhrbest/oracle_12cr2_ee_lhr_12.2.0.1                                     1.0                 c9a76e991b46        27 hours ago        14.8GB
registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_12cr2_ee_lhr_12.2.0.1   1.0                 c9a76e991b46        27 hours ago        14.8GB

二、创建容器并启动数据库

 # 创建镜像
 docker run -itd --name lhrora1221 -h lhrora1221 --privileged=true -p 1521:1521 -p 222:22 -p 5500:5500 -p 5501:5501  lhrbest/oracle_12cr2_ee_lhr_12.2.0.1:1.0 init
 # 进入容器
docker exec -it lhrora1221 bash
 # 启动数据库和监听
 su - oracle
 lsnrctl start
sqlplus / as sysdba
startup
exit
ORACLE_SID=lhrsdb
sas
startup

运行过程:

 [[email protected]~]# docker run -itd --name lhrora1221 -h lhrora1221 --privileged=true -p 1521:1521 -p 222:22 -p 5500:5500 -p 5501:5501  lhrbest/oracle_12cr2_ee_lhr_12.2.0.1:1.0 init
 e46fc8ff1a9bb4dd905d08de3515036695a8267a2e0f30b553d05dc16f38005e
 [[email protected]~]# docker exec -it lhrora1221 bash
 [[email protected]/]# su - oracle
 Last login: Fri Jul 10 16:36:50 CST 2020 on pts/0
 [[email protected]~]$ lsnrctl start
 LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 11-JUL-2020 20:00:05
Copyright (c) 1991, 2016, Oracle.  All rights reserved.
Starting /u01/app/oracle/product/12.2.0.1/dbhome_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 12.2.0.1.0 - Production
System parameter file is /u01/app/oracle/product/12.2.0.1/dbhome_1/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/lhrora1221/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=lhrora1221)(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=lhrora1221)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 12.2.0.1.0 - Production
Start Date                11-JUL-2020 20:00:05
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/12.2.0.1/dbhome_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/lhrora1221/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=lhrora1221)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
The listener supports no services
The command completed successfully
[[email protected]~]$ sas
SQL*Plus: Release 12.2.0.1.0 Production on Sat Jul 11 20:00:17 2020
Copyright (c) 1982, 2016, Oracle.  All rights reserved.
Connected to an idle instance.
[email protected]> startup 
ORACLE instance started.
Total System Global Area  805306368 bytes
Fixed Size                  8797928 bytes
Variable Size             583008536 bytes
Database Buffers          205520896 bytes
Redo Buffers                7979008 bytes
Database mounted.
Database opened.
[email protected]> show pdbs
  CON_ID CON_NAME              OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
    2 PDB$SEED                  READ ONLY  NO
    3 LHRPDB1                  MOUNTED
[email protected]> alter pluggable database lhrpdb1 open;
Pluggable database altered.
[email protected]> show pdbs
  CON_ID CON_NAME            OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
     2 PDB$SEED            READ ONLY  NO
     3 LHRPDB1             READ WRITE  NO
[email protected]> alter pluggable database all save state;
Pluggable database altered.
[email protected]> exit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
[[email protected]~]$ ORACLE_SID=lhrsdb
[[email protected]~]$ sas
SQL*Plus: Release 12.2.0.1.0 Production on Sat Jul 11 20:02:10 2020
Copyright (c) 1982, 2016, Oracle.  All rights reserved.
Connected to an idle instance.
[email protected]> startup 
ORACLE instance started.
Total System Global Area  805306368 bytes
Fixed Size                  8625856 bytes
Variable Size             578814272 bytes
Database Buffers          209715200 bytes
Redo Buffers                8151040 bytes
Database mounted.
Database opened.
[email protected]>

三、尽情使用吧

3.1 数据库使用

该镜像包括一个cdb(sid为lhrcdb1)和一个非cdb(sid为lhrsdb),可以直接使用:

 [[email protected]~]$ lsnrctl status
 LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 11-JUL-2020 20:06:02
 Copyright (c) 1991, 2016, Oracle.  All rights reserved.
 Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=lhrora1221)(PORT=1521)))
 STATUS of the LISTENER
 ------------------------
Alias                  LISTENER
Version                 TNSLSNR for Linux: Version 12.2.0.1.0 - Production
Start Date               11-JUL-2020 20:00:05
Uptime                   0 days 0 hr. 5 min. 57 sec
Trace Level               off
Security                 ON: Local OS Authentication
SNMP                   OFF
Listener Parameter File              /u01/app/oracle/product/12.2.0.1/dbhome_1/network/admin/listener.ora
Listener Log File              /u01/app/oracle/diag/tnslsnr/lhrora1221/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=lhrora1221)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=lhrora1221)(PORT=5500))(Security=(my_wallet_directory=/u01/app/oracle/admin/lhrcdb1/xdb_wallet))(Presentation=HTTP)(Session=RAW))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=lhrora1221)(PORT=5501))(Security=(my_wallet_directory=/u01/app/oracle/admin/lhrsdb/xdb_wallet))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "aa133779e7bf28e8e053090011ac3234" has 1 instance(s).
  Instance "lhrcdb1", status READY, has 1 handler(s) for this service...
Service "lhrcdb1" has 1 instance(s).
  Instance "lhrcdb1", status READY, has 1 handler(s) for this service...
Service "lhrcdb1XDB" has 1 instance(s).
  Instance "lhrcdb1", status READY, has 1 handler(s) for this service...
Service "lhrpdb1" has 1 instance(s).
  Instance "lhrcdb1", status READY, has 1 handler(s) for this service...
Service "lhrsdb" has 1 instance(s).
  Instance "lhrsdb", status READY, has 1 handler(s) for this service...
Service "lhrsdbXDB" has 1 instance(s).
  Instance "lhrsdb", status READY, has 1 handler(s) for this service...
The command completed successfully

3.2 创建数据库

我们也可以自己创建自己需要的数据库,如下所示:

 # 静默创建一个cdb的库
 dbca -silent -ignorePreReqs  -createDatabase -templateName General_Purpose.dbc -responseFile NO_VALUE \
 -gdbname lhrcdb1  -sid lhrcdb1 \
 -createAsContainerDatabase TRUE \
 -numberOfPDBs 1 \
 -pdbName lhrpdb1 \
 -pdbAdminPassword lhr \
 -sysPassword lhr -systemPassword lhr -dbsnmpPassword lhr \
 -datafileDestination '/u01/app/oracle/oradata' -recoveryAreaDestination '/u01/app/oracle/flash_recovery_area' \
-storageType FS \
-characterset AL32UTF8 \
-sampleSchema true \
-totalMemory 1024 \
-databaseType MULTIPURPOSE \
-emConfiguration NONE
# 静默创建一个非cdb的库
dbca -silent -ignorePreReqs  -createDatabase -templateName General_Purpose.dbc -responseFile NO_VALUE \
-gdbname lhrsdb  -sid lhrsdb \
-createAsContainerDatabase FALSE \
-sysPassword lhr -systemPassword lhr -dbsnmpPassword lhr \
-datafileDestination '/u01/app/oracle/oradata' -recoveryAreaDestination '/u01/app/oracle/flash_recovery_area' \
-storageType FS \
-characterset ZHS16GBK \
-sampleSchema true \
-totalMemory 1024 \
-databaseType MULTIPURPOSE \
-emConfiguration NONE

3.3 EMDE的使用

该镜像已经配置好EMDE(Enterprise Manager Database Express)了,可以直接使用,端口号分别为5500和5501,5500端口为cdb的em端口号,5501为非cdb的em端口号:

  • CDB数据库lhrcdb1的EM访问地址:https://192.168.59.220:5500/em
  • 非CDB数据库lhrsdb的EM访问地址:https://192.168.59.220:5501/em
[[email protected]~]$ lsnrctl status | grep tcps
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=lhrora1221)(PORT=5500))(Security=(my_wallet_directory=/u01/app/oracle/admin/lhrcdb1/xdb_wallet))(Presentation=HTTP)(Session=RAW))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=lhrora1221)(PORT=5501))(Security=(my_wallet_directory=/u01/app/oracle/admin/lhrsdb/xdb_wallet))(Presentation=HTTP)(Session=RAW))
[[email protected]~]$ 

3.4 使用ssh连接到容器内

 C:\Users\lhrxxt>[email protected]
 The authenticity of host '[192.168.59.220]:222 ([192.168.59.220]:222)' can't be established.
 ECDSA key fingerprint is SHA256:ccSyRCHeeBDxZ29MPE47TA+c+d875ldU4PyM6Avv7vw.
 Are you sure you want to continue connecting (yes/no)? yes
 Warning: Permanently added '[192.168.59.220]:222' (ECDSA) to the list of known hosts.
 [email protected]'s password:
 Last login: Fri Jul 10 16:23:29 2020
 [[email protected]~]# ps -ef|grep pmon
 oracle      202      0  0 20:00 ?        00:00:00 ora_pmon_lhrcdb1
 oracle      930      0  0 20:02 ?        00:00:00 ora_pmon_lhrsdb
 root       4194     4165  0 20:24 pts/2        00:00:00 grep --color=auto pmon
[[email protected]~]#

3.5 外部客户端连接容器内的数据库

 C:\Users\lhrxxt>[email protected]:1521/lhrcdb1 as sysdba
 SQL*Plus: Release 12.1.0.2.0 Production on Sat Jul 11 20:24:46 2020
 Copyright (c) 1982, 2014, Oracle.  All rights reserved.
 Connected to:
 Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
[email protected]:1521/lhrcdb1> show pdbs
  CON_ID CON_NAME            OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
     2 PDB$SEED            READ ONLY NO
     3 LHRPDB1             READ WRITE NO
[email protected]:1521/lhrcdb1>[email protected]:1521/lhrsdb as sysdba
Connected.
[email protected]:1521/lhrsdb> show pdbs
[email protected]:1521/lhrsdb>

如果使用PLSQL Developer也是可以连接的,如下:

 

未经允许不得转载:ITB运维部落—http://www.itbcn.cn—ITB运维技术交流之家平台 » 在Docker中部署Oracle 12cR2(12.2.0.1)企业版环境

如果文章对你有帮助,欢迎点击上方按钮打赏作者

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址