docker 安裝oracle 19C
最近有個需求,客戶環境安裝oracle資料庫安裝不上,想到用docker的方式制作好oracle鏡像然後傳到客戶的機器上直接用docker跑oracle下面是大概流程記錄一下
安裝oracle19cdocker的版本必須在17以上
Docker version is below the minimum required version 17.09
Please upgrade your Docker installation to proceed.
解除安裝原來yum安裝的docker
systemctl stop docker.service
yum remove -y docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine
安裝docker
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum -y install docker-ce docker-ce-cli containerd.io
[[email protected] dockerfiles]# docker -v
Docker version 20.10.8, build 3967b7d
1.建立目錄下載下傳鏡像
[[email protected] ~]# mkdir /oracle
[[email protected] ~]# cd /oracle
[[email protected] oracle]# git clone https://github.com/oracle/docker-images.git
Cloning into 'docker-images'...
remote: Enumerating objects: 14389, done.
remote: Counting objects: 100% (403/403), done.
remote: Compressing objects: 100% (272/272), done.
remote: Total 14389 (delta 171), reused 313 (delta 115), pack-reused 13986
Receiving objects: 100% (14389/14389), 10.04 MiB | 96.00 KiB/s, done.
Resolving deltas: 100% (8429/8429), done.
[[email protected] oracle]# ll
total 4
drwxr-xr-x 30 root root 4096 Aug 14 12:37 docker-images
[[email protected] oracle]# cd /docker-images/OracleDatabase/SingleInstance/dockerfiles/
[[email protected] docker-images]# ll
total 32
drwxr-xr-x 2 root root 4096 Aug 14 12:37 11.2.0.2
drwxr-xr-x 2 root root 4096 Aug 14 12:37 12.1.0.2
drwxr-xr-x 2 root root 4096 Aug 14 12:37 12.2.0.1
drwxr-xr-x 2 root root 4096 Aug 14 12:37 18.3.0
drwxr-xr-x 2 root root 4096 Aug 14 12:37 18.4.0
drwxr-xr-x 2 root root 4096 Aug 14 12:37 19.3.0
-rwxr-xr-x 1 root root 6953 Aug 14 12:37 buildContainerImage.sh
buildDockerImage.sh 檔案可以制作鏡像
我們看到是存在19.3.0的dockerfile的,同時檢查其安裝的安裝封包件名:
[[email protected] dockerfiles]# cd 19.3.0
[[email protected] 19.3.0]# ll
total 84
-rwxr-xr-x 1 root root 1040 Aug 14 12:37 checkDBStatus.sh
-rwxr-xr-x 1 root root 898 Aug 14 12:37 checkSpace.sh
-rw-r--r-- 1 root root 63 Aug 14 12:37 Checksum.ee
-rw-r--r-- 1 root root 63 Aug 14 12:37 Checksum.se2
-rwxr-xr-x 1 root root 6375 Aug 14 12:37 createDB.sh
-rw-r--r-- 1 root root 9204 Aug 14 12:37 dbca.rsp.tmpl
-rw-r--r-- 1 root root 6878 Aug 14 12:37 db_inst.rsp
-rw-r--r-- 1 root root 4336 Aug 14 12:37 Dockerfile
-rwxr-xr-x 1 root root 2656 Aug 14 12:37 installDBBinaries.sh
-rw-r--r-- 1 root root 1967 Aug 14 12:37 relinkOracleBinary.sh
-rwxr-xr-x 1 root root 7453 Aug 14 12:37 runOracle.sh
-rwxr-xr-x 1 root root 1015 Aug 14 12:37 runUserScripts.sh
-rwxr-xr-x 1 root root 785 Aug 14 12:37 setPassword.sh
-rwxr-xr-x 1 root root 1035 Aug 14 12:37 setupLinuxEnv.sh
-rwxr-xr-x 1 root root 678 Aug 14 12:37 startDB.sh
[[email protected] 19.3.0]# cat Dockerfile|grep INSTALL_FILE_1
INSTALL_FILE_1="LINUX.X64_193000_db_home.zip" \
COPY --chown=oracle:dba $INSTALL_FILE_1 $INSTALL_RSP $INSTALL_DB_BINARIES_FILE $INSTALL_DIR/
2. 将安裝包拷貝到該目錄下,運作開始安裝:
需要提前下載下傳Oracle安裝媒體,檔案名預設是不需要更改的,應該是LINUX.X64_193000_db_home.zip,然後将其複制到對應版本的目錄下即可。
[[email protected] 19.3.0]# ll
total 2988084
-rwxr-xr-x 1 root root 1040 Aug 14 12:37 checkDBStatus.sh
-rwxr-xr-x 1 root root 898 Aug 14 12:37 checkSpace.sh
-rw-r--r-- 1 root root 63 Aug 14 12:37 Checksum.ee
-rw-r--r-- 1 root root 63 Aug 14 12:37 Checksum.se2
-rwxr-xr-x 1 root root 6375 Aug 14 12:37 createDB.sh
-rw-r--r-- 1 root root 9204 Aug 14 12:37 dbca.rsp.tmpl
-rw-r--r-- 1 root root 6878 Aug 14 12:37 db_inst.rsp
-rw-r--r-- 1 root root 4336 Aug 14 12:37 Dockerfile
-rwxr-xr-x 1 root root 2656 Aug 14 12:37 installDBBinaries.sh
-rw-r--r-- 1 root root 3059705302 Aug 17 2019 LINUX.X64_193000_db_home.zip -----------需要上傳
-rw-r--r-- 1 root root 1967 Aug 14 12:37 relinkOracleBinary.sh
-rwxr-xr-x 1 root root 7453 Aug 14 12:37 runOracle.sh
-rwxr-xr-x 1 root root 1015 Aug 14 12:37 runUserScripts.sh
-rwxr-xr-x 1 root root 785 Aug 14 12:37 setPassword.sh
-rwxr-xr-x 1 root root 1035 Aug 14 12:37 setupLinuxEnv.sh
-rwxr-xr-x 1 root root 678 Aug 14 12:37 startDB.sh
[[email protected] dockerfiles]# ./buildContainerImage.sh -v 19.3.0 -e
Removing intermediate container 826420d25096
---> 82192fd0a0b1
Successfully built 82192fd0a0b1
Successfully tagged oracle/database:19.3.0-ee
Oracle Database container image for 'ee' version 19.3.0 is ready to be extended:
--> oracle/database:19.3.0-ee
Build completed in 792 seconds.
當出現上面的提示,就表示鏡像制作完成了,剩下就是利用該鏡像啟動容器即可。
3. 啟動容器:安裝資料庫
啟動容器
[[email protected] dockerfiles]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
oracle/database 19.3.0-ee 82192fd0a0b1 13 minutes ago 6.53GB
oraclelinux 7-slim 0a28ba78f4c9 8 weeks ago 132MB
---簡易啟動不挂載本地目錄
[[email protected] dockerfiles]# docker run --name oracle-19c-test -p 1521:1521 -p 5500:5500 -e ORACLE_SID=ora19c -e ORACLE_PDB=test -e ORACLE_PWD=oracle oracle/database:19.3.0-ee
100% complete
Database creation complete. For details check the logfiles at:
/opt/oracle/cfgtoollogs/dbca/ORA19C.
Database Information:
Global Database Name:ORA19C
System Identifier(SID):ORA19C
登陸主機或資料庫進行操作:
[[email protected] overlay2]# docker exec -it oracle-19c-test bash
[[email protected] dbs]$ export ORACLE_SID=ORA19C
[[email protected] dbs]$ sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on Sat Aug 14 06:50:07 2021
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> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 TEST READ WRITE NO
SQL>
SQL> alter session set container=test;
Session altered.
SQL> create user test identified by test;
User created.
SQL> grant dba to test;
Grant succeeded.
lsnr[[email protected] dbs]$ lsnrctl status
LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 14-AUG-2021 06:53:26
Copyright (c) 1991, 2019, Oracle. All rights reserved.
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 14-AUG-2021 06:14:19
Uptime 0 days 0 hr. 39 min. 6 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/a3ac36cf068a/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=a3ac36cf068a)(PORT=5500))(Security=(my_wallet_directory=/opt/oracle/admin/ORA19C/xdb_wallet))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "ORA19C" has 1 instance(s).
Instance "ORA19C", status READY, has 1 handler(s) for this service...
Service "ORA19CXDB" has 1 instance(s).
Instance "ORA19C", status READY, has 1 handler(s) for this service...
Service "c9801174d7950c41e053020011acf687" has 1 instance(s).
Instance "ORA19C", status READY, has 1 handler(s) for this service...
Service "test" has 1 instance(s).
Instance "ORA19C", status READY, has 1 handler(s) for this service...
The command completed successfully
至此就完成了docker安裝Oracle 19c!對于測試、試驗非常友善~
--測試遠端連接配接test庫的test使用者
sqlplus test/[email protected].70.199.168:1521/test
-----登陸em
https://81.70.199.168:5500/em
###################
注意:/oracle/oradata目錄權限一定要正确,在容器中oracle使用者的uid是54321,是以要保證容器内的oracle使用者有權限讀寫該目錄。
如建立oracle使用者且uid是54321:
容器内的使用者id如下
uid=54321(oracle) gid=54321(oinstall) groups=54321(oinstall),54322(dba),54323(oper),54324(backupdba),54325(dgdba),54326(kmdba),54330(racdba)
groupadd -g 54321 oinstall
groupadd -g 54322 dba
groupadd -g 54323 oper
useradd -u 54321 -g oinstall -G dba,oper -d /home/oracle -s /bin/bash -c "Oracle Software Owner" oracle
echo "oracle" | passwd --stdin oracle
chown oracle:oinstall /data/oracle
useradd -u 54321 -g oinstall -G dba oracle
注:如果"DATABASE IS READY TO USE!"提示資訊,表示資料庫已成功安裝了。
注意:oracle 企業版的docker run的指令格式如下(XE版的都有所差別):
建立本機挂載目錄
[[email protected] ]# mkdir - p /data/oracle
[[email protected] ~]# chmod 775 /data/oracle
----指定挂載本地目錄啟動 加-v參數,-p主控端的1522映射容器的1521端口,
[[email protected] dockerfiles]#docker run --name oracle-19c -p 1522:1521 -p 5501:5500 -e ORACLE_SID=orcl -e ORACLE_PDB=pdb1 -e ORACLE_PWD=oracle -v /data/oracle:/opt/oracle/oradata oracle/database:19.3.0-ee
過程日志報錯:
mkdir: cannot create directory '/opt/oracle/oradata/dbconfig': Permission denied
mv: cannot stat '/opt/oracle/product/19c/dbhome_1/dbs/spfileORCL.ora': No such file or directory
mv: cannot stat '/opt/oracle/product/19c/dbhome_1/dbs/orapwORCL': No such file or directory
mv: cannot move '/opt/oracle/product/19c/dbhome_1/network/admin/sqlnet.ora' to '/opt/oracle/oradata/dbconfig/ORCL/': No such file or directory
mv: cannot move '/opt/oracle/product/19c/dbhome_1/network/admin/listener.ora' to '/opt/oracle/oradata/dbconfig/ORCL/': No such file or directory
mv: cannot move '/opt/oracle/product/19c/dbhome_1/network/admin/tnsnames.ora' to '/opt/oracle/oradata/dbconfig/ORCL/': No such file or directory
mv: cannot move '/opt/oracle/product/19c/dbhome_1/install/.docker_enterprise' to '/opt/oracle/oradata/dbconfig/ORCL/': No such file or directory
cp: cannot create regular file '/opt/oracle/oradata/dbconfig/ORCL/': No such file or directory
ln: failed to create symbolic link '/opt/oracle/product/19c/dbhome_1/network/admin/sqlnet.ora': File exists
ln: failed to create symbolic link '/opt/oracle/product/19c/dbhome_1/network/admin/listener.ora': File exists
ln: failed to create symbolic link '/opt/oracle/product/19c/dbhome_1/network/admin/tnsnames.ora': File exists
cp: cannot stat '/opt/oracle/oradata/dbconfig/ORCL/oratab': No such file or directory
[[email protected] ~]# docker exec -it oracle-19c bash
[[email protected] /]$ cd /opt
[[email protected] opt]$ cd oracle
[[email protected] oracle]$ ll
total 92
drwxr-x--- 3 oracle oinstall 4096 Aug 14 07:16 admin
drwxr-x--- 2 oracle oinstall 4096 Aug 14 07:16 audit
drwxr-x--- 3 oracle oinstall 4096 Aug 14 07:16 cfgtoollogs
-rwxr-xr-x 1 oracle dba 1040 Aug 14 04:37 checkDBStatus.sh
drwxr-xr-x 2 oracle dba 4096 Aug 14 05:36 checkpoints
-rwxr-xr-x 1 oracle dba 6375 Aug 14 04:37 createDB.sh
-rw-r--r-- 1 oracle dba 9204 Aug 14 04:37 dbca.rsp.tmpl
drwxrwxr-x 1 oracle dba 4096 Aug 14 05:36 diag
drwxrwx--- 1 oracle dba 4096 Aug 14 07:16 oraInventory
drwxrwxr-x 2 root root 4096 Aug 14 05:53 oradata
drwxr-xr-x 1 oracle dba 4096 Aug 14 05:28 product
-rwxr-xr-- 1 oracle dba 1967 Aug 14 04:37 relinkOracleBinary.sh
-rwxr-xr-x 1 oracle dba 7453 Aug 14 04:37 runOracle.sh
-rwxr-xr-x 1 oracle dba 1015 Aug 14 04:37 runUserScripts.sh
drwxr-xr-x 1 oracle dba 4096 Aug 14 05:28 scripts
-rwxr-xr-x 1 oracle dba 785 Aug 14 04:37 setPassword.sh
-rwxr-xr-x 1 oracle dba 678 Aug 14 04:37 startDB.sh
oradata的屬主為root:root在主控端上建立oracle使用者,更改/data/oracle的屬主為oracle:oinstall
groupadd -g 3000 oinstall
groupadd -g 3300 dba
groupadd -g 3301 oper
useradd -u 54321 -g oinstall -G dba,oper -d /home/oracle -s /bin/bash -c "Oracle Software Owner" oracle
echo "oracle" | passwd --stdin oracle
chown oracle:oinstall /data/oracle
重新運作docker
[[email protected] dockerfiles]#docker run --name oracle-19c -p 1522:1521 -p 5501:5500 -e ORACLE_SID=orcl -e ORACLE_PDB=pdb1 -e ORACLE_PWD=oracle -v /data/oracle:/opt/oracle/oradata oracle/database:19.3.0-ee
[[email protected] data]# docker exec -it oracle-19c bash
[[email protected] ~]$ cd /opt/oracle
[[email protected] oracle]$ ll
total 104
drwxr-x--- 3 oracle oinstall 4096 Aug 14 07:34 admin
drwxr-x--- 2 oracle oinstall 4096 Aug 14 07:34 audit
drwxr-x--- 3 oracle oinstall 4096 Aug 14 07:34 cfgtoollogs
-rwxr-xr-x 1 oracle dba 1040 Aug 14 04:37 checkDBStatus.sh
drwxr-xr-x 2 oracle dba 4096 Aug 14 05:36 checkpoints
-rwxr-xr-x 1 oracle dba 6375 Aug 14 04:37 createDB.sh
-rw-r--r-- 1 oracle oinstall 9111 Aug 14 07:34 dbca.rsp
-rw-r--r-- 1 oracle dba 9204 Aug 14 04:37 dbca.rsp.tmpl
drwxrwxr-x 1 oracle dba 4096 Aug 14 05:36 diag
drwxrwx--- 1 oracle dba 4096 Aug 14 07:34 oraInventory
drwxrwxr-x 3 oracle 3000 4096 Aug 14 07:34 oradata
#########################
将容器目前運作狀态做成鏡像
[[email protected] data]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
445c7227f000 oracle/database:19.3.0-ee "/bin/sh -c 'exec $O…" 6 minutes ago Up 6 minutes (health: starting) 0.0.0.0:1522->1521/tcp, :::1522->1521/tcp, 0.0.0.0:5501->5500/tcp, :::5501->5500/tcp oracle-19c
a3ac36cf068a oracle/database:19.3.0-ee "/bin/sh -c 'exec $O…" About an hour ago Up About an hour (healthy) 0.0.0.0:1521->1521/tcp, :::1521->1521/tcp, 0.0.0.0:5500->5500/tcp, :::5500->5500/tcp oracle-19c-test
将容器打包成鏡像
-a 為作者
-m 為描述資訊
b2a3d7b67722 運作中的容器的ID
docker commit -a "guan" -m "oracle19c" 容器名稱或id 打包的鏡像名稱:标簽
[[email protected] data]# docker commit -a "guan" -m "oracle19c" a3ac36cf068a oracle19c:19.3
sha256:3c052c4bfb27d95728f5212216f9e6d9fcdee29111d6ef61105f54d182b865fa
[[email protected] data]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
oracle19c 19.3 3c052c4bfb27 About a minute ago 11.1GB
oracle/database 19.3.0-ee 82192fd0a0b1 2 hours ago 6.53GB
oraclelinux 7-slim 0a28ba78f4c9 8 weeks ago 132MB
wnameless/oracle-xe-11g-r2 latest 0d19fd2e072e 22 months ago 2.1GB
拖到本地
[[email protected] data]# docker save -o oracle19c.tar oracle19c
[[email protected] data]# ll
total 11412344
drwxr-xr-x 3 root root 4096 Nov 30 2014 expc
drwxr-xr-x 11 root root 4096 Jun 3 17:27 mysql-8.0.18-el7-x86_64
drwxrwxr-x 4 oracle oinstall 4096 Aug 14 15:49 oracle
-rw------- 1 root root 11090573824 Aug 14 15:54 oracle19c.tar
drwxr-xr-x 3 root root 4096 Jul 14 15:27 pkg
drwxr-xr-x 8 root root 4096 Jul 16 15:09 sysbench-0.5
-rw-r--r-- 1 root root 379910 Oct 15 2019 sysbench-0.5.zip
-rw-r--r-- 1 root root 595253657 May 22 23:51 v10.5_linuxx64_expc.tar.g
如果别的地方需要用這個鏡相包有點大11.1GB,一般都是儲存資料庫初始化前的鏡像
[[email protected] data]# docker save -o oracle19c_init.tar 82192fd0a0b1
#####################
将 oracle19c_init.tar 上傳到其他伺服器初始化資料庫
[[email protected] data]# scp oracle19c.tar 42.193.124.94:/data
docker load -i oracle11g.tar
其他伺服器本地rpm安裝docker 18版本
[[email protected] data]# cd /docker
[[email protected] docker]# ll
total 82028
-rw-r--r-- 1 root root 1369600 Jun 2 2020 busybox.tar
-rw-r--r-- 1 root root 34620 Jun 2 2020 container-selinux-2.55-1.el7.noarch.rpm
-rw-r--r-- 1 root root 36254876 Jun 2 2020 docker-ce-18.03.1.ce-1.el7.centos.x86_64.rpm
-rw-r--r-- 1 root root 165680 Jun 2 2020 libselinux-2.5-12.el7.x86_64.rpm
-rw-r--r-- 1 root root 240876 Jun 2 2020 libselinux-python-2.5-12.el7.x86_64.rpm
-rw-r--r-- 1 root root 154984 Jun 2 2020 libselinux-utils-2.5-12.el7.x86_64.rpm
-rw-r--r-- 1 root root 153596 Jun 2 2020 libsemanage-2.5-11.el7.x86_64.rpm
-rw-r--r-- 1 root root 114804 Jun 2 2020 libsemanage-python-2.5-11.el7.x86_64.rpm
-rw-r--r-- 1 root root 303736 Jun 2 2020 libsepol-2.5-8.1.el7.x86_64.rpm
-rw-r--r-- 1 root root 69596 Jun 2 2020 pigz-2.3.3-1.el7.centos.x86_64.rpm
-rw-r--r-- 1 root root 887548 Jun 2 2020 policycoreutils-2.5-22.el7.x86_64.rpm
-rw-r--r-- 1 root root 464972 Jun 2 2020 policycoreutils-python-2.5-22.el7.x86_64.rpm
-rw-r--r-- 1 root root 35773952 Jun 2 2020 registry.tar
-rw-r--r-- 1 root root 463504 Jun 2 2020 selinux-policy-3.13.1-192.el7_5.3.noarch.rpm
-rw-r--r-- 1 root root 6879848 Jun 2 2020 selinux-policy-targeted-3.13.1-192.el7_5.3.noarch.rpm
-rw-r--r-- 1 root root 634220 Jun 2 2020 setools-libs-3.3.8-2.el7.x86_64.rpm
[[email protected] docker]# yum localinstall *.rpm
或者
[[email protected] docker]# rpm -Uvh *.rpm --nodeps --force
[[email protected] docker]# yum install libltdl*
[[email protected] docker]# docker -v
Docker version 18.03.1-ce, build 9ee9f40
[[email protected] docker]# cd /data
[[email protected] data]# ll
total 6407960
-rw------- 1 root root 6561743872 Aug 14 16:50 oracle19c_init.tar
啟動docker然後加載鏡像
[[email protected] data]# systemctl start docker
[[email protected] data]# docker load -i oracle19c_init.tar
docker images
59759852752f: Loading layer [==================================================>] 138.3MB/138.3MB
9550e87abf8e: Loading layer [==================================================>] 6.144kB/6.144kB
df9bdaa744c5: Loading layer [==================================================>] 36.86kB/36.86kB
77637225ce51: Loading layer [==================================================>] 193.6MB/193.6MB
60836f228c7e: Loading layer [==================================================>] 6.208GB/6.208GB
e6a2db469328: Loading layer [==================================================>] 21.86MB/21.86MB
Loaded image ID: sha256:82192fd0a0b1575b2a2adb93829cfb7e48baea5e7c0f9e23de1e09811d00535a
REPOSITORY 和TAG均為none
[[email protected] data]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 82192fd0a0b1 3 hours ago 6.53GB
wnameless/oracle-xe-11g-r2 latest 0d19fd2e072e 22 months ago 2.1GB
給鏡像重命名
docker tag IMAGEID(鏡像id) REPOSITORY:TAG(倉庫:标簽)
[[email protected] data]# docker tag 82192fd0a0b1 oracle19c:19.3-ee
[[email protected] data]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
oracle19c 19.3-ee 82192fd0a0b1 3 hours ago 6.53GB
wnameless/oracle-xe-11g-r2 latest 0d19fd2e072e 22 months ago 2.1GB
最簡運作
docker run --name oracle-19c-test -p 1521:1521 -p 5500:5500 -e ORACLE_SID=ora19c -e ORACLE_PDB=test -e ORACLE_PWD=oracle oracle19c:19.3-ee