前言
docker是一个用Go语言实现的开源项目,可以让我们方便的创建和使用容器,docker将程序以及程序所有的依赖都打包到docker container,这样你的程序可以在任何环境都会有一致的表现,这里程序运行的依赖也就是容器就好比集装箱,容器所处的操作系统环境就好比货船或港口,程序的表现只和集装箱有关系(容器),和集装箱放在哪个货船或者哪个港口(操作系统)没有关系。
一、下载docker静态二进制存档
要根据硬件平台下载以免造成不兼容
https://download.docker.com/
根据自己的需求安装对应的版本(我这里选择的是docker-20.10.7)
https://download.docker.com/linux/static/stable/x86_64/docker-20.10.7.tgz
将下载好的的包上传到对应服务器
并解压 tar -zxvf docker-20.10.7.tgz
解压完的文件为docker
[root@v-ct-jy-czzp-app-160 opt]# tar -zxvf docker-20.10.7.tgz
二、将解压完的二进制文件移到可执行文件目录下
[root@v-ct-jy-czzp-app-160 opt]# mv docker/* /usr/bin/
三、配置docker.service
[root@v-ct-jy-czzp-app-160 opt]# vim /usr/lib/systemd/system/docker.service
将以下内容填入
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=infinity
LimitNPROC=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
四、启动dockerd服务
[root@v-ct-jy-czzp-app-160 opt]# systemctl daemon-reload
[root@v-ct-jy-czzp-app-160 opt]# systemctl start docker.service
[root@v-ct-jy-czzp-app-160 opt]# docker info
将docker设置为开机自启动
[root@v-ct-jy-czzp-app-160 opt]# systemctl enable docker
五、在有网络的环境生成Oracle11g镜像并导入
5.1下载镜像Oracle11g镜像
注意最好使用的服务器要和内网机器系统兼容否则镜像导入时会报错
[root@summer summer]# docker pull registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
Using default tag: latest
latest: Pulling from helowin/oracle_11g
ed5542b8e0e1: Pull complete
a3ed95caeb02: Pull complete
1e8f80d0799e: Pull complete
Digest: sha256:4c12b98372dfcbaafcd9564a37c8d91456090a5c6fb07a4ec18270c9d9ef9726
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g:latest
registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g:latest
5.2将镜像打包
[root@summer summer]#docker save registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g:latest > oracle11g.tar
5.3将镜像导入
[root@v-ct-jy-czzp-app-160 opt]# docker load -i oracle11g.tar
六、docker安装oracle11g
6.1启动镜像
[root@v-ct-jy-czzp-oth-02 ~]# docker run -d --name oracle -p 1521:1521 registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
6.2宿主机创建文件夹
[root@v-ct-jy-czzp-oth-02 ~]# mkdir -p /opt/oracle/
[root@v-ct-jy-czzp-oth-02 ~]# mkdir -p /opt/oracle/flash_recovery_area/
6.3拷贝数据库文件至宿主机
[root@v-ct-jy-czzp-oth-02 ~]# mkdir -p /opt/oracle/
[root@v-ct-jy-czzp-oth-02 ~]# mkdir -p /opt/oracle/flash_recovery_area/
[root@v-ct-jy-czzp-oth-02 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
149b2d1a4d64 registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g "/bin/sh -c '/home/o…" 26 seconds ago Up 20 seconds 0.0.0.0:1521->1521/tcp, :::1521->1521/tcp oracle
[root@v-ct-jy-czzp-oth-02 ~]# docker cp 149b2d1a4d64:/home/oracle/app/oracle/oradata /opt/oracle/oradata
[root@v-ct-jy-czzp-oth-02 ~]# docker cp 149b2d1a4d64:/home/oracle/app/oracle/flash_recovery_area/helowin /opt/oracle/flash_recovery_area/helowin
[root@v-ct-jy-czzp-oth-02 ~]# chmod -R 777 /opt/oracle/
6.4停止和删除容器
[root@v-ct-jy-czzp-oth-02 ~]# docker stop 149b2d1a4d64
149b2d1a4d64
[root@v-ct-jy-czzp-oth-02 ~]# docker rm 149b2d1a4d64
149b2d1a4d64
6.5启动docker容器(映射数据文件)
[root@v-ct-jy-czzp-oth-02 ~]# docker run -d --name oracle_llg -p 1521:1521 --privileged=true -v /opt/oracle/oradata:/home/oracle/app/oracle/oradata -v /opt/oracle/flash_recovery_area/helowin:/home/oracle/app/oracle/flash_recovery_area/helowin registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
6.6执行并完成基础设置
6.6.1 进入容器
[root@v-ct-jy-czzp-oth-02 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
640d85e4800c registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g "/bin/sh -c '/home/o…" 10 seconds ago Up 10 seconds 0.0.0.0:1521->1521/tcp, :::1521->1521/tcp oracle_llg
[root@v-ct-jy-czzp-oth-02 ~]# docker exec -it 640d85e4800c /bin/bash
6.6.2加载环境变量
[oracle@640d85e4800c /]$ source /home/oracle/.bash_profile
[oracle@640d85e4800c /]$ su root
Password:
#密码:helowin
[root@640d85e4800c /]# vi /etc/profile
#在末尾添加
export ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome_2
export ORACLE_SID=helowin
export PATH=$ORACLE_HOME/bin:$PATH
#刷新配置
[root@640d85e4800c /]# source /etc/profile
[root@640d85e4800c /]# su oracle
6.6.3登录
[oracle@47badc5bb7c4 /]$ sqlplus /nolog
SQL*Plus: Release 11.2.0.1.0 Production on Fri Mar 3 19:42:31 2023
Copyright (c) 1982, 2009, Oracle. All rights reserved.
SQL> connect /as sysdba
Connected.
6.6.4修改默认用户密码
SQL> alter user system identified by system;
User altered.
SQL> alter user sys identified by sys;
User altered.
SQL> ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;
Profile altered.
SQL>
6.6.5创建用户并指定表空间,授权
SQL> create user summer IDENTIFIED BY 123456 default tablespace test;
User created.
SQL> grant connect,resource,dba to summer;
Grant succeeded.
SQL>
名称 | 参数 |
---|---|
IP | 宿主机ip |
端口 | 1521 |
SID | helowin |
账号 | summer |
密码 | 123456 |
6.7 修改SID
原来SID为helowin,先需要修改为orcl
6.7.1关闭数据库
[oracle@47badc5bb7c4 /]$ sqlplus /nolog
SQL*Plus: Release 11.2.0.1.0 Production on Wed Nov 4 01:00:41 2020
Copyright (c) 1982, 2009, Oracle. All rights reserved.
SQL> connect /as sysdba
Connected.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
6.7.2修改环境变量
[oracle@47badc5bb7c4 /]$ vi /home/oracle/.bash_profile
#更改
ORACLE_SID=orcl;export ORACLE_SID
[oracle@47badc5bb7c4 /]$ cat /etc/oratab
orcl:/home/oracle/app/oracle/product/11.2.0/dbhome_2:Y
[oracle@47badc5bb7c4 /]$ cd $ORACLE_HOME/dbs
[oracle@47badc5bb7c4 dbs]$ ll
total 32
-rw-r-----. 1 oracle oinstall 3584 Jan 4 2016 123.sp
-rw-rw----. 1 oracle oinstall 1544 Nov 4 01:01 hc_helowin.dat
-rw-r--r--. 1 oracle oinstall 2851 May 16 2009 init.ora
-rw-r--r--. 1 oracle oinstall 1067 Jan 4 2016 inithelowin.ora
-rw-r-----. 1 oracle oinstall 24 Aug 23 2014 lkHELOWIN
-rw-r-----. 1 oracle oinstall 24 Dec 29 2015 lkORCL
-rw-r-----. 1 oracle oinstall 2048 Nov 4 00:33 orapwhelowin
-rw-r-----. 1 oracle oinstall 3584 Nov 4 00:25 spfilehelowin.ora
[oracle@39721ba8b1dd dbs]$ mv hc_helowin.dat hc_orcl.dat
[oracle@39721ba8b1dd dbs]$ mv orapwhelowin orapworcl
[oracle@39721ba8b1dd dbs]$ mv spfilehelowin.ora spfileorcl.ora
[oracle@39721ba8b1dd dbs]$ mv lkHELOWIN lkORCL
[oracle@39721ba8b1dd dbs]$ exit
exit
[root@47badc5bb7c4 /]# exit
exit
[oracle@47badc5bb7c4 /]$ exit
exit
[root@summer oracle]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
47badc5bb7c4 registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g "/bin/sh -c '/home/o…" 49 minutes ago Up 49 minutes 0.0.0.0:1521->1521/tcp oracle_llg
[root@summer oracle]# docker restart 39721ba8b1dd
47badc5bb7c4
文章来源:https://www.toymoban.com/news/detail-783893.html
总结
就此如何快速在内网环境搭建一个Oracle数据库搭建完成,感谢支持文章来源地址https://www.toymoban.com/news/detail-783893.html
到了这里,关于【Docker】如何在内网快速搭建docker并安装Oracle11g的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!