[Oracle Cloud][AWS] EC2にOracle ClientをインストールしてOCI Database(DBaaS)に接続してみた

本記事の目的

先日、以下のイベントに参加する機会があり、登壇者の話に大いに刺激を受けました。

実践者が語るリアルなマルチクラウド ~AWS、Azure、GCP、Oracle Cloud~

時代はマルチクラウド!!

というわけで、なんかマルチクラウドに絡めた記事を書いておくかと考えた結果、「AWSのEC2上のRHELにOracle Clientをインストールして、Oracle CloudのDBaasにsqlplusでログインする手順」を確認してみました。

※この組み合わせなら簡単に出来るかなーという単純な発想。

 

 

検証手順

0.前提

Oracle CloudのDBaaS上に、Public IPでアクセス可能なDBインスタンスを作成済み。

セキュリティリストでリスナーポート(1521)も開放。

 

1.AWSアカウント作成

実はAWSアカウント持っておらず、この記事をきっかけに作りました(汗

※無料枠1年もあるんですね。ステキです。

 

ちなみに、Oracle Cloudも無料トライアルあります。

申し込みはこちらから。

 

2.EC2起動

Linux 仮想マシンの起動」というチュートリアルに従って、仮想マシンを起動。

「Red Hat Enterprise Linux 7.6 (HVM), SSD Volume Type – ami-0b500ef59d8335eee (64 ビット x86) / ami-0302c1ecc74930ba5 (64 ビット Arm)」を選びました。

 

3.EC2ログイン

Puttyで接続するために、チュートリアルに沿って作成したキー(MyKeyPair.ppk)をputtygenで変換。

OSユーザは「ec2-user」を指定して接続。

Using username "ec2-user".
Authenticating with public key "imported-openssh-key"
[ec2-user@ip ~]$ id
uid=1000(ec2-user) gid=1000(ec2-user) groups=1000(ec2-user),4(adm),10(wheel),190(systemd-journal) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

⇒接続成功!

※初めてのEC2ログインw

 

4.Oracle Clientインストール

マニュアル手順を参考に、Oracle Clientモジュールのインストールを実施。

以下、簡単に実行したコマンドだけ。

・basic
[ec2-user@jp ~]$ sudo -s
[root@jp ec2-user]# curl -o oracle-instantclient18.3-basic-18.3.0.0.0-3.x86_64.rpm http://yum.oracle.com/repo/OracleLinux/OL7/oracle/instantclient/x86_64/getPackage/oracle-instantclient18.3-basic-18.3.0.0.0-3.x86_64.rpm
[root@jp ec2-user]# ls
oracle-instantclient18.3-basic-18.3.0.0.0-3.x86_64.rpm
[root@jp ec2-user]# yum -y localinstall oracle-instantclient18.3-basic-18.3.0.0.0-3.x86_64.rpm

・sqlplus
[root@jp ec2-user]# curl -o oracle-instantclient18.3-sqlplus-18.3.0.0.0-3.x86_64.rpm http://yum.oracle.com/repo/OracleLinux/OL7/oracle/instantclient/x86_64/getPackage/oracle-instantclient18.3-sqlplus-18.3.0.0.0-3.x86_64.rpm
[root@jp ec2-user]# yum -y localinstall oracle-instantclient18.3-sqlplus-18.3.0.0.0-3.x86_64.rpm

・お掃除
[root@jp ec2-user]# rm oracle-instantclient18.3-basic-18.3.0.0.0-3.x86_64.rpm
[root@jp ec2-user]# rm oracle-instantclient18.3-sqlplus-18.3.0.0.0-3.x86_64.rpm

 

5.環境変数設定

ec2-userへ環境変数を設定。

[ec2-user@jp ~]$ export LD_LIBRARY_PATH=/usr/lib/oracle/18.3/client64/lib:$LD_LIBRARY_PATH
[ec2-user@jp ~]$ export PATH=/usr/lib/oracle/18.3/client64/bin:$PATH

 

6.DBaaS上のDBインスタンスへ接続

sqlplusにて、EZCONNECT形式でログイン試行。

[ec2-user@jp ~]$ sqlplus system/xxxxx@<Public IP >:1521/<サービス名>

SQL*Plus: Release 18.0.0.0.0 - Production on Sun Feb 3 14:59:25 2019
Version 18.3.0.0.0

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

Last Successful login time: Sun Feb 03 2019 07:15:57 +00:00

Connected to:
Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production
Version 18.2.0.0.0

SQL>


⇒あっさりログイン成功!

 

AWSアカウント作成からここまで正味1時間くらい。

さすがAWS & Oracle。

ちょっと調べたら必要な情報が出てきて、詰まることなくやりたいことが実現できました。

 

せっかくAWSのアカウントをゲットしたので、今後もマルチクラウドネタを書いていこうかな。

 

 

参考情報

・マニュアル:Oracle Instant Client and Oracle Instant Client Light

【AWS】Amazon LinuxにOracle Instant Clientをインストールする(Chefレシピ付)

スポンサードリンク

2 Comments

  1. I wanted to thank you for this great read!! I absolutely
    enjoyed every little bit of it. I have got you saved
    as a favorite to check out new stuff you It is appropriate time
    to make a few plans for the future and it is time to be happy.

    I have learn this put up and if I could I desire to suggest you some interesting things
    or advice. Maybe you can write subsequent articles relating to this article.
    I desire to learn even more things about it! I’ll immediately take hold of your rss feed as I can’t in finding
    your e-mail subscription hyperlink or newsletter service.

    Do you’ve any? Kindly allow me understand in order that I may subscribe.
    Thanks. http://dell.com

1 Trackback / Pingback

  1. [Oracle Cloud] OCI DBaaS 関連情報まとめ(リンク集) – IT Edge Blog

itedge へ返信する コメントをキャンセル

Your email address will not be published.


*