13 June 2010

(Ubuntu) smartmontoolsでハードディスク監視とメール送信の設定

ハードディスクのSMART機能でエラーが発見された場合、管理者にメールを送信するように設定する。

■ smartmontoolsのインストール


# apt-get install smartmontools

■ SMART値が表示できるかチェック


# smartctl -a /dev/sda
smartctl version 5.38 [i686-pc-linux-gnu] Copyright (C) 2002-8 Bruce Allen
Home page is http://smartmontools.sourceforge.net/

=== START OF INFORMATION SECTION ===
Model Family: Seagate Barracuda 7200.11
Device Model: ST3500320AS
Serial Number: ********
Firmware Version: SD1A
User Capacity: 500,107,862,016 bytes
Device is: In smartctl database [for details use: -P show]
ATA Version is: 8
ATA Standard is: ATA-8-ACS revision 4
Local Time is: Sun Jun 13 13:04:43 2010 JST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled


~ 以下省略 ~

SMARTテストをしてみる。テスト結果は、smartctl -a で表示できる。


# smartctl -t short /dev/sda

■ 自動起動の設定

サービスの起動チェック。 ランレベル2がoffなら、onに変更しておく


# sysv-rc-conf --list | grep smart
smartmontool 1:off 2:on 3:on 4:on 5:on

常駐化の設定をする。 機能設定は/etc/smartd.conf で行うので、ディスク指定やインターバル指定は行わない。

/etc/default/smartmontools

# List of devices you want to explicitly enable S.M.A.R.T. for
# Not needed (and not recommended) if the device is monitored by smartd
#enable_smart="/dev/hda /dev/hdb"

# uncomment to start smartd on system startup
start_smartd=yes ← この設定のみ有効化する

# uncomment to pass additional options to smartd on startup
#smartd_opts="--interval=1800"

■ 設定ファイルの編集

/dev/sdaのSATAディスクをチェックして、エラーの場合に root@localhost にメールするよう設定する。

/etc/smartd.conf

# The word DEVICESCAN will cause any remaining lines in this
# configuration file to be ignored: it tells smartd to scan for all
# ATA and SCSI devices. DEVICESCAN may be followed by any of the
# Directives listed below, which will be applied to all devices that
# are found. Most users should comment out DEVICESCAN and explicitly
# list the devices that they wish to monitor.
#DEVICESCAN -m root -M exec /usr/share/smartmontools/smartd-runner ← コメントアウトする

/dev/sda -a -d ata -m root@localhost

■ smartdのリスタートとエラーチェック


# /etc/init.d/smartmontools restart
* Restarting S.M.A.R.T. daemon smartd [ OK ]

上記のように常駐したという表示が出たら、/var/log/syslog にエラーが吐き出されていないかチェックする。