Docker安装Oracle_11g数据库并配置

一文搞懂Docker的安装
h:ttps://blog.csdn.net/qq_44895681/article/details/105540702

环境

CentOS 7.5

Docker 20.10.2

Oracle_11g

安装Oracle数据库

1.搜索oracle镜像

docker search oracle

[root@localhost ~]# docker search oracle
NAME                                  DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
oraclelinux                           Official Docker builds of Oracle Linux.         731       [OK]
jaspeen/oracle-11g                    Docker image for Oracle 11g database            169                  [OK]
oracleinanutshell/oracle-xe-11g                                                       138
wnameless/oracle-xe-11g-r2            Oracle Express Edition 11g Release 2 on Ubun…   58
absolutapps/oracle-12c-ee             Oracle 12c EE image with web management cons…   46
araczkowski/oracle-apex-ords          Oracle Express Edition 11g Release 2 on Ubun…   30                   [OK]
truevoly/oracle-12c                   Copy of sath89/oracle-12c image (https://git…   27
bofm/oracle12c                        Docker image for Oracle Database                24                   [OK]
datagrip/oracle                       Oracle 11.2 & 12.1.0.2-se2 & 11.2.0.2-xe        20                   [OK]
quillbuilduser/oracle-18-xe           Oracle 18c XE Image for Quill Testing Purpos…   20
openweb/oracle-tomcat                 A fork off of Official tomcat image with Ora…   8                    [OK]
binarybabel/oracle-jdk                Oracle JDKs (Alpine, CentOS, Debian) rebuilt…   5                    [OK]
iamseth/oracledb_exporter             A Prometheus exporter for Oracle modeled aft…   3
18fgsa/oracle-client                  Hosted version of the Oracle Container Image…   2
paulosalgado/oracle-java8-ubuntu-16   Oracle Java 8 on Ubuntu 16.04 LTS.              2                    [OK]
softwareplant/oracle                  oracle db                                       2                    [OK]
arm64v8/oraclelinux                   Official Docker builds of Oracle Linux.         1
roboxes/oracle7                       A generic Oracle Linux 7 base image.            1
publicisworldwide/oracle-core         This is the core image based on Oracle Linux…   1                    [OK]
amd64/oraclelinux                     Official Docker builds of Oracle Linux.         1
toolsmiths/oracle7-test                                                               0
bitnami/oraclelinux-extras            Oracle Linux base images                        0                    [OK]
bitnami/oraclelinux-runtimes          Oracle Linux runtime-optimized images           0                    [OK]
pivotaldata/oracle7-test              Oracle Enterprise Linux (OEL) image for GPDB…   0
gizmotronic/oracle-java               Ubuntu 16.04 image with Oracle Java             0                    [OK]

2.拉取阿里云oracle镜像

docker pull registry.aliyuncs.com/helowin/oracle_11g 或者 docker pull registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g

[root@localhost ~]# docker pull registry.aliyuncs.com/helowin/oracle_11g
Using default tag: latest
latest: Pulling from helowin/oracle_11g
ed5542b8e0e1: Already exists
a3ed95caeb02: Already exists
1e8f80d0799e: Already exists
Digest: sha256:4c12b98372dfcbaafcd9564a37c8d91456090a5c6fb07a4ec18270c9d9ef9726
Status: Image is up to date for registry.aliyuncs.com/helowin/oracle_11g:latest
registry.aliyuncs.com/helowin/oracle_11g:latest

3.查看镜像拉取情况

docker iamges

[root@localhost ~]# docker images
REPOSITORY                                             TAG          IMAGE ID       CREATED       SIZE
...
registry.aliyuncs.com/helowin/oracle_11g               latest       3fa112fd3642   5 years ago   6.85GB

4.创建并启动oracle容器

持久化启动方式:

docker run  -itd -p 1521:1521 --name oracle_11g --restart=always -v /mnt/oracle_data/app:/opt/oracle/app -v /mnt/oracle_data/dpdump:/opt/oracle/dpdump  -v  /mnt/oracle_data/oraInventory:/opt/oracle/oraInventory registry.aliyuncs.com/helowin/oracle_11g

5.查看创建的oracle本地数据映射目录

在创建启动oracle容器的时候会自动在宿主机上创建相关的数据映射目录。

[root@localhost ~]# ll /mnt/oracle_data/
总用量 0
drwxr-xr-x. 2 root root 6 29 23:12 app
drwxr-xr-x. 2 root root 6 29 23:12 dpdump
drwxr-xr-x. 2 root root 6 29 23:12 oraInventory

6.查看进程与启动状态

[root@localhost ~]# netstat -antulp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:1521            0.0.0.0:*               LISTEN      35497/docker-proxy
......

[root@localhost ~]# ss -antulp | grep :1521
tcp    LISTEN     0      128       *:1521                  *:*                   users:(("docker-proxy",pid=35497,fd=4))

[root@localhost ~]# docker ps
CONTAINER ID   IMAGE                                      COMMAND                  CREATED        STATUS        PORTS                    NAMES
3edfba76f476   registry.aliyuncs.com/helowin/oracle_11g   "/bin/sh -c '/home/o…"   42 hours ago   Up 42 hours   0.0.0.0:1521->1521/tcp   oracle_11g

7.以退出不中断容器的方式进入容器

[root@localhost ~]# docker exec -it oracle_11g bash
[oracle@3edfba76f476 /]$

8.配置容器内环境变量

[root@localhost ~]# docker exec -it oracle_11g bash

1.切换为root用户
      # 密码默认为 helowin
[oracle@3edfba76f476 /]$ su root         
Password:                                

2.添加环境变量
[root@3edfba76f476 /]# vi /etc/profile      
...
     61 export ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome_2
     63 export ORACLE_SID=helowin
     65 export PATH=$ORACLE_HOME/bin:$PATH
...

3.使配置生效
[root@3edfba76f476 /]# source  /etc/profile

4.创建软链接
[root@3edfba76f476 /]# ln -s $ORACLE_HOME/bin/sqlplus /usr/bin

9.操作oracle

1.切换回oracle用户
[root@3edfba76f476 /]# su - oracle

2.登录sqlplus
[oracle@3edfba76f476 ~]$ sqlplus /nolog

SQL*Plus: Release 11.2.0.1.0 Production on Sat Jan 30 16:32:18 2021

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

SQL> conn /as sysdba;
Connected.

3.修改sys、system用户密码
SQL> alter user system identified by 123456;

SQL> alter user sys identified by 123456;

SQL> alter profile default limit PASSWORD_LIFE_TIME UNLIMITED;

4.创建用户
SQL> create user root identified by 123456;

SQL> grant connect,resource,dba to root;

SQL> show user;      # 查看当前用户
USER is "SYS"

SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

10.查看oracle实例状态

lsnrctl status

[oracle@434bcfed5c5d ~]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 09-FEB-2022 23:37:27

Copyright (c) 1991, 2009, 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.1.0 - Production
Start Date                09-FEB-2022 23:28:42
Uptime                    0 days 0 hr. 8 min. 45 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /home/oracle/app/oracle/product/11.2.0/dbhome_2/network/admin/listener.ora
Listener Log File         /home/oracle/app/oracle/diag/tnslsnr/434bcfed5c5d/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=434bcfed5c5d)(PORT=1521)))
Services Summary...
Service "helowin" has 1 instance(s).
  Instance "helowin", status READY, has 1 handler(s) for this service...
Service "helowinXDB" has 1 instance(s).
  Instance "helowin", status READY, has 1 handler(s) for this service...
The command completed successfully

注意:外部工具连接数据库时,需要配置开放防火墙相应端口。若是阿里云,则需要开放安全组。

11.使用工具连接oracle容器
Docker安装Oracle_11g数据库并配置_第1张图片
Docker安装Oracle_11g数据库并配置_第2张图片
配置好的oracle容器可以commit成新的镜像,方便以后直接启动运行;也可以把commit的新镜像save导出,方便其他机器load导入镜像直接使用!

↓↓↓↓↓↓

最近刚申请了个微信公众号,上面也会分享一些运维知识,大家点点发财手关注一波,感谢大家。 【原创公众号】:非著名运维 【福利】:公众号回复 “资料” 送运维自学资料大礼包哦!
在这里插入图片描述

你可能感兴趣的:(企业实战,数据库,Docker,oracle,数据库,docker)