前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【DB宝13】在Docker中只需2步即可拥有Oracle 12cR1(12.1.0.2)企业版环境

【DB宝13】在Docker中只需2步即可拥有Oracle 12cR1(12.1.0.2)企业版环境

作者头像
小麦苗DBA宝典
发布2021-05-06 14:53:24
6670
发布2021-05-06 14:53:24
举报

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

  • 小麦苗的Docker Hub的地址:https://hub.docker.com/u/lhrbest
  • 小麦苗的Oracle 12cR1(12.1.0.2)的Docker Hub地址:https://hub.docker.com/r/lhrbest/oracle_12cr1_ee_lhr_12.1.0.2/tags
代码语言:javascript
复制
# 从Docker hub下载,网络不好时,一般比较慢
docker pull lhrbest/oracle_12cr1_ee_lhr_12.1.0.2:1.0
# 推荐从阿里云下载
docker pull registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_12cr1_ee_lhr_12.1.0.2:1.0

# 从阿里云下载后可以tag成如下形式
docker tag registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_12cr1_ee_lhr_12.1.0.2:1.0  lhrbest/oracle_12cr1_ee_lhr_12.1.0.2:1.0

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

代码语言:javascript
复制
[root@lhrdocker ~]# docker search 12cR1 --no-trunc   
NAME                                   DESCRIPTION                                                                                           STARS               OFFICIAL            AUTOMATED
lhrbest/oracle_12cr1_ee_lhr_12.1.0.2   Oracle 12cR1 企业版, 12.1.0.2 ,QQ:646634621,微信公众号:DB宝,CentOS 7.6,包含一个cdb,sid为lhrcdb1,一个非cdb,sid为lhrsdb   0                                       
[root@lhrdocker ~]# 
[root@lhrdocker ~]# docker pull registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_12cr1_ee_lhr_12.1.0.2:1.0
1.0: Pulling from lhrbest/oracle_12cr1_ee_lhr_12.1.0.2
ac9208207ada: Already exists 
3f87d8dbb1ef: Pull complete 
512a15c4c83e: Pull complete 
0602305ad716: Pull complete 
Digest: sha256:99ef263a861f71c7bac56018fad58b61640e40a44e98f0e9bd135a077a07960e
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_12cr1_ee_lhr_12.1.0.2:1.0
registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_12cr1_ee_lhr_12.1.0.2:1.0
[root@lhrdocker ~]# docker tag registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_12cr1_ee_lhr_12.1.0.2:1.0 lhrbest/oracle_12cr1_ee_lhr_12.1.0.2:1.0
[root@lhrdocker ~]# docker images | grep 12.1
lhrbest/oracle_12cr1_ee_lhr_12.1.0.2                                     1.0                 2d8e7a9451ec        28 hours ago        15.9GB
registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_12cr1_ee_lhr_12.1.0.2   1.0                 2d8e7a9451ec        28 hours ago        15.9GB

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

代码语言:javascript
复制
# 创建镜像
docker run -itd --name lhrora1212 -h lhrora1212 --privileged=true -p 1522:1521 -p 223:22 -p 5550:5500 -p 5551:5501  lhrbest/oracle_12cr1_ee_lhr_12.1.0.2:1.0 init

# 进入容器
docker exec -it lhrora1212 bash

# 启动数据库和监听
su - oracle
lsnrctl start
sqlplus / as sysdba
startup
exit
ORACLE_SID=lhrsdb
sas
startup

运行过程:

代码语言:javascript
复制
[root@lhrdocker ~]# docker run -itd --name lhrora1212 -h lhrora1212 --privileged=true -p 1522:1521 -p 223:22 -p 5550:5500 -p 5551:5501  lhrbest/oracle_12cr1_ee_lhr_12.1.0.2:1.0 init      
b9896808a05e6d755d67e4c35159a39ab538fb6dde2af50c5e4a45a01b50b0cc
[root@lhrdocker ~]# docker exec -it lhrora1212 bash
[root@lhrora1212 /]# su - oracle
Last login: Fri Jul 10 18:15:13 CST 2020 on pts/2
[oracle@lhrora1212 ~]$ lsnrctl start

LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 11-JUL-2020 22:52:39

Copyright (c) 1991, 2014, Oracle.  All rights reserved.

Starting /u01/app/oracle/product/12.1.0.2/dbhome_1/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 12.1.0.2.0 - Production
System parameter file is /u01/app/oracle/product/12.1.0.2/dbhome_1/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/lhrora1212/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=lhrora1212)(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=lhrora1212)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 12.1.0.2.0 - Production
Start Date                11-JUL-2020 22:52:39
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.1.0.2/dbhome_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/lhrora1212/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=lhrora1212)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
The listener supports no services
The command completed successfully
[oracle@lhrora1212 ~]$ sas

SQL*Plus: Release 12.1.0.2.0 Production on Sat Jul 11 22:52:42 2020

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

Connected to an idle instance.

SYS@lhrcdb1> startup 
ORACLE instance started.

Total System Global Area  805306368 bytes
Fixed Size                  2929552 bytes
Variable Size             377490544 bytes
Database Buffers          419430400 bytes
Redo Buffers                5455872 bytes
Database mounted.
Database opened.
SYS@lhrcdb1> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 LHRPDB1                        READ WRITE NO
SYS@lhrcdb1> exit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

[oracle@lhrora1212 ~]$ ORACLE_SID=lhrsdb
[oracle@lhrora1212 ~]$ sas

SQL*Plus: Release 12.1.0.2.0 Production on Sat Jul 11 22:53:51 2020

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

Connected to an idle instance.

SYS@lhrsdb> startup
ORACLE instance started.

Total System Global Area  805306368 bytes
Fixed Size                  2929552 bytes
Variable Size             373296240 bytes
Database Buffers          423624704 bytes
Redo Buffers                5455872 bytes
Database mounted.
Database opened.
SYS@lhrsdb> show pdbs
SYS@lhrsdb> exit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

三、尽情使用吧

3.1 数据库使用

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

代码语言:javascript
复制
[oracle@lhrora1212 ~]$ lsnrctl status

LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 11-JUL-2020 22:56:29

Copyright (c) 1991, 2014, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=lhrora1212)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 12.1.0.2.0 - Production
Start Date                11-JUL-2020 22:52:39
Uptime                    0 days 0 hr. 3 min. 49 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/12.1.0.2/dbhome_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/lhrora1212/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=lhrora1212)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=lhrora1212)(PORT=5500))(Security=(my_wallet_directory=/u01/app/oracle/admin/lhrcdb1/xdb_wallet))(Presentation=HTTP)(Session=RAW))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=lhrora1212)(PORT=5501))(Security=(my_wallet_directory=/u01/app/oracle/admin/lhrsdb/xdb_wallet))(Presentation=HTTP)(Session=RAW))
Services Summary...
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 创建数据库

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

代码语言:javascript
复制
# 静默创建一个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端口号,但是我们在创建容器的时候进行了端口映射,所以访问EM时需要注意端口的不同:

  • CDB数据库lhrcdb1的EM访问地址:https://192.168.59.220:5550/em
  • 非CDB数据库lhrsdb的EM访问地址:https://192.168.59.220:5551/em
代码语言:javascript
复制
[oracle@lhrora1212 ~]$ lsnrctl status | grep tcps
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=lhrora1212)(PORT=5500))(Security=(my_wallet_directory=/u01/app/oracle/admin/lhrcdb1/xdb_wallet))(Presentation=HTTP)(Session=RAW))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=lhrora1212)(PORT=5501))(Security=(my_wallet_directory=/u01/app/oracle/admin/lhrsdb/xdb_wallet))(Presentation=HTTP)(Session=RAW))

3.4 使用ssh连接到容器内

代码语言:javascript
复制
C:\Users\lhrxxt>ssh root@192.168.59.220 -p223
The authenticity of host '[192.168.59.220]:223 ([192.168.59.220]:223)' 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]:223' (ECDSA) to the list of known hosts.
root@192.168.59.220's password:
[root@lhrora1212 ~]# ps -ef|grep pmon
oracle      210      0  0 22:52 ?        00:00:00 ora_pmon_lhrcdb1
oracle      656      0  0 22:53 ?        00:00:00 ora_pmon_lhrsdb
root       1733   1705  0 22:59 pts/2    00:00:00 grep --color=auto pmon

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

在连接时,需要注意端口映射的不同,主机的1522映射为容器内的1521端口:

代码语言:javascript
复制
C:\Users\lhrxxt>sqlplus sys/lhr@192.168.59.220:1522/lhrcdb1 as sysdba

SQL*Plus: Release 12.1.0.2.0 Production on Sat Jul 11 23:00:13 2020

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


Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SYS@192.168.59.220:1522/lhrcdb1> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 LHRPDB1                        READ WRITE NO
SYS@192.168.59.220:1522/lhrcdb1> conn sys/lhr@192.168.59.220:1522/lhrsdb as sysdba
Connected.
SYS@192.168.59.220:1522/lhrsdb> show pdbs

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

怎么样,是不是很爽,是不是非常方便呢,文末记得点赞哈。

本文结束。

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-07-31,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 DB宝 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、从Docker Hub或阿里云镜像下载小麦苗上传的镜像文件
  • 二、创建容器并启动数据库
  • 三、尽情使用吧
    • 3.1 数据库使用
      • 3.2 创建数据库
        • 3.3 EMDE的使用
          • 3.4 使用ssh连接到容器内
            • 3.5 外部客户端连接容器内的数据库
            相关产品与服务
            数据库
            云数据库为企业提供了完善的关系型数据库、非关系型数据库、分析型数据库和数据库生态工具。您可以通过产品选择和组合搭建,轻松实现高可靠、高可用性、高性能等数据库需求。云数据库服务也可大幅减少您的运维工作量,更专注于业务发展,让企业一站式享受数据上云及分布式架构的技术红利!
            领券
            问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档