admin

docker快速安装oracle12c和配置数据库

admin 数据库 2023-06-02 1069浏览 0

# 从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左右,所以请保留充足的空间。执行过程如下:

 lhrbest/oracle_12cr2_ee_lhr_12.2.0.1   

 Oracle 12cR2 企业版, 12.2.0.1 CentOS 7.6

 包含一个cdb,sid为lhrcdb1,一个非cdb,sid为lhrsdb

                          

 [root@lhrdocker ~]# 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

[root@lhrdocker ~]# 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

[root@lhrdocker ~]# 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

运行过程:


[root@lhrdocker ~]# 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

 [root@lhrdocker ~]# docker exec -it lhrora1221 bash


 [root@lhrora1221 /]# su - oracle


 Last login: Fri Jul 10 16:36:50 CST 2020 on pts/0

 [oracle@lhrora1221 ~]$ 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

[oracle@lhrora1221 ~]$ 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.

SYS@lhrcdb1> 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.

SYS@lhrcdb1> show pdbs

  CON_ID CON_NAME              OPEN MODE  RESTRICTED

---------- ------------------------------ ---------- ----------

    2 PDB$SEED                  READ ONLY  NO

    3 LHRPDB1                  MOUNTED

SYS@lhrcdb1> alter pluggable database lhrpdb1 open;

Pluggable database altered.

SYS@lhrcdb1> show pdbs

  CON_ID CON_NAME            OPEN MODE  RESTRICTED

---------- ------------------------------ ---------- ----------

     2 PDB$SEED            READ ONLY  NO

     3 LHRPDB1             READ WRITE  NO

SYS@lhrcdb1> alter pluggable database all save state;

Pluggable database altered.

SYS@lhrcdb1> exit

Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

[oracle@lhrora1221 ~]$ ORACLE_SID=lhrsdb

[oracle@lhrora1221 ~]$ 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.

SYS@lhrsdb> 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.

SYS@lhrsdb>

三、尽情使用吧

3.1 数据库使用

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


 [oracle@lhrora1221 ~]$ 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

[oracle@lhrora1221 ~]$ 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))

[oracle@lhrora1221 ~]$ 




3.4 使用ssh连接到容器内

 C:\Users\lhrxxt>ssh root@192.168.59.220 -p222


 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.

 root@192.168.59.220's password:

 Last login: Fri Jul 10 16:23:29 2020

 [root@lhrora1221 ~]# 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

[root@lhrora1221 ~]#

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

 C:\Users\lhrxxt>sqlplus sys/lhr@192.168.59.220: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

SYS@192.168.59.220:1521/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:1521/lhrcdb1> conn sys/lhr@192.168.59.220:1521/lhrsdb as sysdba

Connected.

SYS@192.168.59.220:1521/lhrsdb> show pdbs

SYS@192.168.59.220:1521/lhrsdb>


版权声明

本站《作品展示》类文章均为原创,转载必须注明出处,技术分享类文章部分来源于网络,版权归原作者所有,若侵权请留言。