個人用メモです
1日1回RHELでopensslのバージョンアップ可能か自動で確認するために仕組みを考えました。
実装内容
1.AzureVM作成
2.ストレージアカウント作成
3.Azureファイル共有をVMでマウント
4.VM起動時にコマンド実行するよう設定
5.決まった時間にVM起動するよう設定
6.今後の改善点
1. AzureVM作成
Azure上にRHEL8.1を作成します。
手順は割愛します。
2. ストレージアカウント作成
Azure上にストレージアカウントを作成します。
作成したファイル共有を選択し「接続」をクリックします。
「Linux」を選択するとマウント用のコマンドが表示されます。
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 で自動起動するようにしました。
各ファイルの中身は以下
[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
#!/bin/sh
sleep 10
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で実装します。
次にRunbookを作成します。
「ギャラリーを参照」を選択
最後にスケジュールとパラメータを設定して完成です。
以上でVM起動の設定はできました。
同様に「Stop Azure V2 VMs」で停止用の設定を入れておきます。
これで完成です。
6. 今後の改善点
・VMの起動・停止ではなく、作成・削除にしたい
・runbookではなくFunstionsで実装したい
以上です。