使用Oracle Docker Container 21c 搭建Oracle服务器

why

Using an Oracle Docker container is much easier than a traditional stand-alone installation.

Meanwhile, starting with Oracle Database 21c, the only supported architecture is the multitenant container database, which significantly enhances data accessibility and portability. This new architecture introduces 2 important concepts that are crucial for efficient database management: multitenant container database (CDB) and pluggable databases (PDBs).

For more information, please refer to https://developer.oracle.com/en/learn/technical-articles/what-is-a-container-database.

what

In this article, I will introduce how to setup an Oracle server by creating and running the Oracle 21c docker container.

I will just focus on providing all the necessary steps, rather than introduce all the concepts and commands.

In my case, I need to prepare an Oracle Server with the following information:

                Oracle 

  • Host Name: test.mycloud.com
  • Port: 1521
  • Oracle Network Service Name: dds
  • Database Schema Name for Insurance DDS:  dds
  • User ID: ddsuser
  • Password: Go4thsas

                Host (test.mycloud.com)

  • OS Version
    • Red Hat Enterprise Linux release 8.6 (Ootpa)
  • Docker Version:
    • podman version 4.9.4-dev
    • Note: Podman has replaced Docker on redhat8.
    • Note: most users like simply alias Docker to Podman (“alias docker=podman” )
  • In my host, I need to use root user to run all the docker commands.

How

  1. Docker Hub – Authentication
    1. Go to the Oracle Container Registry page: https://container-registry.oracle.com
    2. Click “Sign In” on the top right corner of the page, and log on with your personal Oracle account.
    3. Enter the “Database” repositories.
    4.  Click “enterprise” repository.
    5.  On the right panel, choose the language to accept the Oracle Standard Terms and Restrictions.0ba592b820fa4d24b2c973bf8af4762b.png
    6.  Click your account name on the top right. Choose “Auth Token” from the menu.
    7.  On the Auth Tokens page, click Generate Token.
      •  If it displays that the token is already existed, then Delete Secret Key at first and generate it again.
    8.  Copy the token and save it somewhere.
  2.  Pull the Docker Image
    1. Once we have the credentials, execute the following command to login on the linux host. Use the token saved at step 1.h as the password.
      docker login container-registry.oracle.com 
    2. Pull the docker image
      docker pull container-registry.oracle.com/database/enterprise:latest
  3.  Create and run the container
    docker run -d –name ddscdb -p 1521:1521 -p 5500:5500 -e ORACLE_SID=ddscdb -e ORACLE_PWD=Go4thsas -e ORACLE_PDB=dds -v /install/oradata:/opt/oracle/oradata container-registry.oracle.com/database/enterprise:21.3.0.0
  4.  Configure inside the container
    1.  Enter the container
      docker exec -it ddscdb sqlplus sys/Go4thsas@ddscdb as sysdba
    2.  Swith to the pdb container
      SQL>alter session set container=dds;
    3. Create user and assign privileges
      SQL>create user ddsuser identified by Go4thsas account unlock; 

      SQL>grant all privileges to ddsuser;

      SQL>exit

    4. Change to use root to enter it to install edit tool
      docker exec -it -u root ddscdb bash 

      bash-4.2# yum install –y vim 

      bash-4.2# exit 

    5. Change to use default user to add tnsnames.ora for the oracle container
      docker exec -it ddscdb bash 

      bash-4.2$ cd $ORACLE_HOME/network/admin 

      bash-4.2$ vim tnsnames.ora

      DDSCDB=localhost:1521/DDSCDB

      DDS=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = DDS)))

    6. Restart listener
      bash-4.2$ lsnrctl stop

      bash-4.2$ lsnrctl start

    7. Check the status of the listener
      bash-4.2$ lsnrctl status

      LSNRCTL for Linux: Version 21.0.0.0.0 – Production on 05-JUN-2024 10:03:57

      Copyright (c) 1991, 2021, Oracle.  All rights reserved.

      Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))

      STATUS of the LISTENER

      ————————

      Alias                     LISTENER

      Version                   TNSLSNR for Linux: Version 21.0.0.0.0 – Production

      Start Date                05-JUN-2024 06:46:28

      Uptime                    0 days 3 hr. 17 min. 29 sec

      Trace Level               off

      Security                  ON: Local OS Authentication

      SNMP                      OFF

      Listener Parameter File   /opt/oracle/homes/OraDB21Home1/network/admin/listener.ora

      Listener Log File         /opt/oracle/diag/tnslsnr/f77014ebf49c/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=f77014ebf49c)(PORT=5500))(Security=(my_wallet_directory=/opt/oracle/admin/DDSCDB/xdb_wallet))(Presentation=HTTP)(Session=RAW))

      Services Summary…

      Service “19f79b261d640cf3e0630600580a3d5a” has 1 instance(s).

        Instance “DDSCDB”, status READY, has 1 handler(s) for this service…

      Service “DDSCDB” has 1 instance(s).

        Instance “DDSCDB”, status READY, has 1 handler(s) for this service…

      Service “DDSCDBXDB” has 1 instance(s).

        Instance “DDSCDB”, status READY, has 1 handler(s) for this service…

      Service “dds” has 1 instance(s).

        Instance “DDSCDB”, status READY, has 1 handler(s) for this service…

      The command completed successfully

    8.  Verify the connection

      docker exec -it ddscdb sqlplus ddsuser/Go4thsas@dds

      SQL*Plus: Release 21.0.0.0.0 – Production on Wed Jun 5 10:06:55 2024

      Version 21.3.0.0.0

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

      Last Successful login time: Wed Jun 05 2024 06:47:11 +00:00

      Connected to:

      Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 – Production

      Version 21.3.0.0.0

      SQL>

  5.  Configure outside the container
    1. Install Oracle Instant Client Using RPMs
      1. Download rpms at Instant Client for Linux x86-64 (64-bit)
      2.  Install them
        dnf install oracle-instantclient-basic-21.14.0.0.0-1.el8.x86_64.rpm

        dnf install oracle-instantclient-sqlplus-21.14.0.0.0-1.el8.x86_64.rpm

    2.  Add the environment variables for the SAS install user
      cd /install/users/cfgsas1

      vim .bashrc

      export ORACLE_HOME=/usr/lib/oracle/21/client64/lib 

      export LD_LIBRARY_PATH=$ORACLE_HOME:$LD_LIBRARY_PATH 

      export PATH=/usr/lib/oracle/21/client64/bin:$PATH

      source .bashrc

    3.  Add the tnsnames.ora
      cd $ORACLE_HOME/network/admin 

      vim tnsnames.ora

      DDSCDB=localhost:1521/DDSCDB

      DDS=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = DDS)))

  6.  Test the connection outside the container

    sqlplus ddsuser/Go4thsas@dds

    SQL*Plus: Release 21.0.0.0.0 – Production on Wed Jun 5 10:06:55 2024

    Version 21.14.0.0.0

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

    Last Successful login time: Wed Jun 05 2024 06:47:11 +00:00

    Connected to:

    Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 – Production

    Version 21.3.0.0.0

    SQL>

Done! 

Reference

[1] Oracle Help Center: Oracle CDBs and PDBs

[2] Oracle Help Center: Oracle 21c Multitenant Administration Guide

[3] Oracle Help Center: How to Install Oracle Database 21c on Docker

[4] Oracle Container Registry: Oracle Database Server Release 21c (21.3.0.0) Docker Image Documentation

[5] Medium Post: Run Oracle Database 21c in Docker

[6] Oracle Help Center: Oracle Cloud Infrastructure Documentation – Getting an Auth Token

[7] Oracle Help Center: Installing Oracle Instant Client Using RPMs

[8] Confluence: Install Oracle 19c database and SQL Server

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值