0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Azure上のRHELで1日1回コマンド実行し結果をAzureファイル共有に吐き出す

Last updated at Posted at 2022-01-10

個人用メモです
1日1回RHELでopensslのバージョンアップ可能か自動で確認するために仕組みを考えました。

実装内容

1.AzureVM作成
2.ストレージアカウント作成
3.Azureファイル共有をVMでマウント
4.VM起動時にコマンド実行するよう設定
5.決まった時間にVM起動するよう設定
6.今後の改善点

1. AzureVM作成

Azure上にRHEL8.1を作成します。
手順は割愛します。

2. ストレージアカウント作成

Azure上にストレージアカウントを作成します。

作成後ファイル共有を作成します。
スクリーンショット (6).png

作成したファイル共有を選択し「接続」をクリックします。
「Linux」を選択するとマウント用のコマンドが表示されます。

スクリーンショット (10).png

3. Azureファイル共有をVMでマウント

今回はSMBでマウントします。
参考

まずはcifs-utilsをインストールします。

dnf install cifs-utils

マウント用のコマンドを実行しマウントします。

dfコマンドでマウントできているか確認します。

Filesystem                                    1K-blocks    Used  Available Use% Mounted on
~略
//<ストレージアカウント名>.file.core.windows.net/azure 5368709120       0 5368709120   0% /mnt/azure

4. VM起動時にコマンド実行するよう設定

systemd で自動起動するようにしました。
各ファイルの中身は以下

/etc/systemd/system/checkupdate.service
[Unit]
Description = check for openssl
After=local-fs.target
ConditionPathExists=/home/script

[Service]
ExecStart=/usr/bin/sh /home/script/kick.sh
Restart=no
Type=simple

[Install]
WantedBy=multi-user.target
/home/script/kick.sh
#!/bin/sh

sleep 10
sh /home/script/checkupdate.sh
/home/script/checkupdate.sh
#!/bin/sh
FILE_DIR=/home/mnt/azure/

echo "====openssl version===" >> ${FILE_DIR}yum_update_list_$(date +%Y%m%d).txt
openssl version >> ${FILE_DIR}yum_update_list_$(date +%Y%m%d).txt

echo "====yum check-update===" >> ${FILE_DIR}yum_update_list_$(date +%Y%m%d).txt
yum check-update openssl-* >> ${FILE_DIR}yum_update_list_$(date +%Y%m%d).txt

echo "====yum update===" >> ${FILE_DIR}yum_update_list_$(date +%Y%m%d).txt
yum update  openssl-*  >> ${FILE_DIR}yum_update_list_$(date +%Y%m%d).txt

5. 決まった時間にVM起動するよう設定

Runbookで実装します。

まずはAutomationアカウントを作成
01.png

次にRunbookを作成します。
「ギャラリーを参照」を選択
02.png

「Start Azure V2 VMs」を選択します。
04.png

作成したRunbookを選択し「公開」を選択します。
03.png

最後にスケジュールとパラメータを設定して完成です。

スクリーンショット (29).png

スクリーンショット (30).png

以上でVM起動の設定はできました。
同様に「Stop Azure V2 VMs」で停止用の設定を入れておきます。スクリーンショット (33).png

これで完成です。

6. 今後の改善点

・VMの起動・停止ではなく、作成・削除にしたい
・runbookではなくFunstionsで実装したい

以上です。

0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?