2022年11月22日火曜日

Oracle APEXの環境作成(6) - Oracle REST Data Servicesのインストール

Oracle REST Data Services(以下ORDS)をインストールします。

ORDSは、バージョン22にて設定ファイルの構成が大きく変更されました。また、22.3ではORDSのインストール先がCDBであれば、デフォルトでPluggable Mappingの設定を行います。

過去の手順ではPluggable MappingでORDSを構成していました。テスト環境ではPDBを作成するたびにORDSの構成を変更せずに済むため便利なのですが、本番環境には推奨できません。そのため、ORDSのインストールにPDBを指定するように手順を変えています。

以下のインストール手順は、ORDS 23.1以降を対象にしています。


firewalldの構成



ユーザーrootにて仮想マシンにログインし、firewalldを構成します。

ORDSは一般ユーザーの権限で動作させるため、HTTPやHTTPSのポート(80および443)の接続を待ち受けることはできません。代わりにポート8080と8443を使用します。firewalldではHTTP(ポート80)の接続をポート8080、HTTPS(ポート443)の接続をポート8443へ転送します。また、HTTPとHTTPSへの接続を許可します。

firewalldを構成する一連のコマンドは以下になります。

firewall-cmd --add-service=https
firewall-cmd --add-service=http
firewall-cmd --add-forward-port=port=443:proto=tcp:toport=8443
firewall-cmd --add-forward-port=port=80:proto=tcp:toport=8080
firewall-cmd --runtime-to-permanent
firewall-cmd --reload
firewall-cmd --list-all

ユーザーrootで、上記のコマンドを実行します。

[root@localhost ~]# firewall-cmd --add-service=https

success

[root@localhost ~]# firewall-cmd --add-service=http

success

[root@localhost ~]# firewall-cmd --add-forward-port=port=443:proto=tcp:toport=8443

success

[root@localhost ~]# firewall-cmd --add-forward-port=port=80:proto=tcp:toport=8080

success

[root@localhost ~]# firewall-cmd --runtime-to-permanent

success

[root@localhost ~]# firewall-cmd --reload

success

[root@localhost ~]# firewall-cmd --list-all

public (active)

  target: default

  icmp-block-inversion: no

  interfaces: enp0s3

  sources: 

  services: cockpit dhcpv6-client http https ssh

  ports: 

  protocols: 

  forward: no

  masquerade: no

  forward-ports: 

port=443:proto=tcp:toport=8443:toaddr=

port=80:proto=tcp:toport=8080:toaddr=

  source-ports: 

  icmp-blocks: 

  rich rules: 

[root@localhost ~]# 


以上でfirewalldの設定は完了です。


Java Development Kitのインストール



ORDSはJavaで書かれたアプリケーションです。使用するJDKは、Oracle JDKを想定しています。不具合なのでSRを上げる場合はOracle JDKで再現することを確認する必要がありますが、今回のような無料の環境での利用であれば、OpenJDKやAmazon Correttoを使用することもできます。

サポートしているJDKのバージョンは11または17です。今回はOracle JDK 17を使用してORDSを動かします。Oracle REST Data Services 23.3に追加されたGraphQLのサポートを有効にするには、通常のJDKではなくGraalVMを使う必要があります。

Oracle JDKをダウンロードします。

Oracle Javaのページを開き、Download Javaをクリックしてダウンロード・ページに移動します。


JDK 17およびLinuxを選択します。

インストールに使用するパッケージはx64 RPM Packageです。ダウンロード・リンクからも分かるように、このRPMも仮想マシンから直接取得することができます。
https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.rpm

2023年11月15日現在、17.0.9がJDK 17の最新バージョンです。


ユーザーrootにて仮想マシンにログインし、curlコマンドでJDK17のRPMをダウンロードします。

curl -OL https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.rpm

[root@localhost ~]# curl -OL https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.rpm

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed

100  173M  100  173M    0     0  10.5M      0  0:00:16  0:00:16 --:--:-- 10.8M

[root@localhost ~]# 


ダウンロードしたRPMをインストールします。

dnf -y localinstall jdk-17_linux-x64_bin.rpm

[root@localhost ~]# dnf -y localinstall jdk-17_linux-x64_bin.rpm

Failed to set locale, defaulting to C.UTF-8

Last metadata expiration check: 0:53:37 ago on Wed Nov 15 11:31:17 2023.

Dependencies resolved.

================================================================================

 Package       Architecture  Version                  Repository           Size

================================================================================

Installing:

 jdk-17        x86_64        2000:17.0.9-11           @commandline        174 M


Transaction Summary

================================================================================

Install  1 Package


Total size: 174 M

Installed size: 303 M

Downloading Packages:

Running transaction check

Transaction check succeeded.

Running transaction test

Transaction test succeeded.

Running transaction

  Preparing        :                                                        1/1 

  Installing       : jdk-17-2000:17.0.9-11.x86_64                           1/1 

  Running scriptlet: jdk-17-2000:17.0.9-11.x86_64                           1/1 

  Verifying        : jdk-17-2000:17.0.9-11.x86_64                           1/1 


Installed:

  jdk-17-2000:17.0.9-11.x86_64                                                  


Complete!

[root@localhost ~]# 


JDKのインストールが完了したら、Javaのバージョンを確認します。

java -version

[root@localhost ~]# java -version

java version "17.0.9" 2023-10-17 LTS

Java(TM) SE Runtime Environment (build 17.0.9+11-LTS-201)

Java HotSpot(TM) 64-Bit Server VM (build 17.0.9+11-LTS-201, mixed mode, sharing)

[root@localhost ~]# 


JDKのダウンロード・ページに書かれていたバージョンと一致していることを確認します。今回の例では、17.0.9になります。


Oracle REST Data Servicesのインストール



ORDSのインストールに使用するメディアは、RPMとZIPの2種類から選ぶことができます。RedHat Enterprise Linuxの系列であれば、RPMを選択するのが良いでしょう。

RPMは以下のYumリポジトリからインストールします。ORDSとSQLclのPRMパッケージが含まれています。
https://yum.oracle.com/repo/OracleLinux/OL8/oracle/software/x86_64/


ZIPファイルは、Oracle REST Data Servicesのダウンロード・ページよりダウンロードできます。
https://www.oracle.com/database/sqldeveloper/technologies/db-actions/download/


最新のORDSのZIPファイルは、Use this link for the latest version updateよりダウンロードできます。このリンクはバージョンによらず、以下になります。
https://download.oracle.com/otn_software/java/ords/ords-latest.zip

今回はRPMをインストールします。以下のコマンドを実行します。

dnf -y --repofrompath ol8_oracle_software,http://yum.oracle.com/repo/OracleLinux/OL8/oracle/software/x86_64 install ords

[root@localhost ~]# dnf -y --repofrompath ol8_oracle_software,http://yum.oracle.com/repo/OracleLinux/OL8/oracle/software/x86_64 install ords

Failed to set locale, defaulting to C.UTF-8

Added ol8_oracle_software repo from http://yum.oracle.com/repo/OracleLinux/OL8/oracle/software/x86_64

ol8_oracle_software                              40 kB/s | 105 kB     00:02    

Last metadata expiration check: 0:00:01 ago on Wed Nov 15 12:26:59 2023.

Dependencies resolved.

================================================================================

 Package    Architecture Version                Repository                 Size

================================================================================

Installing:

 ords       noarch       23.3.0-10.el8          ol8_oracle_software       107 M

Installing dependencies:

 lsof       x86_64       4.93.2-1.el8           ol8_baseos_latest         253 k


Transaction Summary

================================================================================

Install  2 Packages


Total download size: 108 M

Installed size: 113 M

Downloading Packages:

(1/2): lsof-4.93.2-1.el8.x86_64.rpm             376 kB/s | 253 kB     00:00    

(2/2): ords-23.3.0-10.el8.noarch.rpm            3.2 MB/s | 107 MB     00:33    

--------------------------------------------------------------------------------

Total                                           3.2 MB/s | 108 MB     00:33     

Running transaction check

Transaction check succeeded.

Running transaction test

Transaction test succeeded.

Running transaction

  Preparing        :                                                        1/1 

  Installing       : lsof-4.93.2-1.el8.x86_64                               1/2 

  Running scriptlet: ords-23.3.0-10.el8.noarch                              2/2 

  Installing       : ords-23.3.0-10.el8.noarch                              2/2 

  Running scriptlet: ords-23.3.0-10.el8.noarch                              2/2 

INFO: Before starting ORDS service, run the below command as user oracle:

         ords --config /etc/ords/config install

INFO: To enable the ORDS service during startup, run the below command:

         sudo  systemctl enable ords


  Verifying        : lsof-4.93.2-1.el8.x86_64                               1/2 

  Verifying        : ords-23.3.0-10.el8.noarch                              2/2 


Installed:

  lsof-4.93.2-1.el8.x86_64               ords-23.3.0-10.el8.noarch              


Complete!

[root@localhost ~]# 


--repofrompathオプションでYumリポジトリの位置を指定する代わりに、/etc/yum.repos.d/以下にYumリポジトリを定義するファイルを作成しても良いでしょう。

ORDSのインストールは以上で完了です。


Oracle REST Data Servicesの構成



ORDSの構成ファイルのデフォルトの位置は/etc/ords/configです。dnfコマンドでORDSをRPMファイルからインストールしている場合は、この構成ディレクトリも作成されます。

ORDSの構成はユーザーoracleで行います。ORDSを操作するコマンドは、/usr/local/bin/ordsとしてスクリプトがインストールされているので、/usr/local/binを環境変数PATHに追加します。

ORDSコマンドを実行するときに構成ディレクトリが未指定だとカレント・ディレクトリを構成ディレクトリと見做します。作業は/etc/ords/config上で実施します。

su - oracle
export PATH=/usr/local/bin:$PATH
cd /etc/ords/config

[root@localhost ~]# su - oracle

Last login: Thu May 18 11:04:18 JST 2023 on pts/0

[oracle@localhost ~]$ export PATH=/usr/local/bin:$PATH

[oracle@localhost ~]$ cd /etc/ords/config

[oracle@localhost config]$ 


構成を開始します。データベースへのオブジェクトのインストールと、Webサーバーの構成を行います。

ほとんどの指定はデフォルトを選択します。デフォルトと異なる指定は、以下です。

database service name として freepdb1 を指定する。
administrator name として sys を指定する。
database password for SYS AS SYSDBASYSのパスワードを指定する。
APEX static resource location として /home/oracle/i を指定する。

ords install

[oracle@localhost config]$ ords install

2023-05-18T02:06:00Z INFO ORDS has not detected the option '--config' and this will be set up to the default directory.


ORDS: Release 23.1 Production on Thu May 18 02:06:02 2023


Copyright (c) 2010, 2023, Oracle.


Configuration:

  /etc/ords/config/


The configuration folder /etc/ords/config does not contain any configuration files.


Oracle REST Data Services - Interactive Install


  Enter a number to select the type of installation

    [1] Install or upgrade ORDS in the database only

    [2] Create or update a database pool and install/upgrade ORDS in the database

    [3] Create or update a database pool only

  Choose [2]: 

  Enter a number to select the database connection type to use

    [1] Basic (host name, port, service name)

    [2] TNS (TNS alias, TNS directory)

    [3] Custom database URL

  Choose [1]: 

  Enter the database host name [localhost]: 

  Enter the database listen port [1521]: 

  Enter the database service name [orcl]: freepdb1

  Provide database user name with administrator privileges.

    Enter the administrator username: sys

  Enter the database password for SYS AS SYSDBA: ********

Connecting to database user: SYS AS SYSDBA url: jdbc:oracle:thin:@//localhost:1521/freepdb1


Retrieving information.

  Enter the default tablespace for ORDS_METADATA and ORDS_PUBLIC_USER [SYSAUX]: 

  Enter the temporary tablespace for ORDS_METADATA and ORDS_PUBLIC_USER [TEMP]: 

  Enter a number to select additional feature(s) to enable:

    [1] Database Actions  (Enables all features)

    [2] REST Enabled SQL and Database API

    [3] REST Enabled SQL

    [4] Database API

    [5] None

  Choose [1]: 

  Enter a number to configure and start ORDS in standalone mode

    [1] Configure and start ORDS in standalone mode

    [2] Skip

  Choose [1]: 

  Enter a number to select the protocol

    [1] HTTP

    [2] HTTPS

  Choose [1]: 

  Enter the HTTP port [8080]: 

  Enter the APEX static resources location: /home/oracle/i

The setting named: db.connectionType was set to: basic in configuration: default

The setting named: db.hostname was set to: localhost in configuration: default

The setting named: db.port was set to: 1521 in configuration: default

The setting named: db.servicename was set to: freepdb1 in configuration: default

The setting named: plsql.gateway.mode was set to: proxied in configuration: default

The setting named: db.username was set to: ORDS_PUBLIC_USER in configuration: default

The setting named: db.password was set to: ****** in configuration: default

The setting named: feature.sdw was set to: true in configuration: default

The global setting named: database.api.enabled was set to: true

The setting named: restEnabledSql.active was set to: true in configuration: default

The setting named: security.requestValidationFunction was set to: ords_util.authorize_plsql_gateway in configuration: default

The global setting named: standalone.http.port was set to: 8080

The global setting named: standalone.static.path was set to: /home/oracle/i/

The global setting named: standalone.static.context.path was set to: /i

The global setting named: standalone.context.path was set to: /ords

The global setting named: standalone.doc.root was set to: /etc/ords/config/global/doc_root

2023-05-18T02:07:03.819Z INFO        Installing Oracle REST Data Services version 23.1.2.r1151944 in FREEPDB1

------------------------------------------------------------

Date       : 18 May 2023 02:07:03

Release    : Oracle REST Data Services 23.1.2.r1151944

Type       : ORDS Install

Database   : Oracle Database 23c Free,  

DB Version : 23.2.0.0.0

------------------------------------------------------------

Container Name: FREEPDB1



[中略]


Mapped local pools from /etc/ords/config/databases:

  /ords/                              => default                        => VALID     



2023-05-18T02:07:32.334Z INFO        Oracle REST Data Services initialized

Oracle REST Data Services version : 23.1.2.r1151944

Oracle REST Data Services server info: jetty/10.0.12

Oracle REST Data Services java info: Java HotSpot(TM) 64-Bit Server VM 17.0.7+8-LTS-224



ORDSが正しく構成されていると、ORDSは起動したままでコマンド・プロンプトに戻りません。


Oracle APEXの接続確認



仮想マシンではORDSが起動し、HTTPによる接続を待っている状態です。VirtualBoxマネージャーより、仮想マシンのネットワークのポート・フォワーディングのルールを追加します。


localhostのポート8080への接続要求が仮想マシンのポート80へ転送されます。仮想マシンではfirewalldがポート80への接続要求を、ORDSが接続を待ち受けしているポート8080へ転送します。

ブラウザを立ち上げ、以下のURLに接続します。

管理サービスの接続画面が開いたら、ユーザー名adminパスワードとしてAPEXのインストール時にapxchpwd.sqlを実行して設定したパスワードを指定します。

管理にサインインをクリックします。


サインインに成功することを確認します。

ワークスペースの作成を求められます。上部のナビゲーション・メニューを選択すると、ワークスペースの作成をスキップできます。


これ以降はOracle APEXの使い方になります。APEXが動作する環境は出来ています。


ORDSの自動起動の設定



仮想マシンが起動したときにORDSも起動するように設定します。

実行中のORDSをCTRL+Cを入力して終了します。

Oracle REST Data Services java info: Java HotSpot(TM) 64-Bit Server VM 17.0.7+8-LTS-224


^C[oracle@localhost config]$ 

[oracle@localhost config]$ 


データベースより先にORDSが起動していると、HTTP 503 - ORA-12514のエラーが発生することがあります。


接続上の問題が発生したときに、コネクション・プールをリセットする時間を設定します。今回は30sとします。

ords config set --global db.invalidPoolTimeout 30s

[oracle@localhost config]$ ords config set --global db.invalidPoolTimeout 30s

2023-05-22T09:35:27Z INFO ORDS has not detected the option '--config' and this will be set up to the default directory.


ORDS: Release 23.1 Production on Mon May 22 09:35:29 2023


Copyright (c) 2010, 2023, Oracle.


Configuration:

  /etc/ords/config/


The global setting named: db.invalidPoolTimeout was set to: 30s

[oracle@localhost config]$ 


ユーザーoracleから抜けます。

exit

[oracle@localhost config]$ exit

logout

[root@localhost ~]# 


ORDSの自動起動を設定します。

systemctl enable ords

[root@localhost ~]# systemctl enable ords

Synchronizing state of ords.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.

Executing: /usr/lib/systemd/systemd-sysv-install enable ords

Created symlink /etc/systemd/system/multi-user.target.wants/ords.service → /etc/systemd/system/ords.service.

Created symlink /etc/systemd/system/graphical.target.wants/ords.service → /etc/systemd/system/ords.service.

[root@localhost ~]# 


systemctlコマンドによってORDSが起動できることを確認します。

systemctl stop ords
systemctl start ords

[root@localhost ~]# systemctl stop ords

[root@localhost ~]# systemctl start ords

[root@localhost ~]# 


先ほどと同様にOracle APEXの管理サービスに接続できることを確認します。

接続の確認ができれば、ORDSのインストールと構成は完了です。

また、これよりOracle APEXを使用することができます。

続く