Software-Raid

在高可用性軟體 RAID 1 伺服器上使用 smartd(在 smartmontools 中)監控磁碟執行狀況

  • April 1, 2014

我有一台帶有三個相同 SATA/600 3TB 驅動器的伺服器:/dev/sda, /dev/sdb, /dev/sdc. 使用 GPT 對驅動器進行分區,每個分區具有三個分區:

  • 1 MB:為引導載入程序保留的分區
  • 1 GB:RAID1 /dev/md0(ext2(/boot))
  • 3 TB:RAID1 /dev/md1(加密卷(LVM(卷組(交換、/、/etc、/home …))))

三個驅動器之一是熱備用,另外兩個在 RAID 集中處於活動狀態。它工作正常,我可以在斷開任何單個 HDD 後啟動。我想使用smartd(smartmontools 的一部分)來監控驅動器的執行狀況並向 syslog(我使用logcheck監控)報告錯誤。此伺服器應具有盡可能高的可用性,但在測試期間性能降低是可以接受的。

這是輸出smartctl -a /dev/sda

smartctl 5.41 2011-06-09 r3365 [x86_64-linux-3.2.0-4-amd64] (local build)
Copyright (C) 2002-11 by Bruce Allen, http://smartmontools.sourceforge.net

=== START OF INFORMATION SECTION ===
Device Model:     WDC WD30EZRX-00MMMB0
Serial Number:    WD-WMAWZ0412093
LU WWN Device Id: 5 0014ee 2b19fbdcd
Firmware Version: 80.00A80
User Capacity:    3,000,592,982,016 bytes [3.00 TB]
Sector Sizes:     512 bytes logical, 4096 bytes physical
Device is:        Not in smartctl database [for details use: -P showall]
ATA Version is:   8
ATA Standard is:  Exact ATA specification draft version not indicated
Local Time is:    Fri Sep 27 15:37:25 2013 CEST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED

General SMART Values:
Offline data collection status:  (0x82) Offline data collection activity
                   was completed without error.
                   Auto Offline Data Collection: Enabled.
Self-test execution status:      (   0) The previous self-test routine completed
                   without error or no self-test has ever 
                   been run.
Total time to complete Offline 
data collection:        (50280) seconds.
Offline data collection
capabilities:            (0x7b) SMART execute Offline immediate.
                   Auto Offline data collection on/off support.
                   Suspend Offline collection upon new
                   command.
                   Offline surface scan supported.
                   Self-test supported.
                   Conveyance Self-test supported.
                   Selective Self-test supported.
SMART capabilities:            (0x0003) Saves SMART data before entering
                   power-saving mode.
                   Supports SMART auto save timer.
Error logging capability:        (0x01) Error logging supported.
                   General Purpose Logging supported.
Short self-test routine 
recommended polling time:    (   2) minutes.
Extended self-test routine
recommended polling time:    ( 255) minutes.
Conveyance self-test routine
recommended polling time:    (   5) minutes.
SCT capabilities:          (0x3035) SCT Status supported.
                   SCT Feature Control supported.
                   SCT Data Table supported.

SMART Attributes Data Structure revision number: 16
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
 1 Raw_Read_Error_Rate     0x002f   200   200   051    Pre-fail  Always       -       0
 3 Spin_Up_Time            0x0027   148   148   021    Pre-fail  Always       -       9575
 4 Start_Stop_Count        0x0032   100   100   000    Old_age   Always       -       95
 5 Reallocated_Sector_Ct   0x0033   200   200   140    Pre-fail  Always       -       0
 7 Seek_Error_Rate         0x002e   200   200   000    Old_age   Always       -       0
 9 Power_On_Hours          0x0032   099   099   000    Old_age   Always       -       820
10 Spin_Retry_Count        0x0032   100   253   000    Old_age   Always       -       0
11 Calibration_Retry_Count 0x0032   100   253   000    Old_age   Always       -       0
12 Power_Cycle_Count       0x0032   100   100   000    Old_age   Always       -       93
192 Power-Off_Retract_Count 0x0032   200   200   000    Old_age   Always       -       65
193 Load_Cycle_Count        0x0032   196   196   000    Old_age   Always       -       12824
194 Temperature_Celsius     0x0022   119   116   000    Old_age   Always       -       33
196 Reallocated_Event_Count 0x0032   200   200   000    Old_age   Always       -       0
197 Current_Pending_Sector  0x0032   200   200   000    Old_age   Always       -       0
198 Offline_Uncorrectable   0x0030   200   200   000    Old_age   Offline      -       0
199 UDMA_CRC_Error_Count    0x0032   200   200   000    Old_age   Always       -       0
200 Multi_Zone_Error_Rate   0x0008   200   200   000    Old_age   Offline      -       0

SMART Error Log Version: 1
No Errors Logged

SMART Self-test log structure revision number 1
Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error
# 1  Short offline       Completed without error       00%       787         -
# 2  Extended offline    Completed without error       00%       727         -

SMART Selective self-test log data structure revision number 1
SPAN  MIN_LBA  MAX_LBA  CURRENT_TEST_STATUS
   1        0        0  Not_testing
   2        0        0  Not_testing
   3        0        0  Not_testing
   4        0        0  Not_testing
   5        0        0  Not_testing
Selective self-test flags (0x0):
 After scanning selected spans, do NOT read-scan remainder of disk.
If Selective self-test is pending on power-up, resume after 0 minute delay.

似乎支持離線測試。當我發出smartctl -o on時,smartctl -c說明Offline data collection status已經設置為(0x82)。如果我發出smartctl -o off相同的值變為(0x02).

我已經設置 smartd 通過設置啟動伺服器start_smartd=yes/etc/default/smartmontools您如何建議我通過編輯/etc/smartd.conf為此伺服器配置 smartd?請描述您使用的每個參數以及您使用它的原因。

我將添加我目前的設置作為答案。隨意將其用作基礎並在您自己的答案中進行改進。使用相同設置進行更好的描述也是一種改進!

我從長時間的自測切換到select,cont測試。這就像長時間的自檢,但一次只有一片磁碟。因此,雖然長時間的自測可能需要一天以上的時間(使用原本繁忙的 3TB 磁碟),但選擇性測試可以在伺服器最不繁忙的每晚執行並實際完成,而不會在更繁忙的時間損害性能。

因此,基本上您將分發整個磁碟的每月長自測,到在一個月的過程中仍然覆蓋整個磁碟的夜間選擇性測試。

不過這需要一些準備。

  • smartd必須使用該--savestates選項執行,因為磁碟本身通常不會跟踪最後測試的區域。
  • 您必須手動啟動第一次選擇性自檢 ( -t select,0-$size),這樣smartd才能知道每天要測試的切片大小。大小決定了測試需要多長時間以及跨越整個磁碟的天數。
  • 確保您選擇的 $size 與磁碟大小對齊。否則,您可能會冒最後一個切片非常小的風險(最壞的情況是您浪費一天時間只測試磁碟的單個扇區)。
  • 您必須驗證此資訊是否確實進入了 savestates 文件,因為有時它不會,然後測試將不會按照您想要的方式執行。(直接編輯保存狀態文件也是一種選擇)。
  • smartd.conf文件的語法是-s c/../.././01(在此範例中,它將在每天凌晨 1 點執行)。

一旦完成,該過程是自動且可靠的。一旦到達磁碟的末尾,它將在第二天開始時自動開始。閱讀smartctl有關select,cont測試的手冊頁。

雖然長期或選擇性測試很棒,但您可能仍應進行短期或整體評估測試。它們只需要很短的時間,可能有助於檢測一般問題。

我們已將所有伺服器配置為執行正常自測,其中包含以下行/etc/smartd.conf

# DEVICESCAN matches all hard disks found in /dev/ and applies the following
# options to them.
#
# Default options from Debian:
# -d removable     don't exit when the device when a device vanishes
# -n standby       don't wake a device up that is sleeping
# -m root          send error reports to root
# -M exec ...      pipe the mail through that script
#
# Our options:
# -s L/../02/./17  run a long selftest on every 2nd of every month
#                  at 17 o'clock
DEVICESCAN -d removable -n standby -m root -M exec /usr/share/smartmontools/smartd-runner -s L/../02/./17

自檢是 IMO SMART 提供的最可靠的健康檢查。


編輯:

你能解釋一下是什麼-d removable嗎?

來自man smartd.conf

         removable - the device or its media is  removable.   This  indi‐
         cates  to  smartd  that  it should continue (instead of exiting,
         which is the default behavior) if the device does not appear  to
         be  present  when smartd is started.  This Directive may be used
         in conjunction with the other ´-d´ Directives.

我認為smartd當其中一個受監控的磁碟消失時,它可以防止死亡……?我不確定,我只是將-s L/../02/./17部分添加到該行。原行:

DEVICESCAN -d removable -n standby -m root -M exec /usr/share/smartmontools/smartd-runner

是 Debian 的預設設置。

引用自:https://unix.stackexchange.com/questions/92655