always freeにOracle Database 18c XEを入れてみる(失敗)

Oracle Cloud always free Advent Calendar 2019の13日目です。

今日はOracle Database XE 18cをインストールしてみようと思います。
インストール対象は昨日GUI化したOracle Linux7環境です。

 

#Database Preinstallation RPMのインストール
sudo yum -y install oracle-database-preinstall-18c

 

#Oracle Database XE 18cのダウンロード
Always Free ComputeインスタンスへRDPログインして、firefoxを起動してOracle Database XE 18cのダウンロードをします。
https://www.oracle.com/database/technologies/xe-downloads.html

f:id:KNOPP:20191116232604p:plain

XEダウンロード

#Oracle Database XE 18cのインストール

sudo yum -y localinstall /home/opc/ダウンロード/oracle-database-xe
-18c-1.0-1.x86_64.rpm
読み込んだプラグイン:langpacks, ulninfo
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ oracle-database-xe-18c.x86_64 0:1.0-1 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

================================================================================
Package アーキテクチャ
バージョン
リポジトリー 容量
================================================================================
インストール中:
oracle-database-xe-18c x86_64 1.0-1 /oracle-database-xe-18c-1.0-1.x86_64 5.2 G

トランザクションの要約
================================================================================
インストール 1 パッケージ

合計容量: 5.2 G
インストール容量: 5.2 G
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
[SEVERE] Oracle Database 18c Express Edition requires a minimum of 1GB of physical
memory (RAM). This system has 971 MB of RAM and does not meet minimum
requirements.

エラー: %pre(oracle-database-xe-18c-1.0-1.x86_64) スクリプトの実行に失敗しました。終了ステータス 1
Error in PREIN scriptlet in rpm package oracle-database-xe-18c-1.0-1.x86_64
検証中 : oracle-database-xe-18c-1.0-1.x86_64 1/1

失敗:
oracle-database-xe-18c.x86_64 0:1.0-1

完了しました!

 

なんと! メモリ不足でチェック失敗してしまいました。

 

悔しいので以下を見ながら頑張ってみることにします。

community.oracle.com

 

#scriptの抜き出し

rpm -qp --scripts /home/opc/ダウンロード/oracle-database-xe-18c-1.0-1.x86_64.rpm > xe-scripts.sh

 

#preinstall scriptの抜き出し

sed -n '2,327p' xe-scripts.sh > xe-pre.sh

vi xe-pre.sh


#1行目のコメントアウト
#preinstall scriptlet (using /bin/sh):

#メモリチェックの部分を変更
#if [ $PhyMem -lt 1024 ]
if [ $PhyMem -lt 900 ]

 

#preinstall scriptの実行

sudo bash xe-pre.sh 1

 

#rpmのみのインストール

sudo rpm -i --noscripts /home/opc/ダウンロード/oracle-database-xe-18c-1.0-1.x86_64.rpm

 #postinstall scriptの抜き出し、実行

sed -n '329,392p' xe-scripts.sh > xe-post.sh

sudo bash xe-post.sh

 

あとは、通常インストールと同じです。

sudo /etc/init.d/oracle-xe-18c configure
Specify a password to be used for database accounts. Oracle recommends that the password entered should be at least 8 characters in length, contain at least 1 uppercase character, 1 lower case character and 1 digit [0-9]. Note that the same password will be used for SYS, SYSTEM and PDBADMIN accounts:
Confirm the password:
Configuring Oracle Listener.
Listener configuration succeeded.
Configuring Oracle Database XE.
[WARNING] [DBT-11209] 現在の使用可能メモリーは、データベースの作成に必要な使用可能メモリー(388MB)を下回っています。
原因: 次のノードには必要な使用可能メモリーがありません:
ノード:ol77 使用可能なメモリー:264.2656MB (270608.0KB)

[WARNING] [DBT-11205] 指定した共有プール・サイズが推奨の最小サイズ要件を満たしていません。これにより、データベースの作成が失敗します。
アクション: 共有プール・サイズに少なくとも(383 MB)を指定してください。
SYSユーザー・パスワードを入力してください:
*************
SYSTEMユーザー・パスワードを入力してください:
**************
PDBADMINユーザー・パスワードを入力してください:
**************
DB操作の準備
7%完了
データベース・ファイルのコピー中
8%完了
[WARNING] ORA-00821: Specified value of sga_target 292M is too small, needs to be at least 400M
ORA-01078: failure in processing system parameters

9%完了
[FATAL] ORA-01034: ORACLE not available

29%完了
100%完了
[FATAL] ORA-01034: ORACLE not available

7%完了
0%完了
詳細はログ・ファイル"/opt/oracle/cfgtoollogs/dbca/XE/XE.log"を参照してください。

Database configuration failed. Check logs under '/opt/oracle/cfgtoollogs/dbca'.

 

やはりメモリが足りなかったようです。

メモリ関連の初期パラメータをいじって無理やり構成することも考えましたが、経験上ケチりすぎるとまともに動かないので止めておきます。

 

アンインストール

sudo /etc/init.d/oracle-xe-18c delete

sudo rpm -e oracle-database-xe-18c-1.0-1.x86_64

 

というわけで不本意ながら本日はここまで。

Computeインスタンス(Oracle Linux7)をGUI化する

Oracle Cloud always free Advent Calendar 2019の12日目です。

今回はComputeインスタンスGUI化します。
6日目にもdockerイメージでGUIを使用できるようにしましたが、今回は直接ホストOSごとGUI化してみます。
デスクトップ環境には軽量と言われているXFCEを使用します。

なお、今回xrdp接続用のポート(3389)は公開せず、SSH転送(ポートフォワーディング)で接続することにします。

 

#XFCE/XRDPのインストールと有効化
sudo yum -y groupinstall Xfce
sudo yum -y install xrdp
sudo systemctl enable xrdp
sudo systemctl start xrdp

 

#日本語フォントのインストール

sudo yum -y install vlgothic-*

#日本語入力メソッドのインストール
sudo yum -y install ibus-kkc

#firefoxのインストール
sudo yum -y install firefox

#ロケールを日本語に変更

sudo localectl set-locale LANG=ja_JP.UTF-8

 

#xrdp接続時にxfceセッションが起動するようにする
cat > ~/.Xclients <<EOF
#!/bin/bash
export LANG="ja_JP.UTF-8"
export XMODIFIERS="@im=ibus"
export XMODIFIER="@im=ibus"
export GTK_IM_MODULE=ibus
export QT_IM_MODULE=ibus
export DefaultIMModule=ibus
ibus-daemon -drx
exec xfce4-session
EOF
chmod +x ~/.Xclients

 

#パスワードの設定
sudo passwd opc

 

Computeインスタンス側の設定が終わったら、WindowsクライアントからTeratermでComputeインスタンスSSH接続します。


SSH接続したらポートフォワーディングの設定です。
設定->SSH転送で
ローカルのポート 3389
リモート側ホスト 127.0.0.1
ポート 3389

と設定します。

f:id:KNOPP:20191116151435p:plain

設定->SSH転送

 

f:id:KNOPP:20191116151510p:plain

ポートフォワーディング設定


SSH転送設定が終わったら、リモートデスクトップで接続します。

 

f:id:KNOPP:20191116151537p:plain

リモートデスクトップ起動

リモートデスクトップ画面ではコンピューターにlocalhostと入力します。

f:id:KNOPP:20191116151623p:plain

リモートデスクトップ接続画面

f:id:KNOPP:20191116151843p:plain

接続画面

 

XRDP接続画面になるので、先ほど設定したユーザー(opc)、パスワードを入力します。

f:id:KNOPP:20191116151946p:plain

XRDPログイン画面

パスワード入力が終わるとログイン画面です。

f:id:KNOPP:20191116222954p:plain

接続後

ComputeインスタンスGUIログインすることができました。

日本語入力も可能です。

 

<参考>

参考メモ/minimal installしたCentOS7にXfce4 + ibus-kkcで日本語入力可能にする - Qiita

REST APIからComputeインスタンスの起動・停止を行う。

Oracle Cloud always free Advent Calendar 2019の11日目です。

12/10のユーザの作成~APIキーの作成までおこなっていることが前提となります。

 

#REST API発行するサンプルシェルのダウンロード

wget https://docs.cloud.oracle.com/iaas/Content/Resources/Assets/signing_sample_bash.txt
mv signing_sample_bash.txt oci-curl.sh
chmod +x oci-curl.sh

 

oci-curl.shを編集する。
tenancyId・・・・テナンシのOCID
authUserId・・・・REST APIを発行するユーザーのOCID
keyFingerprint・・・・REST APIを発行するユーザーのAPI KEYのkeyFingerprint
privateKeyPath・・・・REST APIを発行するユーザーの秘密鍵

 

#空のjsonファイル作成 (jsonの空要素{}ではダメで空ファイルであることが必要)
touch empty.json

 

#読み込み
source oci-curl.sh

 

#VM停止

#ocid1.instance~の部分が操作対象のコンピュートインスタンスのOCID、

#actions=の後が行いたいアクション
oci-curl iaas.ap-tokyo-1.oraclecloud.com post ./empty.json "/20160918/instances/ocid1.instance.oc1.ap-tokyo-1.anxhiljrzww3oficeo6igkzvj75zqvyytzzavjreb3k5mcpesbrqznfqx3aq?action=STOP"

Oracle Cloud Infrastructureから確認すると、インスタンスが停止していることが確認できます。

 

#起動
oci-curl iaas.ap-tokyo-1.oraclecloud.com post ./empty.json "/20160918/instances/ocid1.instance.oc1.ap-tokyo-1.anxhiljrzww3oficeo6igkzvj75zqvyytzzavjreb3k5mcpesbrqznfqx3aq?action=START"

 

#起動
[opc@docker vmoperator]$ oci-curl iaas.ap-tokyo-1.oraclecloud.com post ./empty.json "/20160918/instances/ocid1.instance.oc1.ap-tokyo-1.anxhiljrzww3oficeo6igkzvj75zqvyytzzavjreb3k5mcpesbrqznfqx3aq?action=START"

Oracle Cloud Infrastructureから確認すると起動していることが確認できます。

<参考>

cloudii.atomitech.jp

 

medium.com

 

docs.cloud.oracle.com

 

docs.cloud.oracle.com

 

docs.cloud.oracle.com

ユーザー・グループの作成・ポリシーの割り当てをoci cliから行う

Oracle Cloud always free Advent Calendar 2019の10日目です。

今日は、VM起動停止を行うOCIユーザをOCI CLIで作成してみます。

(実際にVM起動停止を行うのは後日やります)

 

流れは、

ユーザ作成、
グループ作成、
グループにユーザの割り当て、
グループにポリシー(権限)の割り当て

となります。

 

#ユーザの作成  (実行結果のid (user OCID)を控えておく)
oci iam user create --name vmoperator --description vmoperator

#グループの作成 (実行結果のid (group OCID)を控えておく)
oci iam group create --name vmoperator_group --description vmoperator_group

#グループへユーザの割り当て(user-idとgroup-idは先ほど作成したユーザーとグループのID)
oci iam group add-user \
--user-id ocid1.user.oc1..aaaaaaaaiwmlhkfv2nek4r7sk4av3jhz5jwyl23suvvwcjXXXXXXX \
--group-id ocid1.group.oc1..aaaaaaaazgetyuvrdag3ofrjedzq3f3a3d7b7gfnvin66pkXXXXXX

#ポリシーの作成。ポリシーはグループに割り当てる

#割り当てるポリシーはテナンシ内のVM管理
oci iam policy create --name vmoperator_policy \
--statements '["Allow group vmoperator_group to manage instance-family in tenancy"]' \
--description vmoperator_group_policy

#AUTHトークンの作成
#今回は使用しません。ADWなどで使用する場合があります。
oci iam auth-token create \
--user-id ocid1.user.oc1..aaaaaaaaiwmlhkfv2nek4r7sk4av3jhz5jwyl2XXXXXXXX \
--description vmoperator


#APIキーの作成
#ここで新規にAPIキーを作成する(oci cliAPIキーと分けたいため)
mkdir vmoperator
cd vmoperator
oci setup key
oci setup keys --output-dir .
Enter a passphrase for your private key (empty for no passphrase):
Public key written to: ./oci_api_key_public.pem
Private key written to: ./oci_api_key.pem
Public key fingerprint: ad:fd:82:7a:b5:42:82:df:47:37:e9:b0:ac:b9:82:d1


oci iam user api-key upload \
--key-file ~/vmoperator/oci_api_key_public.pem \
--user-id ocid1.user.oc1..aaaaaaaaiwmlhkfv2nek4r7sk4av3jhz5jwyl23suvvXXXXXXX

 

<オプション Oracle Cloud Infrastractureへログインする場合>
#Oracle Cloud Infrastractureへのログインパスワード発行
oci iam user ui-password create-or-reset \
--user-id ocid1.user.oc1..aaaaaaaaiwmlhkfv2nek4r7sk4av3jhz5jwyl23suvvwXXXXXX

Oracle Cloud Infrastractureへログインするとパスワード変更が促されますので、パスワード変更をします。


<参考>

cosol.jp

 

docs.cloud.oracle.com

 

docs.cloud.oracle.com

ansibleを使って、iperfでalway free間のネットワークスループットを計測する

Oracle Cloud always free Advent Calendar 2019の9日目です。

 

本日は、iperfでalway free間のネットワークスループットを計測してみます。
2台でiperfのインストール、firewalldのポート開放などがあるので、ansibleでやってみます。

 

〇セキュリティリストの確認
oracle cloudコンソールから
ネットワーキング-仮想クラウド・ネットワーク-VirtualCloudNetwork-XXXXXXXを選択
パブリック・パブリックサブネットをクリック
Default Security List for VirtualCloudNetwork-XXXXXXXXXをクリック

イングレス・ルールに以下があることを確認
ソース 10.0.0.0/24
IPプロトコル すべて

 

#作業用ディレクトリの作成
[opc@docker ~]$ mkdir iperf3
[opc@docker ~]$ cd iperf3
[opc@docker iperf3]$

 

#hostsファイルの作成
#iperfのサーバ、クライアントのIPを変数化
export iperfserver="10.0.0.3"
export iperfclient="10.0.0.5"

 

#ansible hostファイルの作成
#ここでSSHポート(54222)、秘密鍵の指定
cat <<EOF > hosts
[iperfserver]
$iperfserver
[iperfclient]
$iperfclient

[all:vars]
ansible_port=54222
ansible_user=opc
ansible_ssh_private_key_file=~/id_rsa2
EOF

 

 

#ansible-playbookの作成
cat <<EOF > iperf.yml
- hosts: all
  become: yes
  tasks:
  - name: install iperf3
    yum:
        name:
        - iperf3

  - name: firewalld 5201/tcp
    firewalld:
      port: 5201/udp
      permanent: yes
      state: enabled
      immediate: true

  - name: firewalld 5201/udp
    firewalld:
      port: 5201/tcp
      permanent: yes
      state: enabled
      immediate: true

 

- hosts: iperfserver
  become: yes
  tasks:
  - name: start server iperf
    shell: iperf3 --server --one-off --daemon

 

- hosts: iperfclient
  become: yes
  tasks:
  - name: start client iperf
    shell: iperf3 --client {{ hostvars[groups['iperfserver'][0]]['ansible_ens3']['ipv4']['address'] }} --time 60
    register: iperf_result

  - debug: var=iperf_result.stdout_lines
EOF

 

 

#ansible-playbookの実行
[opc@docker iperf3]$ ansible-playbook -i hosts iperf.yml
PLAY [all] ***********************************************************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************
ok: [10.0.0.5]
ok: [10.0.0.3]
・・・
TASK [start client iperf] ********************************************************************************************************************************
changed: [10.0.0.5]

TASK [debug] *********************************************************************************************************************************************
ok: [10.0.0.5] => {
"iperf_result.stdout_lines": [
"Connecting to host 10.0.0.3, port 5201",
"[ 4] local 10.0.0.5 port 29044 connected to 10.0.0.3 port 5201",
"[ ID] Interval Transfer Bandwidth Retr Cwnd",
"[ 4] 0.00-1.00 sec 88.4 MBytes 741 Mbits/sec 1067 332 KBytes ",
"[ 4] 1.00-2.00 sec 56.2 MBytes 472 Mbits/sec 692 393 KBytes ",
"[ 4] 2.00-3.00 sec 57.5 MBytes 482 Mbits/sec 895 131 KBytes ",
"[ 4] 3.00-4.00 sec 56.2 MBytes 472 Mbits/sec 615 43.7 KBytes ",
"[ 4] 4.00-5.00 sec 47.5 MBytes 398 Mbits/sec 461 280 KBytes ",
"[ 4] 5.00-6.00 sec 36.2 MBytes 304 Mbits/sec 367 568 KBytes ",
"[ 4] 6.00-7.00 sec 80.0 MBytes 671 Mbits/sec 1370 78.6 KBytes ",
"[ 4] 7.00-8.00 sec 46.2 MBytes 388 Mbits/sec 415 17.5 KBytes ",
"[ 4] 8.00-9.00 sec 63.8 MBytes 535 Mbits/sec 1060 78.6 KBytes ",
"[ 4] 9.00-10.00 sec 55.0 MBytes 461 Mbits/sec 500 96.1 KBytes ",
"[ 4] 10.00-11.00 sec 51.2 MBytes 430 Mbits/sec 425 315 KBytes ",
"[ 4] 11.00-12.00 sec 61.2 MBytes 514 Mbits/sec 676 603 KBytes ",
"[ 4] 12.00-13.00 sec 61.2 MBytes 514 Mbits/sec 674 1.08 MBytes ",
"[ 4] 13.00-14.00 sec 50.0 MBytes 419 Mbits/sec 760 175 KBytes ",
"[ 4] 14.00-15.00 sec 55.0 MBytes 461 Mbits/sec 464 61.2 KBytes ",
"[ 4] 15.00-16.00 sec 65.0 MBytes 545 Mbits/sec 793 848 KBytes ",
"[ 4] 16.00-17.00 sec 53.8 MBytes 451 Mbits/sec 591 69.9 KBytes ",
"[ 4] 17.00-18.00 sec 52.5 MBytes 440 Mbits/sec 819 166 KBytes ",
"[ 4] 18.00-19.00 sec 67.5 MBytes 566 Mbits/sec 691 8.74 KBytes ",
"[ 4] 19.00-20.00 sec 57.5 MBytes 482 Mbits/sec 483 87.4 KBytes ",
"[ 4] 20.00-21.00 sec 53.8 MBytes 451 Mbits/sec 369 874 KBytes ",
"[ 4] 21.00-22.00 sec 47.5 MBytes 398 Mbits/sec 661 8.74 KBytes ",
"[ 4] 22.00-23.00 sec 68.8 MBytes 577 Mbits/sec 673 35.0 KBytes ",
"[ 4] 23.00-24.00 sec 57.5 MBytes 481 Mbits/sec 584 463 KBytes ",
"[ 4] 24.00-25.00 sec 56.2 MBytes 473 Mbits/sec 720 140 KBytes ",
"[ 4] 25.00-26.00 sec 56.2 MBytes 472 Mbits/sec 773 35.0 KBytes ",
"[ 4] 26.00-27.00 sec 51.2 MBytes 430 Mbits/sec 437 629 KBytes ",
"[ 4] 27.00-28.00 sec 62.5 MBytes 524 Mbits/sec 734 114 KBytes ",
"[ 4] 28.00-29.00 sec 48.8 MBytes 409 Mbits/sec 617 184 KBytes ",
"[ 4] 29.00-30.00 sec 57.5 MBytes 482 Mbits/sec 561 489 KBytes ",
"[ 4] 30.00-31.00 sec 65.0 MBytes 545 Mbits/sec 717 43.7 KBytes ",
"[ 4] 31.00-32.00 sec 51.2 MBytes 430 Mbits/sec 529 61.2 KBytes ",
"[ 4] 32.00-33.00 sec 61.2 MBytes 514 Mbits/sec 764 26.2 KBytes ",
"[ 4] 33.00-34.00 sec 52.5 MBytes 440 Mbits/sec 352 778 KBytes ",
"[ 4] 34.00-35.00 sec 61.2 MBytes 514 Mbits/sec 534 253 KBytes ",
"[ 4] 35.00-36.00 sec 56.2 MBytes 472 Mbits/sec 917 114 KBytes ",
"[ 4] 36.00-37.00 sec 52.5 MBytes 440 Mbits/sec 769 69.9 KBytes ",
"[ 4] 37.00-38.00 sec 53.8 MBytes 451 Mbits/sec 520 481 KBytes ",
"[ 4] 38.00-39.00 sec 52.5 MBytes 440 Mbits/sec 613 638 KBytes ",
"[ 4] 39.00-40.00 sec 67.5 MBytes 566 Mbits/sec 771 1.20 MBytes ",
"[ 4] 40.00-41.00 sec 56.2 MBytes 472 Mbits/sec 686 1014 KBytes ",
"[ 4] 41.00-42.00 sec 56.2 MBytes 472 Mbits/sec 665 78.6 KBytes ",
"[ 4] 42.00-43.00 sec 60.0 MBytes 503 Mbits/sec 778 26.2 KBytes ",
"[ 4] 43.00-44.00 sec 45.0 MBytes 377 Mbits/sec 384 8.74 KBytes ",
"[ 4] 44.00-45.00 sec 67.5 MBytes 566 Mbits/sec 384 1.38 MBytes ",
"[ 4] 45.00-46.00 sec 56.2 MBytes 471 Mbits/sec 896 35.0 KBytes ",
"[ 4] 46.00-47.00 sec 56.2 MBytes 473 Mbits/sec 540 96.1 KBytes ",
"[ 4] 47.00-48.00 sec 57.5 MBytes 482 Mbits/sec 487 253 KBytes ",
"[ 4] 48.00-49.00 sec 53.8 MBytes 451 Mbits/sec 578 61.2 KBytes ",
"[ 4] 49.00-50.00 sec 51.2 MBytes 430 Mbits/sec 595 533 KBytes ",
"[ 4] 50.00-51.00 sec 60.0 MBytes 503 Mbits/sec 730 1.12 MBytes ",
"[ 4] 51.00-52.00 sec 62.5 MBytes 524 Mbits/sec 1042 551 KBytes ",
"[ 4] 52.00-53.00 sec 57.5 MBytes 482 Mbits/sec 646 69.9 KBytes ",
"[ 4] 53.00-54.00 sec 56.2 MBytes 472 Mbits/sec 473 87.4 KBytes ",
"[ 4] 54.00-55.00 sec 53.8 MBytes 451 Mbits/sec 563 944 KBytes ",
"[ 4] 55.00-56.00 sec 55.0 MBytes 461 Mbits/sec 531 78.6 KBytes ",
"[ 4] 56.00-57.00 sec 55.0 MBytes 462 Mbits/sec 274 52.4 KBytes ",
"[ 4] 57.00-58.00 sec 51.2 MBytes 430 Mbits/sec 687 245 KBytes ",
"[ 4] 58.00-59.00 sec 68.8 MBytes 577 Mbits/sec 746 166 KBytes ",
"[ 4] 59.00-60.00 sec 51.2 MBytes 430 Mbits/sec 398 717 KBytes ",
"- - - - - - - - - - - - - - - - - - - - - - - - -",
"[ ID] Interval Transfer Bandwidth Retr",
"[ 4] 0.00-60.00 sec 3.35 GBytes 479 Mbits/sec 38516 sender",
"[ 4] 0.00-60.00 sec 3.34 GBytes 479 Mbits/sec receiver",
"",
"iperf Done."
]
}

PLAY RECAP ***********************************************************************************************************************************************
10.0.0.3 : ok=6 changed=3 unreachable=0 failed=0
10.0.0.5 : ok=7 changed=3 unreachable=0 failed=0

 


Bandwidthがsender/receiverともに479 Mbits/secとなっています。
https://docs.oracle.com/cd/E97706_01/Content/Compute/References/computeshapes.htm
によるとVM.Standard.E2.1.Microのネットワーク帯域幅は480 Mbpsなので、そのままの結果になったと思います。

OCI CLI・Ansible OCI modulesを入れてみる

Oracle Cloud always free Advent Calendar 2019の8日目です。

 

昨日はAnsibleをインストールしましたが、本日はそれに続き、OCI CLIとOCI Ansibleモジュールをインストールします。
(昨日インストールしたansible環境が前提です)

 

#OCI CLIのインストール
[opc@docker ~]$ sudo yum -y install python-oci-cli

 

#USER OCID,Tenancy OCID,Compartment OCIDの確認(Oracle Cloudの管理コンソール)
USER OCID ・・・・ アイデンティティ->ユーザー で確認したいユーザのOCIDの「表示」をクリックします。
Tenancy OCID・・・ 管理->テナンシ詳細 で確認したいテナンシのOCIDの「表示」をクリックします。
Compartment OCID・ アイデンティティ->コンパートメントで確認したいユーザのコンパートメントの「表示」をクリックします。

 

#configファイルおよび公開鍵の作成
[opc@docker ~]$ oci setup config
This command provides a walkthrough of creating a valid CLI config file.

The following links explain where to find the information required by this
script:

User OCID and Tenancy OCID:

https://docs.cloud.oracle.com/Content/API/Concepts/apisigningkey.htm#Other

Region:

https://docs.cloud.oracle.com/Content/General/Concepts/regions.htm

General config documentation:

https://docs.cloud.oracle.com/Content/API/Concepts/sdkconfig.htm


Enter a location for your config [/home/opc/.oci/config]:
Enter a user OCID: ocid1.user.oc1..aaaaaaaariv62l6vabhcskbpj6ytb5i4ymm2s5p3hvnvedvhv27bs623opmq
Enter a tenancy OCID: ocid1.tenancy.oc1..aaaaaaaab2snt4bpmiq72kxirfn6sdcsappqa3fk3sljtbfjtkxsc3pmnfca
Enter a region (e.g. ap-mumbai-1, ap-seoul-1, ap-sydney-1, ap-tokyo-1, ca-toronto-1, eu-frankfurt-1, eu-zurich-1, sa-saopaulo-1, uk-london-1, us-ashburn-1, us-gov-ashburn-1, us-gov-chicago-1, us-gov-phoenix-1, us-langley-1, us-luke-1, us-phoenix-1): ap-tokyo-1
Do you want to generate a new RSA key pair? (If you decline you will be asked to supply the path to an existing key.) [Y/n]: Y
Enter a directory for your keys to be created [/home/opc/.oci]:
Enter a name for your key [oci_api_key]:
Public key written to: /home/opc/.oci/oci_api_key_public.pem
Enter a passphrase for your private key (empty for no passphrase):
Private key written to: /home/opc/.oci/oci_api_key.pem
Fingerprint: ee:1a:98:69:8a:be:34:28:31:c4:7b:1e:1a:19:d9:f6
Config written to /home/opc/.oci/config


If you haven't already uploaded your public key through the console,
follow the instructions on the page linked below in the section 'How to
upload the public key':

https://docs.cloud.oracle.com/Content/API/Concepts/apisigningkey.htm#How2

 


#公開鍵の確認
[opc@docker ~]$ cat ~/.oci/oci_api_key_public.pem
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsFb2vXNqzlrsZSWbaBOY
jFsUMsuIf1OcWJ9o+xP2CEm43wIO5R/5aO52SgQwxY6ZQvaNdpWHU2dYB70sWPny
wRMgB6WBon4AhYVqzXbA+2MMAdUMrYnG0rs0ypqrwmudUIfFiVpOhkRErmqdwk8P
・・・・・・・
-----END PUBLIC KEY-----


#公開鍵の登録
Oracle Cloudの管理コンソールから
アイデンティティ->ユーザー
公開鍵を登録したいユーザのユーザー詳細をクリックします。
APIキー->公開鍵の追加をクリックし、先ほど確認した公開鍵の「-----BEGIN PUBLIC KEY-----」から「-----END PUBLIC KEY-----」までを入力します。

 

#デフォルトコンパートメント値の設定
[opc@docker ~]$ oci setup oci-cli-rc
Predefined queries written under section OCI_CLI_CANNED_QUERIES
Command aliases written under section OCI_CLI_COMMAND_ALIASES
Parameter aliases written under section OCI_CLI_PARAM_ALIASES

 

#oci_cli_rcファイルにデフォルトコンパートメントIDの登録
[opc@docker ~]$ vi ~/.oci/oci_cli_rc
[DEFAULT]
compartment-id = ocid1.tenancy.oc1..aaaaaaaab2snt4bpmiq72kxirfn6sdcsappqa3fk3sljtbfjtkxsc3pmnfca

 

 

#設定の確認
[opc@docker ~]$oci compute image list
{
"data": [
{
"agent-features": null,
"base-image-id": null,
"compartment-id": null,
"create-image-allowed": true,
"defined-tags": {},
"display-name": "Windows-Server-2016-Standard-Edition-VM-Gen2-2019.10.09-0",
"freeform-tags": {},
"id": "ocid1.image.oc1.ap-tokyo-1.aaaaaaaavlzb37igtmrnftw4ulolbdh5ysjyxqq3d4nv72slraedsrjkwyjq",
"launch-mode": "NATIVE",
"launch-options": {
"boot-volume-type": "PARAVIRTUALIZED",
"firmware": "UEFI_64",
"is-consistent-volume-naming-enabled": false,
"is-pv-encryption-in-transit-enabled": true,
"network-type": "PARAVIRTUALIZED",
"remote-data-volume-type": "PARAVIRTUALIZED"
},
"lifecycle-state": "AVAILABLE",
"operating-system": "Windows",
"operating-system-version": "Server 2016 Standard",
"size-in-mbs": 262144,
"time-created": "2019-10-10T04:03:14.266000+00:00"
},・・・・

 


#Ansible OCI modulesのインストール
[opc@docker ~]sudo yum -y install oci-ansible-modules

 

 

#gitのインストール
[opc@docker ~]sudo yum -y install git

#oci-ansible-moduleのサンプルをダウンロード
[opc@docker ~]git clone https://github.com/oracle/oci-ansible-modules.git

 

 

#sample playbookを使って、インスタンスの起動/削除
[opc@docker ~]cd ~/oci-ansible-modules/samples/compute/launch_compute_instance

#今回、always free(VM.Standard.E2.1.Micro)を使い切っているので、VM.Standard.E2.1で試します。
#export SAMPLE_INSTANCE_SHAPE=VM.Standard.E2.1.Micro
[opc@docker launch_compute_instance]export SAMPLE_INSTANCE_SHAPE=VM.Standard.E2.1
[opc@docker launch_compute_instance]export SAMPLE_IMAGE_OCID=ocid1.image.oc1.ap-tokyo-1.aaaaaaaavafdy6turyejyoteynggaogbvmdcy2zwl5ukgy3mww6ohbmrgs7q
[opc@docker launch_compute_instance]export SAMPLE_COMPARTMENT_OCID=ocid1.tenancy.oc1..aaaaaaaab2snt4bpmiq72kxirfn6sdcsappqa3fk3sljtbfjXXXXXXXXXXXXX
[opc@docker launch_compute_instance]export SAMPLE_AD_NAME=FJrI:AP-TOKYO-1-AD-1

 

 

 

#ansible-playbookの実行
#最後までエラーなく実行できればOK
[opc@docker launch_compute_instance]$ ansible-playbook sample.yaml
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'


PLAY [Launch a compute instance and connect to it using SSH] *********************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************
ok: [localhost]

TASK [Check pre-requisites] ******************************************************************************************************************************
skipping: [localhost] => (item=SAMPLE_COMPARTMENT_OCID)
skipping: [localhost] => (item=SAMPLE_IMAGE_OCID)
skipping: [localhost] => (item=SAMPLE_AD_NAME)
・・・・・

TASK [Print SSH response from launched instance] *********************************************************************************************************
ok: [localhost] => {
"msg": "SSH response from instance -> [u'Please login as the user \"ubuntu\" rather than the user \"opc\".']"
}

TASK [Terminate the instance] ****************************************************************************************************************************
changed: [localhost]

TASK [Delete the subnet] *********************************************************************************************************************************
changed: [localhost]

TASK [Delete the security list] **************************************************************************************************************************
changed: [localhost]

TASK [Delete the route table] ****************************************************************************************************************************
changed: [localhost]

TASK [Delete the Internet Gateway] ***********************************************************************************************************************
changed: [localhost]

TASK [Delete the VCN] ************************************************************************************************************************************
changed: [localhost]

PLAY RECAP ***********************************************************************************************************************************************
localhost : ok=38 changed=11 unreachable=0 failed=0

 

<参考>

qiita.com

 

community.oracle.com

 

ansible入れる

Oracle Cloud always free Advent Calendar 2019の7日目です。

 

今日は環境構築の要であるansibleを入れます。

〇前提 always free ComputeインスタンスOracle Linux 7.7

 

#Ansibleのインストール
#yumリポジトリの最新版2.8.4だと後日実施するoci-anbile-moduleと競合するのでひとつバージョン下げてインストール
[opc@docker ~]$sudo yum -y install ansible-2.7.9

 

#動作確認
#まずはansible操作対象ファイル(hosts)を作成する。54222はSSH接続ポート

[opc@docker ~]$ cat <<EOF > hosts
10.0.0.3:54222
10.0.0.5:54222
EOF

#ansibleコマンド実行 各ホストでuname -aを実行する --private-key には秘密鍵のパスを指定する
[opc@docker ~]$ ansible --private-key=id_rsa2 -i hosts -m shell -a "uname -a" all
10.0.0.3 | CHANGED | rc=0 >>
Linux docker 4.14.35-1902.6.6.el7uek.x86_64 #2 SMP Tue Oct 8 07:32:21 PDT 2019 x86_64 x86_64 x86_64 GNU/Linux

10.0.0.5 | CHANGED | rc=0 >>
Linux ol77 4.14.35-1902.7.3.el7uek.x86_64 #2 SMP Thu Oct 31 10:06:41 PDT 2019 x86_64 x86_64 x86_64 GNU/Linux
Linux docker 4.14.35-1902.6.6.el7uek.x86_64 #2 SMP Tue Oct 8 07:32:21 PDT 2019 x86_64 x86_64 x86_64 GNU/Linx

 

 

<余談>
Oracle Linux7でanbileを導入するには、3パターンがあります。
a. python2のpipからインストール
b. python3.6のpipからインストール
c. yumからインストール

aに関しては、python2が2020年1月にサポート終了になるので、各種モジュールのメンテナンスがいつまで続くかわかりません。
bに関しては、現時点(2019年12月)では、以下の不具合がありうまく動きません。(かなりハマって断念)
https://github.com/pycontribs/selinux/issues/22
RHEL7.8では解消されるようなので、半年後は状況違うかもしれませんが。
現状、まともに使えてパッケージメンテナンスを受けられそうなのが、cのyumからのインストールとなります。