LoginSignup
1
0

More than 1 year has passed since last update.

AWS EC2にOracle Database 18c Express Edition(XE)をインストールする方法

Last updated at Posted at 2021-05-31

前提

Oracle Silver DBAの勉強目的でOracleDBをEC2にインストールしてみました。
OracleXEのシステム要件を満たすため、以下設定でEC2インスタンスを起動。
・OSはRHEL7.0
・インスタンスタイプはt2.small
・ストレージは30GBに拡張(最小要件は10G。余裕持たせて20Gか30Gあれば十分。)
・インバウンドルールでport1521を開放しておく。(Oracleリスナー用)

参考:
https://docs.oracle.com/cd/E96517_01/xeinl/system-requirements.html

インスタンスタイプは無料枠のt2.microではRAMの容量不足でインストールできないので注意。

[SEVERE] Oracle Database 18c Express Edition requires a minimum of 1GB of physical
memory (RAM).  This system has 992 MB of RAM and does not meet minimum
requirements.

1hで10円ほどかかります。勉強のため課金。
こまめにインスタンスを停止していれば問題なしでしょ!(多分)

準備(disk拡張)

cmdからEC2にssh接続

cmd
ssh -i C:xxxx.pem ec2-user@xxx.xxx.xxx.xxx

容量確認

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda2      6.0G  802M  5.3G  14% /
devtmpfs        487M     0  487M   0% /dev
tmpfs           497M     0  497M   0% /dev/shm
tmpfs           497M   13M  484M   3% /run
tmpfs           497M     0  497M   0% /sys/fs/cgroup

あれ?インスタンス起動時に30GBに設定したけど反映されていない。

調べてみると、手動での反映が必要らしいことが分かった。

参考:
https://qiita.com/tao_s/items/17e73d5d4108482f5f41
https://bugzilla.redhat.com/show_bug.cgi?id=1155742

パーティション確認

$ lsblk
NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda    202:0    0  30G  0 disk
├─xvda1 202:1    0   1M  0 part
└─xvda2 202:2    0   6G  0 part /

xvdaは30G。一方で、ルートのxvda2は6G。

xvda2に30GBを反映する。作業に必要なgdiskなるパッケージをインストール。

$ sudo yum install gdisk

拡張

$ sudo growpart -u off /dev/xvda 2

★sudo growpart /dev/xvda 2ではうまくいかない。2時間程ハマった。

再起動

$ shutdown -r now

再接続後ディスクサイズ確認

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda2       30G  4.2G   26G  14% /
devtmpfs        487M     0  487M   0% /dev
tmpfs           497M     0  497M   0% /dev/shm
tmpfs           497M   13M  484M   3% /run
tmpfs           497M     0  497M   0% /sys/fs/cgroup
tmpfs           100M     0  100M   0% /run/user/1000

/dev/xvda2のSizeが30Gになっている。

準備(パッケージ)

XEのパッケージをローカルにダウンロード。
https://www.oracle.com/jp/database/technologies/xe-downloads.html

ec2-user配下にrpmを置くtmpフォルダを作成。

$ mkdir tmp
$ ll
total 0
drwxrwxr-x. 2 ec2-user ec2-user 6 May 29 12:06 tmp

cmdでローカルからec2へrpmをscpでコピー

cmd
scp -i C:xxxx.pem C:\temp\oracle-database-xe-18c-1.0-1.x86_64.rpm ec2-user@xxx.xxx.xxx.xxx:/home/ec2-user/tmp

存在確認

$ cd tmp
$ ll
total 2462664
-rw-rw-r--. 1 ec2-user ec2-user 2521766408 May 29 12:10 oracle-database-xe-18c-1.0-1.x86_64.rpm

/usr/local/srcに移動

$ cd /usr/local/src/

compat-libstdc++-33とpreinstallをgetしてインストール(これを先に入れておかないと依存関係で怒られる)

$ sudo curl -o compat-libstdc++-33-3.2.3-72.el7.x86_64.rpm http://mirror.centos.org/centos/7/os/x86_64/Packages/compat-libstdc++-33-3.2.3-72.el7.x86_64.rpm
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  190k  100  190k    0     0  90614      0  0:00:02  0:00:02 --:--:-- 90583

$ sudo yum -y localinstall compat-libstdc++-33-3.2.3-72.el7.x86_64.rpm

$ sudo curl -o oracle-database-preinstall-18c-1.0-1.el7.x86_64.rpm https://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/getPackage/oracle-database-preinstall-18c-1.0-1.el7.x86_64.rpm
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 18244  100 18244    0     0  49243      0 --:--:-- --:--:-- --:--:-- 49308

$ sudo yum -y localinstall oracle-database-preinstall-18c-1.0-1.el7.x86_64.rpm

OracleXEインストール

ここから先は公式のインストレーションガイドを参考に進めた。
参考:https://docs.oracle.com/cd/E96517_01/xeinl/installing-oracle-database-xe.html

先ほどtmpにコピーしたrpmを/usr/local/srcにmv

$ sudo mv /home/ec2-user/tmp/oracle-database-xe-18c-1.0-1.x86_64.rpm .

OracleXEをインストール

$ sudo yum -y localinstall oracle-database-xe-18c-1.0-1.x86_64.rpm

rootにsuしてサービス構成スクリプトを実行

$ su -
# /etc/init.d/oracle-xe-18c configure

oraenvスクリプトを使用して環境変数設定

# export ORACLE_SID=XE 
# export ORAENV_ASK=NO 
# . /opt/oracle/product/18c/dbhomeXE/bin/oraenv

PATH、ORACLE_BASE、ORACLE_HOMEが設定されていることを確認

# printenv
...
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/opt/oracle/product/18c/dbhomeXE/bin
ORACLE_BASE=/opt/oracle
ORACLE_HOME=/opt/oracle/product/18c/dbhomeXE
...

接続確認

SQL*Plusでデータベースに接続してみる。
tnsnames.oraを開きネットサービス名(接続識別子)確認

# cat /opt/oracle/product/18c/dbhomeXE/network/admin/tnsnames.ora

XE =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = xxxxxxxxxxx)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = XE)
    )
  )

接続

# sqlplus system@XE

SQL*Plus: Release 18.0.0.0.0 - Production on Sat May 29 22:05:34 2021
Version 18.4.0.0.0

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

Enter password:
Last Successful login time: Sat May 29 2021 22:05:09 -04:00

Connected to:
Oracle Database 18c Express Edition Release 18.0.0.0.0 - Production
Version 18.4.0.0.0

SQL>

成功!

永続的な環境変数を設定する

今は環境変数が一時的であるため、ログアウトすると設定が失われる。
永続的な環境変数を設定し、また、oracleユーザーでログイン後変数設定の準備なくSQL*Plusを使用できるようにする

/etc/profileを編集する(全ユーザへの環境変数設定)

# sudo vi /etc/profile

【編集内容】以下を末尾に追記
export ORACLE_SID=XE
export ORAENV_ASK=NO
export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=/opt/oracle/product/18c/dbhomeXE

設定反映

# source /etc/profile

反映確認

# printenv

rootからoracleにsuし、~./bash_profileのPATHを編集(oracleユーザーのみの環境変数設定)
:$ORACLE_HOME/binを追加する。

$ su - oracle
$ vi ~/.bash_profile
$ cat ~/.bash_profile

# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin:$ORACLE_HOME/bin

export PATH

設定反映し、環境変数を確認

$ source /etc/profile
$ printenv

ec2-userにexitで戻った後、再度oracleにsuして接続確認

$ sudo su - oracle
Last login: Sun May 30 00:28:20 EDT 2021 on pts/0
$ sqlplus system@XE

SQL*Plus: Release 18.0.0.0.0 - Production on Sun May 30 00:36:20 2021
Version 18.4.0.0.0

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

Enter password:
Last Successful login time: Sun May 30 2021 00:33:03 -04:00

Connected to:
Oracle Database 18c Express Edition Release 18.0.0.0.0 - Production
Version 18.4.0.0.0

SQL>

成功!

自動起動/停止設定

EC2インスタンスを停止/起動する際に、手動でリスナーおよびDataBaseを停止/起動するのは面倒。
自動で落とし上げできるようにしておく。

$ su -
Password:
Last login: Sun May 30 00:53:21 EDT 2021 on pts/0

# systemctl daemon-reload
# systemctl enable oracle-xe-18c
oracle-xe-18c.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig oracle-xe-18c on

DataBaseの起動状態はSQL*Plusで以下のコマンドで確認可能

SQL> select host_name, instance_name, status from v$instance;

HOST_NAME
----------------------------------------------------------------
INSTANCE_NAME    STATUS
---------------- ------------
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
XE               OPEN

おまけ EM Express

OracleDBにはEM ExpressというGUIベースの管理ツールが標準搭載されている。せっかくなので利用してみる。

使用するportを確認

$ sqlplus system@EX

SQL> select dbms_xdb_config.gethttpsport from dual;
GETHTTPSPORT
------------
        5500

EC2のネットワーク設定にて5500を開放しておく

インバウンドルール
カスタム TCP TCP 5500 0.0.0.0/0 –

ローカルマシン(クライアント)からの接続を許可

SQL> exec dbms_xdb.setlistenerlocalaccess(FALSE);
PL/SQL procedure successfully completed.

ブラウザでhttps://EC2インスタンスのIPアドレス/em/を入力
⇒ログインページに遷移するが、2021/5/30現在 FlashはEOLのため使えない

以上。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0