在云上简单、快捷的部署Oracle Database,我们有多种途径实现:
一种方式是采用Oracle数据库云服务(Database Cloud Service)的方式,一键式部署Oracle数据库;
还有一种方法更加快速,只需要3分钟,是的,你没有看错,只要3分钟,你就可以获得一个全新的Oracle Database 11g环境。
首先,在Oracle云上创建一个Oracle Linux 7.3的实例(略过创建过程,具体流程参见本公众号的其他文章《在Oracle云上创建Oracle Linux实例》),然后在Oracle Linux 7.3的实例中安装和配置Docker Engine(略过创建过程,具体流程参见本公众号的其他文章《在Oracle云上安装和配置Docker Engine(OL7)》)。
系统环境信息:
[root@f807e9 opc]# uname -a
Linux f807e9 4.1.12-94.3.5.el7uek.x86_64 #2 SMP Wed May 24 08:36:18 PDT 2017 x86_64 x86_64 x86_64 GNU/Linux
[root@f807e9 opc]# cat etc/oracle-release
Oracle Linux Server release 7.3
IP地址: 129.191.27.7
首先,我们可以尝试在Docker Hub上搜索,看看是否有Oracle Database 11g的镜像:
[root@f807e9 opc]# docker search oracle
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
wnameless/oracle-xe-11g Oracle Express 11g R2 on Ubuntu 16.04 LTS 450 [OK]
oraclelinux Oracle Linux is an open-source operating s... 344 [OK]
alexeiled/docker-oracle-xe-11g This is a working (hopefully) Oracle XE 11... 208 [OK]
sath89/oracle-12c Oracle Standard Edition 12c Release 1 with... 137 [OK]
sath89/oracle-xe-11g Oracle xe 11g with database files mount su... 99 [OK]
isuper/java-oracle This repository contains all java releases... 56 [OK]
oracle/oraclelinux Oracle Linux is an open-source operating s... 37 [OK]
ingensi/oracle-jdk Official Oracle JDK installed on centos. 20 [OK]
oracle/openjdk Docker images containing OpenJDK Oracle Linux 20 [OK]
cogniteev/oracle-java Oracle JDK 6, 7, 8, and 9 based on Ubuntu ... 18 [OK]
airdock/oracle-jdk Docker Image for Oracle Java SDK (8 and 7)... 17 [OK]
oracle/glassfish GlassFish Java EE Application Server on Or... 14 [OK]
n3ziniuka5/ubuntu-oracle-jdk Ubuntu with Oracle JDK. Check tags for ver... 13 [OK]
oracle/nosql Oracle NoSQL on a Docker Image with Oracle... 10 [OK]
andreptb/oracle-java Debian Jessie based image with Oracle JDK ... 8 [OK]
infogene/oracle Image for running Oracle Database 11g Stan... 6 [OK]
openweb/oracle-tomcat A fork off of Official tomcat image with O... 5 [OK]
flurdy/oracle-java7 Base image containing Oracle's Java 7 JDK 4 [OK]
jtech/oracle-jdk A Docker image based on the smallest Linux... 3 [OK]
davidcaste/debian-oracle-java Oracle Java 8 (and 7) over Debian Jessie 3 [OK]
sgrio/java-oracle Docker images of Java 7/8 provided by Orac... 2 [OK]
publicisworldwide/oracle-core This is the core image based on Oracle Lin... 1 [OK]
clincase/oracle clincase oracle db server image 1 [OK]
jckrz/debian-oracle-jdk Vanilla Debian + Oracle JDK 1 [OK]
expertsystems/oracle-jdk8 CentOS based base image with Oracle JDK 8 0 [OK]
可以看到,Docker Hub确实已经有人上传了Oracle数据库镜像,而且从镜像的描述上可以了解到,这些镜像多是由Oracle公司提供,镜像质量有保障。但是,很不幸,网上能找到的镜像都是标准版或者快捷版(XE版),没有我们需要的企业版。
看来只能是自动动手,丰衣足食了。
好在前几天,老余难得有空,自己动手做了一个11g企业版的Docker 镜像,并上传到前段时间刚创建好的私有Docker Registry上(略过创建过程,具体流程参见本公众号的其他文章《在Oracle云上部署Docker Registry》),今天正好给大家演示一下,从私有Docker Registry下载Oracle Database 11g的Docker 镜像,并部署到Oracle云上。等哪天有空,我会创建Oracle Database 11g Docker镜像的过程好好整理,再发布到本公众号上,敬请期待。
Docker Registry环境信息:
IP地址: 129.191.26.216
端口:5000
查看Docker Registry上的镜像信息:
[root@f807e9 opc]# curl 129.191.26.216:5000/v2/_catalog
{"repositories":["yc/helloworld","yc/oracle11g"]}
[root@f807e9 opc]# curl 129.191.26.216:5000/v2/yc/oracle11g/tags/list
{"name":"yc/oracle11g","tags":["latest"]}
从Docker Registry下载镜像:
[root@f807e9 opc]# docker pull 129.191.26.216:5000/yc/oracle11g
Using default tag: latest
Error response from daemon: Get https://129.191.26.216:5000/v1/_ping: http: server gave HTTP response to HTTPS client
以上信息提示表明,该registry类型为insecure registry,需要在本地docker daemon中加入insecure-registries启动参数。
通过以下命令在docker daemon中添加insecure-registries选项
[root@f807e9 opc]# echo '{ "insecure-registries":["129.191.26.216:5000"] }' > /etc/docker/daemon.json
[root@f807e9 opc]#
[root@f807e9 opc]# cat /etc/docker/daemon.json
{ "insecure-registries":["129.191.26.216:5000"] }
修改后,需要重启Docker服务
[root@f807e9 opc]# service docker restart
Redirecting to /bin/systemctl restart docker.service
从Docker Registry下载Oracle Database 11g的镜像:
[root@f807e9 opc]# docker pull 129.191.26.216:5000/yc/oracle11g
Using default tag: latest
latest: Pulling from yc/oracle11g
41fcaf1b19e7: Pull complete
b697676d090b: Pull complete
8919a4aeeb59: Pull complete
ad70449d2d8d: Pull complete
18f7a81233a3: Pull complete
Digest: sha256:924ab67c61e251d453cdcaec7249c8f65c5dfca3ce67175824f4e19bae5c21f5
Status: Downloaded newer image for 129.191.26.216:5000/yc/oracle11g:latest
这个镜像中已经包含Oracle软件介质,同时数据库也创建好了,因此镜像比较大,有7.364 GB,在Oracle云上,两个实例之间传输镜像速度非常快,整个下载镜像过程只用了短短的3分钟,是的,你没有看错,只用了3分钟。
查看以下载的镜像信息:
[root@f807e9 opc]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
129.191.26.216:5000/yc/oracle11g latest 68f7cfe25072 15 hours ago 7.364 GB
为便于管理,可以改一下镜像的标签:
[root@f807e9 opc]# docker tag 129.191.26.216:5000/yc/oracle11g yc/oracle11g
[root@f807e9 opc]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
129.191.26.216:5000/yc/oracle11g latest 68f7cfe25072 16 hours ago 7.364 GB
yc/oracle11g latest 68f7cfe25072 16 hours ago 7.364 GB
在本地启动容器,让容器在后台运行:
[root@f807e9 opc]# docker run -m 4G --memory-swap 5G -dit -p 1521:1521 --name oracle11g yc/oracle11g /bin/bash
注:将容器的1521端口映射到本地的1521端口,这样其他服务器就可以通过这个端口访问容器中的数据库。
[root@f807e9 opc]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7c1187951986 yc/oracle11g "/bin/bash" 42 minutes ago Up 42 minutes 0.0.0.0:1521->1521/tcp oracle11g
进入容器:
[root@f807e9 opc]#docker exec -it 7c1187951986 /bin/bash
[root@7c1187951986 /]#
[root@7c1187951986 /]# su - oracle
[oracle@7c1187951986 ~]$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvdc 50G 7.0G 43G 15% /
tmpfs 7.3G 0 7.3G 0% /dev
tmpfs 7.3G 0 7.3G 0% /sys/fs/cgroup
/dev/xvdc 50G 7.0G 43G 15% /etc/resolv.conf
/dev/xvdc 50G 7.0G 43G 15% /etc/hostname
/dev/xvdc 50G 7.0G 43G 15% /etc/hosts
shm 64M 0 64M 0% /dev/shm
tmpfs 7.3G 0 7.3G 0% /proc/kcore
tmpfs 7.3G 0 7.3G 0% /proc/timer_list
tmpfs 7.3G 0 7.3G 0% /proc/timer_stats
tmpfs 7.3G 0 7.3G 0% /proc/sched_debug
[oracle@7c1187951986 ~]$ cat /etc/oracle-release
Oracle Linux Server release 6.9
[oracle@7c1187951986 ~]$ uname -a
Linux 7c1187951986 4.1.12-94.3.5.el7uek.x86_64 #2 SMP Wed May 24 08:36:18 PDT 2017 x86_64 x86_64 x86_64 GNU/Linux
这个数据库的镜像已经安装了数据库软件,同时创建了数据库,但是没有设置数据库和监听器自启动,需要手工启动。
[oracle@7c1187951986 ~]$ lsnrctl start
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 01-JUN-2017 08:40:04
Copyright (c) 1991, 2009, Oracle. All rights reserved.
Starting /u01/app/oracle/product/11.2.0/db_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Log messages written to /u01/app/oracle/diag/tnslsnr/7c1187951986/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=7c1187951986)(PORT=1521)))
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date 01-JUN-2017 08:40:10
Uptime 0 days 0 hr. 0 min. 5 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Log File /u01/app/oracle/diag/tnslsnr/7c1187951986/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=7c1187951986)(PORT=1521)))
The listener supports no services
The command completed successfully
[oracle@7c1187951986 ~]$ sqlplus "/as sysdba"
SQL*Plus: Release 11.2.0.1.0 Production on Thu Jun 1 08:40:22 2017
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 1603411968 bytes
Fixed Size 2213776 bytes
Variable Size 402655344 bytes
Database Buffers 1191182336 bytes
Redo Buffers 7360512 bytes
Database mounted.
Database opened.
SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
好的,数据库和监听器已经启动完毕。
测试连接数据库
登录另一台服务器,测试连接docker容器中的oracle数据库
[oracle@bc1c3b ~]$ ping 129.191.27.7
PING 129.191.27.7 (129.191.27.7) 56(84) bytes of data.
64 bytes from 129.191.27.7: icmp_seq=1 ttl=60 time=0.926 ms
64 bytes from 129.191.27.7: icmp_seq=2 ttl=60 time=0.536 ms
^C
--- 129.191.27.7 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1914ms
rtt min/avg/max/mdev = 0.536/0.731/0.926/0.195 ms
采用EZconnect的方式连接容器中的数据库
[oracle@bc1c3b ~]$ sqlplus system/Welcome1@129.191.27.7:1521/ora11
SQL*Plus: Release 11.2.0.1.0 Production on Thu Jun 1 05:01:23 2017
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
至此,我们已经把镜像从私有的Docker Registry上下载到本地,并顺利启动容器,启动数据库,数据库运行正常。
总结一下整个过程:
第一步,从Docker Registry下载Oracle Database 11g镜像,只需一条命令,下载7.3G的镜像耗时3分钟。
第二步,在本地启动容器,只需一条命令,耗时2秒。
第三步,进入容器,启动数据库和监听,耗时10秒。
整个过程耗时3分钟左右, 是不是很神奇!!!
你是不是心动了,赶紧来试一试吧。