LoginSignup
1
1

More than 3 years have passed since last update.

raidの定期チェック

Last updated at Posted at 2021-02-06

自分のサーバではraid5で12TBのストレージを運用しています。
これに何かあったらすぐに対処したいので障害が起きたらメールで通知が来るように設定しておきます。

chkraid.sh
cat /proc/mdstat | grep _ > /dev/null
if [ $? = 0 ]; then
        # raidでエラー発生
        cat /proc/mdstat | mail -s "raid error!" user@hoge.com
else
        echo "raid check success."
fi

こんな感じのスクリプトを用意します。
エラーチェックの方法は正規の方法が分からなかったので、/proc/mdstat の中に_があったらエラーとみなし、/proc/mdstatの内容をメールで送るようにしました。

追記:
/sbin/mdadm --monitor --scan -1 --test
でエラー発生時ではなく実行時にメールが飛ぶのでこれでもいいかな。

正常に動くことを確認したら

/etc/cron.d/raid_chk
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed
#17 *   * * *   root    cd / && run-parts --report /etc/cron.hourly
10 0 * * *      user1  /home/user/scripts/chkraid.sh >> /home/user1/scripts/cron.log

このようなファイルを作成してcronで定期的に実行させます。
とりあえず一日一回実行し、出力をログに残します。

メールが飛んでこないことを祈りましょう。

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