Oracle DBをSilent Installする

Oracle DBをサイレント インストールします。

環境情報

事前設定

日本向けのOS設定

タイムゾーンとlocaleを変更。

$ sudo timedatectl set-timezone Asia/Tokyo
$ sudo localectl set-locale LANG=ja_JP.utf8

物理メモリのサイズ

OS上の各種設定値を確認していきます。

サーバーのハードウェアとメモリー構成の確認

Oracle Databaseのインストールには、1GB以上のRAMが必要です。2GBのRAMを推奨します

$ grep MemTotal /proc/meminfo
MemTotal:       15791384 kB

swapサイズの確認

1GBから2GB: RAMのサイズの1.5倍

2GBから16GB: RAMのサイズに等しい

16GBより大きい: 16GB

$ grep SwapTotal /proc/meminfo
SwapTotal:             0 kB
$ sudo dd if=/dev/zero of=/swapfile bs=1M count=15360
15360+0 records in
15360+0 records out
16106127360 bytes (16 GB) copied, 91.3986 s, 176 MB/s
$ sudo chown root:root /swapfile
$ sudo chmod 600 /swapfile
$ sudo mkswap /swapfile
$ sudo swapon /swapfile
$ grep SwapTotal /proc/meminfo
SwapTotal:      15728636 k

/etc/fstab に追記。

/swapfile swap  swap  defaults  0 0

/tmpディレクトリ空き領域を確認

/tmpディレクトリに1GB以上の領域。

$ $ df -h /tmp
Filesystem      Size  Used Avail Use% Mounted on
/dev/nvme0n1p1   60G   16G   45G  27% /

共有メモリのサイズを確認

共有メモリー(/dev/shm)に十分なサイズのメモリーがマウントされていることを確認

$ df -h /dev/shm
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           7.6G     0  7.6G   0% /dev/shm

透過的なHugePagesの無効化

HugePageとは、

Hugepage の機能により、現代的なハードウェアアーキテクチャに備わっている複数のページサイズを Linux カーネルで使用できます。Linux は物理 RAM も swap も両方からマップされている仮想メモリの複数ページを作成します。ページは仮想メモリの基本単位で、x86 アーキテクチャのデフォルトページサイズは 4096 バイトです。

Linux は、"Translation Lookaside Buffers" (TLB) と呼ばれる CPU アーキテクチャのメカニズムを使用して、仮想メモリページから実際の物理メモリアドレスへのマッピングを管理します。TLB は限られたハードウェアリソースであるため、デフォルトのページサイズで物理メモリを大量に使用すると TLB が消費され、処理のオーバーヘッドをもたらします (4096 バイトサイズのページによって多くの TLB リソースが消費されます。) Huge Page を使用すると、より大きなサイズのページを作成でき、各ページは一つの TLB リソースを消費します。Huge Page を作成すると、Huge Page にマッピングされた物理メモリは通常のメモリ割り当ての影響を受けなくなり、カーネル仮想メモリーマネージャで管理できなくなるため、Huge Page は実質 '保護され'、Huge Page を必要とするアプリケーションのみが利用できるという副次的な効果があります。Huge Page は物理 RAM に '固定' され、スワップアウトできません。

通常は特有の高位メモリを使用するアプリケーションのために、そしてシステムが高メモリ負荷下にあってもページがスワップアウトされないように、Huge Page を割り当てます。また、32 ビットシステムでメモリ使用量を管理するために Huge Page を割り当てます。Huge Page を作成して、それを使用するようにアプリケーションを設定すると、カーネルが管理するページが減るため、カーネルによるメモリ管理のオーバーヘッドが減ります。カーネル仮想メモリーマネージャは低位メモリを利用します。管理するページが少ない場合は、低位メモリはあまり消費されません。

Huge Page とは何ですか? これを使用する利点は?

透過的なHugePage(Transparet HugePage)とは、このHugePageの機能を透過的に、つまりアプリケーション側の変更を必要とせず自動的に利用できるようする機能です。ただOracle DBでこの機能を利用するのは問題があるらしく、下記とのこと。

透過的なHugePagesを使用すると、実行中にメモリー割当ての遅延が生じます。パフォーマンスの問題を回避するために、透過的なHugePagesはすべてのOracle Databaseサーバーで無効にすることをお薦めします。かわりに標準のHugePagesを使用すると、パフォーマンスが向上します。

透過的なHugePagesメモリーが標準のHugePagesメモリーと異なるのは、カーネルのkhugepagedスレッドが実行時にメモリーを動的に割り当てるためです。標準のHugePagesメモリーは起動時に事前割当てされ実行中には変更されません。

大容量メモリーを最適化する構成

現在の設定の確認。 always は有効化されている意味。

$ sudo cat /sys/kernel/mm/transparent_hugepage/enabled
[always] madvise never

GRUBの設定変更が必要となるらしく、設定変更前の確認。 /proc/cmdlineブートローダーがkernelに渡すパラメータを記録しているファイルらしいです。

$ cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-3.10.0-957.1.3.el7.x86_64 root=UUID=f41e390f-835b-4223-a9bb-9b45984ddf8d ro console=tty0 console=ttyS0,115200n8 crashkernel=auto console=ttyS0,115200 LANG=en_US.UTF-8

/etc/sysconfig/grub を編集して、 GRUB_CMDLINE_LINUX の値に transparent_hugepage=never を追加します。

GRUB_CMDLINE_LINUX="console=tty0 crashkernel=auto console=ttyS0,115200 transparent_hugepage=never"

以下のコマンドにて、GRUBの設定ファイルが再作成されるらしいです。

$ sudo grub2-mkconfig -o /boot/grub2/grub.cfg

OS再起動。起動後に /proc/cmdline を再確認。 transparent_hugepage=never が渡されています。

$ cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-3.10.0-957.1.3.el7.x86_64 root=UUID=f41e390f-835b-4223-a9bb-9b45984ddf8d ro console=tty0 crashkernel=auto console=ttyS0,115200 transparent_hugepage=never

こちらも確認。 never となっています。

$ sudo cat /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]

透過的なHugePagesの無効化

Red Hat Enterprise Linux 7 で transparent hugepages (THP) を無効にする

OSグループとユーザの追加

OracleDBで利用されるOSグループとユーザを追加。

$ sudo groupadd -g 54321 oinstall
$ sudo groupadd -g 54322 dba
$ sudo groupadd -g 54323 oper
$ sudo groupadd -g 54324 backupdba
$ sudo groupadd -g 54325 dgdba
$ sudo groupadd -g 54326 kmdba
$ sudo groupadd -g 54330 racdba
$ sudo useradd -u 54321 -g oinstall -G dba,oper,backupdba,dgdba,kmdba,racdba oracle

オペレーティング・システム権限のグループの作成

併せて、上記で作成したoracleユーザの /home/oracle/.bashrc に、以下のumask設定を実施。

umask 022

Oracleソフトウェア所有者の環境要件

sudo権限も付与しておきます。

$ sudo echo "oracle ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/oracle

リソース制限の確認

oracleユーザの制限を、 /etc/security/limits.conf より、推奨値を参考に変更。変更後はOS再起動しておきます。

oracle           soft    nofile          1024
oracle           hard    nofile          65536
oracle           soft    nproc           2047
oracle           hard    nproc           16384
oracle           soft    stack           10240
oracle           hard    stack           32768
oracle           soft    memlock         14155776
oracle           hard    memlock         14155776

f:id:goodbyegangster:20191115043822p:plain

Oracleソフトウェア・インストール・ユーザーのリソース制限の確認

OS環境変数の確認

Oracle関連の環境変数が設定されていないことを確認。

$ printenv | grep -e ORA_CRS_HOME -e ORACLE_HOME -e ORA_NLS10 -e TNS_ADMIN
$ echo $PATH | grep oracle

Oracleインストール所有者の環境変数の設定削除

kernelパラメータの変更

OracleDBインストール時の推奨最小値を公開してくれているので、それを参考に変更します。 /etc/sysctl.d/97-oracle-database-sysctl.conf というフィアルを作成して、環境に見合ったパラメータを以下のように記述。

fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 1579123
kernel.shmmax = 8085112832
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576

以下コマンドにて有効となります。

$ sudo /sbin/sysctl --system

ここでもOS再起動を実施。

インストールのための最小パラメータ設定

SELinuxの無効化

無効にしてしまいます。 /etc/selinux/config ファイルの、 SELINUX の値を disabled に変更。

SELINUX=disabled

ここでもOS再起動を実施。

インストール

以下を参考にインストール処理していきます。

レスポンス・ファイルを使用したOracle Databaseのインストールおよび構成

必要ディレクトリの作成

Oracle Baseディレクトリとなるディレクトリを作成します。

$ sudo mkdir -p /u01/app/oracle
$ sudo chown -R oracle:oinstall /u01
$ sudo chmod -R g+w /u01

oracleユーザにスイッチして、インストール用ディレクトリを用意します。

$ sudo su oracle
$ mkdir /home/oracle/install

OracleDBインストールモジュールの配置

OTNのサイトより、開発版のOracle DBインストールモジュールをダウンロードしてきます。

Oracle Database ソフトウェア・ダウンロード

上記で作成したディレクトリにアップロードして、zipを解凍しておきます。

レスポンスファイルの編集

レスポンスファイルは、 解凍したディレクトリの database/response/db_install.rsp にあります。このファイルをコピーして必要な設定を編集します。

パラメータ
oracle.install.option INSTALL_DB_SWONLY
UNIX_GROUP_NAME oinstall
ORACLE_HOME /u01/app/oracle/product/12.2.0/db_1
ORACLE_BASE /u01/app/oracle
INVENTORY_LOCATION /u01/app/oraInventory
oracle.install.db.InstallEdition EE
oracle.install.db.OSDBA_GROUP dba
oracle.install.db.OSOPER_GROUP oper
oracle.install.db.OSBACKUPDBA_GROUP backupdba
oracle.install.db.OSDGDBA_GROUP dgdba
oracle.install.db.OSKMDBA_GROUP kmdba
oracle.install.db.OSRACDBA_GROUP racdba

インストール実行

実行します。

$ /home/oracle/install/database/runInstaller -waitforcompletion -noconfig -silent -responseFile /home/oracle/install/sample_install.rsp

以下は runInstaller コマンドのヘルプです。

$ database/runInstaller -help
Following are the possible flags:
        -help - display help.
        -silent - run in silent mode. The inputs can be a response file or a list of command line variable value pairs.
                [-lenientInstallMode - perform the best effort installation by automatically ignoring invalid data in input parameters.]
                [-ignorePrereqFailure - ignore all prerequisite checks failures.]
                [-showProgress - show the installation progress on the console. This option is supported for silent mode installation only.]
        -responseFile - specify the complete path of the response file to use.
        -invPtrLoc - point to a different inventory location. The orainst.loc file contains the location of the central inventory (inventory_loc) and the inventory group (inst_group).
        -jreLoc - specify the location for the jre used in the installation.
        -logLevel - enable the log of messages up to the priority level provided in this argument. Valid options are: severe, warning, info, config, fine, finer, finest.
        -paramFile - specify the location of the oraparam.ini file to be used in the installation.
        -executePrereqs | -executeConfigTools | -deinstall
        -executePrereqs - execute the prerequisite checks only.
        -executeConfigTools - execute the config tools for an installed home.
                -responseFile - specify the complete path of the response file to use.
                [-all - execute all the config tools for an installed home, including the config tools that have already succeeded.]
        -deinstall - uninstall the specified home.
        -debug - run in debug mode.
        -executeSysPrereqs - execute the system prerequisite checks and exit.
        -ignoreSysPrereqs - ignore the results of the system prerequisite checks.
        -printdiskusage - log the debug information for the disk usage.
        -printmemory - log the debug information for the memory usage.
        -printtime - log the debug information for the time usage.
        -waitForCompletion - wait for the completion of the installation, instead of spawning the installer and returning the console prompt.
        -suppressPreCopyScript - suppress the execution of the precopy script.
        -acceptUntrustedCertificates - accept untrusted certificates from a secure site.
        -suppressPostCopyScript - suppress the execution of the postcopy script.
        -noconfig - do not execute the config tools.
        -noconsole - suppress the display of messages in the console. The console is not allocated.
        -skipPrereqs - skip the prerequisite checks.
        -ignoreInternalDriverError - ignore any internal driver errors.
        -promptForPassword - provide the passwords on the console during a silent installation of an Oracle database.
        -remotecp - specify the path to the remote copy program on the local cluster node. Used only for cluster installs.
        -remoteshell - specify the path to the remote shell program on the local cluster node. Used only for cluster installs.
        -version - get the product version.

実行結果です。

$ /home/oracle/install/database/runInstaller -waitforcompletion -noconfig -silent -responseFile /home/oracle/install/sample_install.rsp
Starting Oracle Universal Installer...

Checking Temp space: must be greater than 500 MB.   Actual 36772 MB    Passed
Checking swap space: must be greater than 150 MB.   Actual 15359 MB    Passed
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2019-11-13_11-08-51PM. Please wait ...You can find the log of this install session at:
 /u01/app/oraInventory/logs/installActions2019-11-13_11-08-51PM.log
The installation of Oracle Database 12c was successful.
Please check '/u01/app/oraInventory/logs/silentInstall2019-11-13_11-08-51PM.log' for more details.

As a root user, execute the following script(s):
        1. /u01/app/oraInventory/orainstRoot.sh
        2. /u01/app/oracle/product/12.2.0/db_1/root.sh

僕の実施した環境では、successfulとなるものの、以下のようなエラーが大量に発生していました。

  • Error in invoking target 'client_sharedlib' of makefile '/u01/app/oracle/product/12.2.0/db_1/rdbms/lib/ins_rdbms.mk'. See '/u01/app/oraInventory/logs/installActions2019-11-13_11-08-51PM.log' for details.
  • Error in invoking target 'links proc gen_pcscfg procob' of makefile '/u01/app/oracle/product/12.2.0/db_1/precomp/lib/ins_precomp.mk'. See '/u01/app/oraInventory/logs/installActions2019-11-13_11-08-51PM.log' for details.
  • Error in invoking target 'idg4odbc' of makefile '/u01/app/oracle/product/12.2.0/db_1/rdbms/lib/ins_rdbms.mk'. See '/u01/app/oraInventory/logs/installActions2019-11-13_11-08-51PM.log' for details.

メッセージ内で確認を示唆しているログ・ファイルでgrepしてあげると、プロンプト上に表示されていないメッセージも確認できました。こんな感じですね。

$ cat /u01/app/oraInventory/logs/installActions2019-11-13_11-08-51PM.log | grep Err

そのメッセージを確認すると、以下のパッケージが不足しているようでした。

  • compat-libcap1
  • libstdc++-devel(x86_64)
  • sysstat
  • gcc-c++
  • ksh
  • glibc-devel(x86_64)
  • libaio
  • libaio-devel(x86_64)
  • smartmontools

そのため、必要なパッケージを入れ直して、インストールをやり直しています。

$ sudo yum install -y compat-libcap1 libstdc++-devel sysstat gcc-c++ ksh glibc-devel libaio libaio-devel smartmontools

指定スクリプトの実行

プロンプトに表示された2つのスクリプトをsudo権限で実行します。

$ sudo /u01/app/oraInventory/orainstRoot.sh
Changing permissions of /u01/app/oraInventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.

Changing groupname of /u01/app/oraInventory to oinstall.
The execution of the script is complete.
$ sudo /u01/app/oracle/product/12.2.0/db_1/root.sh
Check /u01/app/oracle/product/12.2.0/db_1/install/root_ip-172-31-34-16.ap-northeast-1.compute.internal_2019-11-13_11-30-09-053248891.log for the output of root script

Net Configuration Assistantの実行

Network Configuration Assistantを実行して、Listenerを作成しておきます。Network Configuration Assistant用のレスポンスファイルは、インストールモジュールの database/response/netca.rsp にあります。レスポンスファイルはデフォルト値から変更せずに利用できるので、適当なPathにコピーして netca コマンドを実行。

$ /u01/app/oracle/product/12.2.0/db_1/bin/netca -silent -responsefile /home/oracle/install/sample_netca.rsp

Parsing command line arguments:
    Parameter "silent" = true
    Parameter "responsefile" = /home/oracle/install/sample_netca.rsp
Done parsing command line arguments.
Oracle Net Services Configuration:
Profile configuration complete.
Oracle Net Listener Startup:
    Running Listener Control:
      /u01/app/oracle/product/12.2.0/db_1/bin/lsnrctl start LISTENER
    Listener Control complete.
    Listener started successfully.
Listener configuration complete.
Oracle Net Services configuration successful. The exit code is 0

レスポンス・ファイルを使用したNet Configuration Assistantの実行

Database Configuration Assistantの実行

Database Configuration Assistantを実行して、データベースを作成します。

事前にデータファイルを配置するディレクトリを作成しておきます。

$ sudo mkdir /data
$ sudo chown oracle:oinstall /data
$ sudo chmod g+w /data

dbca用のレスポンスファイルは、インストールモジュールの database/response/dbca.rsp にあるのですが、レスポンスファイルでのインストールは上手くいかなったため、以下のようにパラメータで値を指定しています。

$ /u01/app/oracle/product/12.2.0/db_1/bin/dbca -silent -createDatabase \
-templateName /u01/app/oracle/product/12.2.0/db_1/assistants/dbca/templates/General_Purpose.dbc \
-gdbName orcl \
-sid orcl \
-sysPassword change_on_install \
-systemPassword manager \
-datafileDestination /data \
-characterSet "AL32UTF8" \
-nationalCharacterSet "UTF8"

スペックに依るのでしょうが、作成完了までは結構時間がかかります。

レスポンス・ファイルを使用したDatabase Configuration Assistantの実行

接続確認

データベースが出来たはずですので、接続してみます。

接続前にOracleDB用の環境変数を設定します。 /home/oracle/.bashrc に以下を追記します。

export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=${ORACLE_BASE}/product/12.2.0/db_1
export PATH=$ORACLE_HOME/bin:$PATH:$HOME/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export ORACLE_SID=orcl
export NLS_LANG=Japanese_Japan.UTF8
export LC_ALL=ja_JP.utf8

sqlplusで接続してみます。

$ sqlplus / as sysdba

SQL*Plus: Release 12.2.0.1.0 Production on 水 1113 23:55:53 2019

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

Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production に接続されました。
SQL> select instance_name from v$instance;

INSTANCE_NAME
------------------------------------------------
orcl

接続できました。