Docker安装Oracle19c

1. 准备镜像

接上一章 准备好Oraccle19c镜像:

https://www.jianshu.com/p/b683640677c9

myzmac:dockerfiles myz$ docker images  oracle/database:19.3.0-ee
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
oracle/database     19.3.0-ee           3c1a9d1ffc0a        14 minutes ago      6.61GB

2. 通过镜像创建实例

2.1. 创建实例

把数据文件 ,参数配置文件 ,tns ,监听挂载出来
分配2G内存,设定时区, 容器中的主机名, 容器名, 端口映身等

mkdir  -p /Users/myz/Docker/Oracle/19.3/
--执行创建
docker run -e TZ="Asia/Shanghai"  -itd -h ora193 -m 2048m --name ora193 \
  -p 1521:1521 -p 5500:5500 \
  -e ORACLE_SID=mycdb \
  -e ORACLE_PDB=pdb1 \
  -v /Users/myz/Docker/Oracle/19.3/:/opt/oracle/oradata  oracle/database:19.3.0-ee

通过命令:docker logs -f ora193 观察部署进度,预估15-25分钟完成


myzmac:Oracle myz$ docker logs -f ora193
ORACLE PASSWORD FOR SYS, SYSTEM AND PDBADMIN: C1eNxx1/a+k=1

LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 21-FEB-2020 00:03:01

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/ora193a/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                21-FEB-2020 00:03:01
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/ora193/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/MYCDB.
Database Information:
Global Database Name: MYCDB
System Identifier(SID): MYCDB
Look at the log file "/opt/oracle/cfgtoollogs/dbca/MYCDB/MYCDB.log" for further details.

SQL*Plus: Release 19.0.0.0.0 - Production on Fri Feb 21 00:25:35 2020
Version 19.3.0.0.0

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


Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

SQL>
System altered.

SQL>
System altered.

SQL>
Pluggable database altered.

SQL>
PL/SQL procedure successfully completed.

SQL> Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
The Oracle base remains unchanged with value /opt/oracle
#########################
DATABASE IS READY TO USE!
#########################
The following output is now a tail of the alert.log:
ORCLPDB1(3):ALTER DATABASE DEFAULT TABLESPACE "USERS"
ORCLPDB1(3):Completed: ALTER DATABASE DEFAULT TABLESPACE "USERS"
2020-02-21T00:25:35.547850+08:00
ALTER SYSTEM SET control_files='/opt/oracle/oradata/MYCDB/control01.ctl' SCOPE=SPFILE;
2020-02-21T00:25:35.568154+08:00
ALTER SYSTEM SET local_listener='' SCOPE=BOTH;
   ALTER PLUGGABLE DATABASE PDB1 SAVE STATE
Completed:    ALTER PLUGGABLE DATABASE PDB1 SAVE STATE

XDB initialized.

^C
myzmac:Oracle myz$   

当看到显示 DATABASE IS READY TO USE!
表示部署完成, 可以ctrl+c退出Log, 查看实例:

myzmac:Oracle myz$ docker ps -a
CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS                     PORTS                                            NAMES
02c23cc4cda5        oracle/database:19.3.0-ee   "/bin/sh -c 'exec $O…"   27 minutes ago      Up 27 minutes (healthy)    0.0.0.0:1521->1521/tcp, 0.0.0.0:5500->5500/tcp   ora193

3. 使用

设置sys,system等用户密码

docker exec ora193  ./setPassword.sh welcome1

3.1. 客户端连接

 sqlplus sys/oracle@//127.0.0.1:1521/mycdb as sysdba
SQL> sho pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDB1                           READ WRITE NO
SQL>   

 sqlplus sys/oracle@//127.0.0.1:1521/pdb1 as sysdba
SQL> sho con_name

CON_NAME
------------------------------
PDB1
SQL>     

3.2. 容器本地连接

需要配置环境变量,不然报如下错

myzmac:Oracle myz$ docker exec -it ora193a  bash
[oracle@ora193a ~]$ sqlplus / as sysdba

SQL*Plus: Release 19.0.0.0.0 - Production on Fri Feb 21 00:33:03 2020
Version 19.3.0.0.0

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

ERROR:
ORA-12162: TNS:net service name is incorrectly specified


Enter user-name: ^C
[oracle@ora193a ~]$  
--这里报错是因为没有配环境变量

配置bash_profile

vi ~/.bash_profile 
--增加如下内容
export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=/opt/oracle/product/19c/dbhome_1
export EDITOR=vi
stty erase ^H


vi ~/.bashrc
--增加如下内容
alias sqlplus='rlwrap sqlplus'
alias rman='rlwrap rman'
export ORACLE_SID=MYCDB
PS1='\[\e[37;40m\][\[\e[32;40m\]\u\[\e[37;40m\]@\h \[\e[35;40m\]\W\[\e[0m\]]\$'
alias tf='tail -100f /opt/oracle/diag/rdbms/mycdb/MYCDB/trace/al*.log'
alias tf100='tail -100 /opt/oracle/diag/rdbms/mycdb/MYCDB/trace/al*.log|more'
alias tf1000='tail -1000 /opt/oracle/diag/rdbms/mycdb/MYCDB/trace/al*.log|more'

不知道为什么ORACLEA_SID写到.bash_profile中并不生效.. 改到bashrc中了
重新登录

[oracle@ora193~]$ sqlplus / as sysdba       

SQL*Plus: Release 19.0.0.0.0 - Production on Tue Dec 31 20:57:15 2019
Version 19.3.0.0.0

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


Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

SQL>

4. 其他操作, 如迁移容器:

导出该容器,做为新的镜像 , 过程为 容器-> 导出为镜像-> scp-> 导入镜像->创建实例

--导出
docker export 02c23cc4cda5 >  19c.tar
--复制新镜像到其他环境后然后导入tar包(导入后是镜像)
docker import 19c.tar  oracle19c:19.3
--就可以创建个新的容器出来, 如果是本机注意外挂目录, 及映身端口的不同

你可能感兴趣的:(Docker安装Oracle19c)