签到成功

知道了

CNDBA社区CNDBA社区

【DB宝14】在Docker中只需2步即可拥有Oracle 11g企业版环境(11.2.0.4)

2020-08-05 08:51 3654 0 原创 安装卸载
作者: 小麦苗
[TOC]

原文地址:https://mp.weixin.qq.com/s/1Z630TbilkQ3aAyOcosl4w

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

# 从Docker hub下载,网络不好时,一般比较慢
docker pull lhrbest/oracle_11g_ee_lhr_11.2.0.4:1.0
# 可以选择从阿里云下载,一般比较快
docker pull registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_11g_ee_lhr_11.2.0.4:1.0
# 从阿里云下载后可以tag成如下形式
docker tag registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_11g_ee_lhr_11.2.0.4:1.0 lhrbest/oracle_11g_ee_lhr_11.2.0.4:1.0

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

[root@lhrdocker ~]# docker search 11.2.0.4 --no-trunc | grep -E "NAME|lhr"
NAME                                          DESCRIPTION                                                                                  STARS               OFFICIAL            AUTOMATED
lhrbest/oracle_11g_ee_lhr_11.2.0.4            Oracle 11g 企业版, 11.2.0.4 ,QQ:646634621,微信公众号:DB宝,作者:小麦苗                                      0                                       
[root@lhrdocker ~]# 
[root@docker36 ~]# docker pull registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_11g_ee_lhr_11.2.0.4:1.0
1.0: Pulling from lhrbest/oracle_11g_ee_lhr_11.2.0.4
5dd797628260: Already exists 
ea1a739ab78d: Pull complete 
593d06e585fc: Pull complete 
Digest: sha256:7a2c2bf264cc9e5b5608deb98abe388c61d8fe2c981ee3475b0d2a38bb1fd8b4
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_11g_ee_lhr_11.2.0.4:1.0
registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_11g_ee_lhr_11.2.0.4:1.0
[root@docker36 ~]# docker tag registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_11g_ee_lhr_11.2.0.4:1.0  lhrbest/oracle_11g_ee_lhr_11.2.0.4:1.0
[root@docker36 ~]# docker images | grep 11.2.0.4
lhrbest/oracle_11g_ee_lhr_11.2.0.4                                       1.0                 18261f9fdcf0        43 minutes ago      7.61GB
registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_11g_ee_lhr_11.2.0.4     1.0                 18261f9fdcf0        43 minutes ago      7.61GB

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

 # 创建容器
docker run -itd --name lhrora11204 -h lhrora11204 --privileged=true -p 1521:1521 -p 222:22  -p 1158:1158 lhrbest/oracle_11g_ee_lhr_11.2.0.4:1.0 init

# 进入容器
docker exec -it lhrora11204 bash

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

# 启动EM
emctl start dbconsole

执行过程: http://www.cndba.cn/lhrbest/article/4223

[root@docker36 ~]# docker exec -it lhrora11204 bash
[root@lhrora11204 /]#
[root@lhrora11204 /]# su - oracle
[oracle@lhrora11204 ~]$ 
[oracle@lhrora11204 ~]$ lsnrctl start

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 24-JUL-2020 09:20:41

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

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

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date                24-JUL-2020 09:20:41
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/11.2.0.4/dbhome_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/lhrora11204/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=lhrora11204)(PORT=1521)))
The listener supports no services
The command completed successfully

[oracle@lhrora11204 ~]$ sas

SQL*Plus: Release 11.2.0.4.0 Production on Fri Jul 24 09:20:50 2020

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

Connected to an idle instance.

SYS@LHR11G> startup 
ORACLE instance started.

Total System Global Area  325685248 bytes
Fixed Size                  2252944 bytes
Variable Size             188747632 bytes
Database Buffers          130023424 bytes
Redo Buffers                4661248 bytes
Database mounted.
Database opened.
SYS@LHR11G> 
SYS@LHR11G> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

[oracle@lhrora11204 ~]$ emctl status dbconsole
Oracle Enterprise Manager 11g Database Control Release 11.2.0.4.0 
Copyright (c) 1996, 2013 Oracle Corporation.  All rights reserved.
https://lhrora11204:1158/em/console/aboutApplication
Oracle Enterprise Manager 11g is not running. 
------------------------------------------------------------------
Logs are generated in directory /u01/app/oracle/product/11.2.0.4/dbhome_1/lhrora11204_LHR11G/sysman/log 
[oracle@lhrora11204 ~]$ emctl start dbconsole 
Oracle Enterprise Manager 11g Database Control Release 11.2.0.4.0 
Copyright (c) 1996, 2013 Oracle Corporation.  All rights reserved.
https://lhrora11204:1158/em/console/aboutApplication
Starting Oracle Enterprise Manager 11g Database Control ...... started. 
------------------------------------------------------------------
Logs are generated in directory /u01/app/oracle/product/11.2.0.4/dbhome_1/lhrora11204_LHR11G/sysman/log 
[oracle@lhrora11204 ~]$ emctl status dbconsole
Oracle Enterprise Manager 11g Database Control Release 11.2.0.4.0 
Copyright (c) 1996, 2013 Oracle Corporation.  All rights reserved.
https://lhrora11204:1158/em/console/aboutApplication
Oracle Enterprise Manager 11g is running. 
------------------------------------------------------------------
Logs are generated in directory /u01/app/oracle/product/11.2.0.4/dbhome_1/lhrora11204_LHR11G/sysman/log

三、尽情使用吧

3.1 数据库使用

[oracle@lhrora11204 ~]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 24-JUL-2020 09:23:08

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date                24-JUL-2020 09:20:41
Uptime                    0 days 0 hr. 2 min. 26 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/11.2.0.4/dbhome_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/lhrora11204/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=lhrora11204)(PORT=1521)))
Services Summary...
Service "LHR11G" has 1 instance(s).
  Instance "LHR11G", status READY, has 1 handler(s) for this service...
Service "LHR11GXDB" has 1 instance(s).
  Instance "LHR11G", status READY, has 1 handler(s) for this service...
The command completed successfully
[oracle@lhrora11204 ~]$ sas

SQL*Plus: Release 11.2.0.4.0 Production on Fri Jul 24 09:23:10 2020

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


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SYS@LHR11G> select * from v$version;

BANNER
-------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
CORE    11.2.0.4.0      Production
TNS for Linux: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - Production

SYS@LHR11G> select * from v$tablespace;

       TS# NAME        INCLUD BIGFIL FLASHB ENCRYP
---------- ----------- ------ ------ ------ ------
         0 SYSTEM      YES    NO     YES
         1 SYSAUX      YES    NO     YES
         2 UNDOTBS1    YES    NO     YES
         4 USERS       YES    NO     YES
         3 TEMP        NO     NO     YES
         6 EXAMPLE     YES    NO     YES

6 rows selected.

SYS@LHR11G>

3.2 创建数据库(可选)

我们也可以自己创建自己需要的数据库,如下所示,http://www.cndba.cn/lhrbest/article/4223

dbca -silent -createDatabase -templateName General_Purpose.dbc -responseFile NO_VALUE /
-gdbname LHR11G2  -sid LHR11G2 /
-sysPassword lhr -systemPassword lhr /
-datafileDestination '/u01/app/oracle/oradata' /
-recoveryAreaDestination '/u01/app/oracle/flash_recovery_area' /
-storageType FS /
-characterset AL32UTF8 -nationalCharacterSet AL16UTF16 /
-sampleSchema true /
-totalMemory 300 /
-databaseType OLTP  /
-emConfiguration NONE

3.3 EMDC的使用

该镜像已经创建好了EMDC (Enterprise Manager Database Control) 了, 所以,可以直接访问,地址为:https://192.168.1.36:1158/em ,sys用户密码为lhrhttp://www.cndba.cn/lhrbest/article/4223

1595582856573

1595582908536http://www.cndba.cn/lhrbest/article/4223

3.4 使用ssh连接到容器内

C:/Users/lhrxxt>ssh root@192.168.1.36 -p222
The authenticity of host '[192.168.1.36]:222 ([192.168.1.36]:222)' can't be established.
RSA key fingerprint is SHA256:KCuMsxiuP493oXTYB6R3VNl2BXBEl9Hf9EYtmsAjOEE.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[192.168.1.36]:222' (RSA) to the list of known hosts.
root@192.168.1.36's password:
Last login: Mon Jul 13 02:59:40 2020 from 172.17.0.1
[root@lhrora11204 ~]#  ps -ef|grep pmon
oracle     1574      0  0 09:20 ?        00:00:00 ora_pmon_LHR11G
root       3882   3856  0 09:28 pts/3    00:00:00 grep pmon

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

我们可以在容器外部通过sqlplus或其他工具连接容器内的数据库:http://www.cndba.cn/lhrbest/article/4223

C:/Users/lhrxxt>sqlplus sys/lhr@192.168.1.36/LHR11G AS SYSDBA

SQL*Plus: Release 12.1.0.2.0 Production on Fri Jul 24 17:29:46 2020

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


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SYS@192.168.1.36/LHR11G>

如果使用PLSQL Developer也是可以连接的,如下: http://www.cndba.cn/lhrbest/article/4223http://www.cndba.cn/lhrbest/article/4223

1595583097887

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

版权声明:本文为博主原创文章,未经博主允许不得转载。

用户评论
* 以下用户言论只代表其个人观点,不代表CNDBA社区的观点或立场
小麦苗

小麦苗

关注

小麦苗博客,实用经典,简单易懂,接地气!-----技术应用型博客,主打实用性,只讲实用的,不讲没用的,多做实验,多思考!

  • 58
    原创
  • 0
    翻译
  • 0
    转载
  • 2
    评论
  • 访问:168591次
  • 积分:288
  • 等级:中级会员
  • 排名:第14名
精华文章
    最新问题
    查看更多+
    热门文章
      热门用户
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by CNDBA · 皖ICP备2022006297号-1·

        QQ交流群

        注册联系QQ