CentOS 7.7 1908 使用 Docker 中的数据库增加监听端口与端口映射

  1. 查看 docker 容器目录
    docker info | grep 'Docker Root Dir'
    运行结果:
    [root@localhost ~]# docker info | grep 'Docker Root Dir'
      WARNING: You're not using the default seccomp profile
    WARNING: bridge-nf-call-iptables is disabled
    WARNING: bridge-nf-call-ip6tables is disabled
    Docker Root Dir: /data/docker
    [root@localhost ~]# 
    安装目录为:/data/docker
     
  2. 查看已创建的容器:
    docker ps -a
    运行结果:
    [root@localhost ~]# docker ps -a
    CONTAINER ID        IMAGE                                                  COMMAND                  CREATED             STATUS              PORTS                                              NAMES
    a89bffd7afe8        registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g   "/bin/sh -c '/home..."   3 days ago          Up 8 minutes        0.0.0.0:11521->1521/tcp                            oracle_11g
    [root@localhost ~]# 
    
    oracle_11g 唯一ID为:a89bffd7afe8,唯一ID是安装目录的前 12 位
     
  3. 进入 oracle_11g 安装目录:
    docker 容器在安装目录中的 containers 文件夹下:
    根据上述条件,进入安装目录:
    cd /data/docker/containers/a89bffd7afe8ed7168bc1ba641f7327ba1f5da662563ba335f69bad8dadee038/
  4. 查看 vim 版本:
    vim -v
    若未安装 vim,请运行命令安装:
    yum -y install vim
  5. 通知 docker:
    systemctl stop docker
  6. 编辑 hostconfig.json 文件:
    vim hostconfig.json
    输入命令,回车进行 JSON 格式化:
    :%!python -m json.tool
    找到:
    "PortBindings": {
    	"1521/tcp": [
    		{
    			"HostIp": "",
    			"HostPort": "11521"
    		}
    	]
    }
    新增内部端口 1158,外部端口 11158:
    "PortBindings": {
    	"1521/tcp": [
    		{
    			"HostIp": "",
    			"HostPort": "11521"
    		}
    	],
    	"1522/tcp": [
    		{
    			"HostIp": "",
    			"HostPort": "11522"
    		}
    	]
    }
  7. 编辑 config.v2.json 文件:
    vim config.v2.json
    输入命令,回车进行 JSON 格式化:
    :%!python -m json.tool
    在 "ExposedPorts" 中增加内部端口 1522:
    "ExposedPorts": {
    	"1521/tcp": {},
    	"1522/tcp": {}
    },
  8. 启动 docker:
    systemctl start docker
  9. 查看已创建的容器:
    docker ps -a
    运行结果:
    [root@localhost a89bffd7afe8ed7168bc1ba641f7327ba1f5da662563ba335f69bad8dadee038]# docker ps -a
    CONTAINER ID        IMAGE                                                  COMMAND                  CREATED             STATUS              PORTS                                              NAMES
    a89bffd7afe8        registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g   "/bin/sh -c '/home..."   3 days ago          Up 4 seconds        0.0.0.0:11521->1521/tcp, 0.0.0.0:11522->1522/tcp   oracle_11g
    [root@localhost a89bffd7afe8ed7168bc1ba641f7327ba1f5da662563ba335f69bad8dadee038]#
  10. 开通本机(非 docker)11522端口:
    firewall-cmd --zone=public --add-port=11522/tcp --permanent
    firewall-cmd --reload
    firewall-cmd --list-all
  11. 进入 oracle11g:
    docker exec -it oracle_11g bash
    执行结果:
    [root@localhost a89bffd7afe8ed7168bc1ba641f7327ba1f5da662563ba335f69bad8dadee038]# docker exec -it oracle_11g bash
    [oracle@a89bffd7afe8 /]$ 
  12. 编辑 tnsnames.ora:
    vi /home/oracle/app/oracle/product/11.2.0/dbhome_2/network/admin/tnsnames.ora
    由:
    LISTENER =
      (DESCRIPTION_LIST =
        (DESCRIPTION =
          (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
          (ADDRESS = (PROTOCOL = TCP)(HOST = )(PORT = 1521))
        )
      )
    
    ADR_BASE_LISTENER = /home/oracle/app/oracle
    
    新增端口 1522:
    LISTENER =
      (DESCRIPTION_LIST =
        (DESCRIPTION =
          (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
          (ADDRESS = (PROTOCOL = TCP)(HOST = )(PORT = 1521))
          (ADDRESS = (PROTOCOL = TCP)(HOST = )(PORT = 1522))
        )
      )
    
    ADR_BASE_LISTENER = /home/oracle/app/oracle
    
  13. 重启监听:
    停止监听:
    lsnrctl stop
    运行如下:
    [oracle@a89bffd7afe8 /]$ lsnrctl stop
    
    LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 14-JUN-2020 22:56:27
    
    Copyright (c) 1991, 2009, Oracle.  All rights reserved.
    
    Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
    The command completed successfully
    [oracle@a89bffd7afe8 /]$
    启动监听:
    lsnrctl start
    运行如下:
    [oracle@a89bffd7afe8 /]$ lsnrctl start
    
    LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 14-JUN-2020 22:56:35
    
    Copyright (c) 1991, 2009, Oracle.  All rights reserved.
    
    Starting /home/oracle/app/oracle/product/11.2.0/dbhome_2/bin/tnslsnr: please wait...
    
    TNSLSNR for Linux: Version 11.2.0.1.0 - Production
    System parameter file is /home/oracle/app/oracle/product/11.2.0/dbhome_2/network/admin/listener.ora
    Log messages written to /home/oracle/app/oracle/diag/tnslsnr/a89bffd7afe8/listener/alert/log.xml
    Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
    Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=a89bffd7afe8)(PORT=1521)))
    Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=a89bffd7afe8)(PORT=1522)))
    
    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                14-JUN-2020 22:56:35
    Uptime                    0 days 0 hr. 0 min. 0 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/a89bffd7afe8/listener/alert/log.xml
    Listening Endpoints Summary...
      (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
      (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=a89bffd7afe8)(PORT=1521)))
      (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=a89bffd7afe8)(PORT=1522)))
    The listener supports no services
    The command completed successfully
    [oracle@a89bffd7afe8 /]$
  14. 重启数据库:
    使用 dba 登录数据库:
    sqlplus / as sysdba
    运行如下:
    [oracle@a89bffd7afe8 /]$ sqlplus / as sysdba
    
    SQL*Plus: Release 11.2.0.1.0 Production on Sun Jun 14 22:57:40 2020
    
    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
    
    SQL>
    停止数据库:
    shutdown immediate;
    运行如下:
    SQL> shutdown immediate;
    Database closed.
    Database dismounted.
    ORACLE instance shut down.
    SQL>
    启动数据库:
    startup;
    运行如下:
    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> 
  15. 使用 11521 连接:

     
  16. 使用 11522 连接:


     
  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: Age of Ai 设计师:meimeiellie 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值