2-Oracle 23ai free-Podman&True Cache 基本操作

从23ai free container安装完毕后,进行基本的设置。
由于23ai free有硬件和数据量的使用限制2c/2g、数据12g,若超过此限制会报错 ORA-12954,不建议在生产环境中使用。
此系列为了测试新特性和对比19c与23ai的差异,等待Oracle Database 23ai ​OP版本(On-Premises,本地部署版)发布。

一、Podman自定义配置 oracle23ai

为了便于自定义配置,Oracle Database 容器提供了可以在启动容器时使用的配置参数。
以下是支持所有自定义配置的详细命令:
podman run --name <container name> \
-P | -p <host port>:1521 \
-e ORACLE_PWD=<your database passwords> \
-e ORACLE_CHARACTERSET=<your character set> \
-e ENABLE_ARCHIVELOG=true \
-e ENABLE_FORCE_LOGGING=true \
-v [<host mount point>:]/opt/oracle/oradata \
container-registry.oracle.com/database/free:latest

Parameters:
   --name:        The name of the container (default: auto generated)
   -P | -p:       The port mapping of the host port to the container port.
                  Only one port is exposed: 1521 (Oracle Listener)
   -e ORACLE_PWD: The Oracle Database SYS, SYSTEM and PDB_ADMIN password (default: auto generated)
   -e ORACLE_CHARACTERSET:
                  The character set to use when creating the database (default: AL32UTF8)
   -e ENABLE_ARCHIVELOG:
                  To enable archive log mode when creating the database (default: true)
   -e ENABLE_FORCE_LOGGING:
                  To enable force logging mode when creating the database (default: true)
   -v /opt/oracle/oradata
                  The data volume to use for the database.
                  Has to be writable by the Unix "oracle" (uid: 54321) user inside the container.
                  If omitted the database will not be persisted over container recreation.
   -v /opt/oracle/scripts/startup
                  Optional: A volume with custom scripts to be run after database startup.
                  For further details see the "Running scripts after setup and on startup" section below.
   -v /opt/oracle/scripts/setup
                  Optional: A volume with custom scripts to be run after database setup.
                  For further details see the "Running scripts after setup and on startup" section below.

支持的配置选项包括:
  • ORACLE_CHARACTERSET:此参数修改数据库的字符集。此参数为可选参数,默认值为 AL32UTF8。请注意,此参数仅在创建新数据库时设置字符集,即在运行镜像时使用 -v 选项挂载主机系统目录。
  • ORACLE_PWD:此参数修改用户的密码。该参数为可选参数,默认值为随机生成。注: 使用此选项会将密码公开为容器环境变量。因此,建议使用 Podman 密钥,如下:
  • SYS, SYSTEM and PDBADMIN
  • Podman Secrets 支持:仅当使用 Podman 运行时运行 Oracle Database 23ai Free 容器镜像时,才支持此选项。Podman 密钥是一种将文本字符串(如 ssh 密钥或密码)传递给容器的安全机制。要安全地为用户指定密码,请创建一个名为 的密钥和一个为密钥命名的密钥以加密密码。如下:
  • SYS, SYSTEM and PDBADMINoracle_pwdoracle_pwd_privkey
- Generate the private and public key files
  ```
  mkdir /opt/.secrets/
  cd /opt/.secrets
  openssl genrsa -out key.pem
  openssl rsa -in key.pem -out key.pub -pubout
  ```
- Create a text file with the unencrypted password
  Seed password and saving the /opt/.secrets/pwdfile.txt
  ```
  vi /opt/.secrets/pwdfile.txt
  ```
- Encrypt the password file using the private key generated above
  ```
  openssl pkeyutl -in /opt/.secrets/pwdfile.txt -out /opt/.secrets/pwdfile.enc -pubin -inkey /opt/.secrets/key.pub -encrypt
  rm -rf /opt/.secrets/pwdfile.txt
  ```
- Create podman secrets for the encrypted passwords and the public key generated above
  ```
  podman secret create oracle_pwd /opt/.secrets/pwdfile.enc
  podman secret create oracle_pwd_privkey /opt/.secrets/key.pem
  ```
- Pass the podman secrets to the container
  Pass the above created podman secrets `oracle_pwd` and `oracle_pwd_privkey` to the container with the `--secret` option
  ```
  podman run --name <container_name> --secret=oracle_pwd --secret=oracle_pwd_privkey container-registry.oracle.com/database/free:latest
  ```

  • 挂载 Podman 卷/主机目录以实现数据库持久性:要获得数据库持久性,可以在容器内的位置挂载命名的 Podman 卷或主机系统目录。这两个选项之间的区别如下:/opt/oracle/oradata
  • 如果 Podman 卷挂载到该位置,则该卷将预填充镜像中已存在的数据文件。在这种情况下,启动速度会非常快,类似于在没有挂载的情况下启动镜像。这些数据文件存在于镜像中,以便快速启动数据库。/opt/oracle/oradata
要将 podman 卷用于数据卷,命令如下:
    $ podman run -d --name oracle23ai \
      -v <OracleDBData>:/opt/oracle/oradata \
      container-registry.oracle.com/database/free:latest

  • 如果主机系统目录挂载到该位置,则可能会发生两种情况:/opt/oracle/oradata
  • 如果数据文件存在于正在挂载的主机系统目录中,则这些文件将覆盖 中存在的文件,并且数据库启动将非常快。/opt/oracle/oradata
  • 如果主机系统目录不包含数据文件,则存在的数据文件将被覆盖,并且将开始新的数据库设置。设置新数据库需要耗费时间。/opt/oracle/oradata
要将主机系统上的目录用于数据卷,命令如下:
    $ podman run -d --name oracle23ai \
      -v <writable_directory_path>:/opt/oracle/oradata \
      container-registry.oracle.com/database/free:latest

注意:清理挂载的主机目录可以通过更改为目录位置并执行,删除命令请注意文件路径 rm -rf XXX
  • ENABLE_ARCHIVELOG 和/或 ENABLE_FORCE_LOGGING:默认情况下,这些选项在预构建的数据库镜像中处于启用状态。要禁用这些选项,需要使用 SQLPlus 从数据库容器中执行相关的 SQL 命令。

1.1 更改 SYS 用户的默认密码

首次启动容器时,如果未使用 -e 选项提供密码,则会为数据库生成随机密码,
要更改这些帐户的密码,请使用命令运行在容器中找到的脚本。请注意,在运行脚本之前,容器必须处于运行状态。
podman execsetPassword.sh
比如:
podman exec oracle23ai ./setPassword.sh <your_password>

1.2 数据库警报日志

您可以使用以下命令访问数据库警报日志,其中容器的名称:oracle23ai
podman logs oracle23ai

1.3 连接到 Oracle Database Free 容器

在 Oracle Database 指示容器已启动,并且字段显示客户端应用程序可以连接到数据库之后。

podman stats

1.4 从容器内连接

可以通过使用以下命令之一从容器内运行 SQL*Plus 命令来连接到 Oracle Database:
podman exec -it oracle23ai sqlplus sys/<your_password>@FREE as sysdba
podman exec -it oracle23ai sqlplus system/<your_password>@FREE
podman exec -it oracle23ai sqlplus pdbadmin/<your_password>@FREEPDB1

1.5 从容器外部连接

默认情况下,Oracle Database 使用 Oracle 的 SQL*Net 协议为 Oracle 客户端连接公开端口 1521。SQL*Plus 或任何 Oracle Database 客户端软件可用于从容器外部连接到数据库。
要从容器外部进行连接,
通过运行以下命令来发现映射的端口:
podman port oracle23ai
要使用 SQL*Plus 从容器外部进行连接,请运行以下命令:
# To connect to the database at the CDB$ROOT level as sysdba:
sqlplus sys/<your password>@//localhost:<port mapped to 1521>/FREE as sysdba

# To connect as non sysdba at the CDB$ROOT level:
sqlplus system/<your password>@//localhost:<port mapped to 1521>/FREE

# To connect to the default Pluggable Database (PDB) within the FREE Database:
sqlplus pdbadmin/<your password>@//localhost:<port mapped to 1521>/FREEPDB1

1.5 读取持久数据后的数据库

如果使用安装在容器内某个位置的主机系统目录启动数据库,挂载 Podman 卷/主机目录以实现数据库持久性后,则即使在容器销毁后,数据文件仍保持持久性。可以通过再次启用image后,读取系统目录来启动另一个具有相同数据文件的容器。/opt/oracle/oradata
要在主机系统上为数据卷重复使用此目录,运行以下命令:
podman run -d --name oracle23ai -v \
                     <writable_host_directory_path>:/opt/oracle/oradata \
                     container-registry.oracle.com/database/free:latest

1.6 在设置后和启动时运行脚本

容器镜像可以配置为在设置后和启动时运行脚本。目前,支持扩展。对于安装后脚本,启动后脚本挂载卷以在此目录中包含脚本。
.sh.sql/opt/oracle/scripts/setup/opt/oracle/scripts/startup
设置或启动数据库后,这些文件夹中的脚本将针对容器中的数据库运行。SQL 脚本作为 SYSDBA 运行,shell 脚本作为当前用户运行。为了确保脚本的运行顺序正确,Oracle 建议在脚本前面加上一个数字。
养成良好的命名习惯。01_users.sql02_permissions.sql
注意:安装脚本不会在 Free 和 Free Lite 镜像中运行,因为两者都带有预构建的数据库。
如果提供了主机挂载点(空目录),则将启动新的数据库设置并运行设置脚本。
以下将本地目录挂载到 ,自定义启动脚本:
/home/oracle/myScripts/opt/oracle/scripts/startup
podman run -d --name oracle23ai -v \
                     /home/oracle/myScripts:/opt/oracle/scripts/startup \
                     container-registry.oracle.com/database/free:latest

二、Oracle True Cache

Oracle True Cache 是适用于 Oracle 数据库的内存中、一致且自动管理的缓存。
此功能做测试的重点功能,后续将持续测试。

2.1 设置用于主数据库和 True Cache Container 之间通信的网络

Oracle Database Free True Cache 容器(True Cache 容器)和 Oracle Database Free 主数据库容器(主数据库容器)必须位于同一 podman 网络上才能相互通信。使用以下命令设置用于容器间通信的 podman 网络,该命令将创建一个网桥连接,从而在同一主机上的容器之间启用通信。

podman network create tc_net
通过运行以下命令获取分配给上述网络的默认子网:
podman inspect tc_net | grep -iw 'subnet'
从前面的子网中选择任意两个 IP 地址,并为主数据库容器分配一个 IP 地址(例如 PRI_DB_FREE_IP),另一个分配给 True Cache 容器(例如 TRU_CC_FREE_IP)。
对于跨主机的通信,根据创建 macvlan 或 ipvlan 连接。
使用主数据库容器和 True Cache 容器的 podman run 命令的 --net 选项指定前面的 podman 网络,如以下部分所示。

2.3 在容器中运行 Oracle Database Free True Cache

使用命令启动 Oracle Database Free 主数据库容器,如下:
      podman run -td --name pri-db-free \
      --hostname pri-db-free \
      --net=tc_net \
      --ip <PRI_DB_FREE_IP> \
      -p :1521 \
      --secret=oracle_pwd \
      --secret=oracle_pwd_privkey \
      --add-host="tru-cc-free:<TRU_CC_FREE_IP>" \
      -e ENABLE_ARCHIVELOG=true \
      -e ENABLE_FORCE_LOGGING=true \
      -v [<host mount point>:]/opt/oracle/oradata \
      container-registry.oracle.com/database/free:latest

确保主数据库容器已启动并正在运行,并且处于正常状态。
使用以下命令启动 Oracle Database Free True Cache 容器,如下:
    podman run -td --name tru-cc-free \
    --hostname tru-cc-free \
    --net=tc_net \
    --ip <TRU_CC_FREE_IP> \
    -p :1521 \
    --secret=oracle_pwd \
    --secret=oracle_pwd_privkey \
    --add-host="pri-db-free:<PRI_DB_FREE_IP>" \
    -e TRUE_CACHE=true \
    -e PRIMARY_DB_CONN_STR=<PRI_DB_FREE_IP>:1521/FREE \
    -e PDB_TC_SVCS="FREEPDB1:sales1:sales1_tc;FREEPDB1:sales2:sales2_tc;FREEPDB1:sales3:sales3_tc;FREEPDB1:sales4:sales4_tc" \
    -v [<host mount point>:]/opt/oracle/oradata \
    container-registry.oracle.com/database/free:latest

注意:在上面的命令中,使用字符串 “FREEPDB1:sales1:sales1_tc;FREEPDB1:销售2:sales2_tc;FREEPDB1:销售额3:sales3_tc;FREEPDB1:销售额4:sales4_tc” 字符串由格式中的多个条目组成,这些条目用 “;” 分隔。::

三、使用 Lite 镜像

虽然Lite镜像与完整镜像一样,Oracle Database 23ai Free Lite Container 镜像也包含一个预构建的数据库,因此启动时间非常快。
Oracle Database 23ai Free Lite 容器,简化太多功能此处不做测试。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值