Friday, February 27, 2015

check serial hard disk on Ubuntu | CentOS

1. sudo smartctl -i -H -c /dev/sda
** for CentOS install package

yum install smartmontools
 
 
vim /etc/smartmontools/smartd.conf
smartctl 6.2 2013-07-26 r3841 [i686-linux-3.13.0-46-generic] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Model Family:     Seagate Momentus 5400.6
Device Model:     ST9500325AS
Serial Number:    6VEMGZEG
LU WWN Device Id: 5 000c50 032cbc8df
Firmware Version: 0001SDM1
User Capacity:    500,107,862,016 bytes [500 GB]
Sector Size:      512 bytes logical/physical
Rotation Rate:    5400 rpm
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   ATA8-ACS T13/1699-D revision 4
SATA Version is:  SATA 2.6, 3.0 Gb/s
Local Time is:    Fri Feb 27 16:42:48 2015 ICT
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:                (    0) 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:        (   1) minutes.
Extended self-test routine
recommended polling time:        ( 144) minutes.
Conveyance self-test routine
recommended polling time:        (   2) minutes.
SCT capabilities:              (0x103b) SCT Status supported.
                                        SCT Error Recovery Control supported.
                                        SCT Feature Control supported.
                                        SCT Data Table supported.

** ปรับให้ smartd check disk แล้วส่งเมลแจ้งเมื่อพบ Error
vim /etc/smartmontools/smartd.conf
vim /etc/smartmontools/smartd.conf
vim /etc/smartmontools/smartd.conf
vim /etc/smartmontools/smartd.conf
vim /etc/smartmontools/smartd.conf
vim /etc/smartmontools/smartd.conf

---edit---
#1
# Monitor SMART status, ATA Error Log, Self-test log, and track
# changes in all attributes except for attribute 194
#/dev/sdb -H -l error -l selftest -t -I 194
/dev/sda -a -I 194 -W 4,45,55 -R 5 -m admin@domain.com (-ระบุผู้รับเมล)

#2
# A very silent check.  Only report SMART health status if it fails
# But send an email in this case
#/dev/sdc -H -C 0 -U 0 -m admin@example.com
#/dev/sdc -a -m admin@example.com
/dev/sda -H -C 0 -U 0 -m admin@domain.com (-ระบุผู้รับเม)
/dev/sdb -H -C 0 -U 0 -m admin@domain.com
/dev/sdc -H -C 0 -U 0 -m admin@domain.com
/dev/sdd -H -C 0 -U 0 -m admin@domain.com

-----------------

start service smartd on CentOS
systemctl enable smartd.service
systemctl start smartd.service
systemctl reload smartd.service
systemctl status smartd.service
check status is running
systemctl |grep smartd.service

ทำ Crontab เพื่อให้ smartd ค่อย monitor hard disk
# vim systemctlreload.sh
systemctl reload smartd
# chmod u+x systemctlreload.sh
# vim /etc/crontab
05 05 * * * root /root/systemctlreload.sh

ปรับแต่งการส่งเมลโดยให้ส่งเมลจาก Sender ที่เราต้องการ และปรับแต่ง Subject
vim /etc/smartmontools/smartd_warning.sh
----------------------------------------------------
# Format subject
export SMARTD_SUBJECT="ALERT: SMART error (${SMARTD_FAILTYPE-[SMARTD_FAILTYPE]}) detected on host: $hostname"

# Send mail, use platform mailer by default
  test -n "$SMARTD_MAILER" || SMARTD_MAILER=$os_mailer
  if [ -n "$dryrun" ]; then
    echo "exec '$SMARTD_MAILER' -s '$SMARTD_SUBJECT' -r "noreply@domain.com" $SMARTD_ADDRESS <$fullmessage
EOF"
  else
    exec "$SMARTD_MAILER" -s "$SMARTD_SUBJECT" -r "noreply@domain.com" $SMARTD_ADDRESS <$fullmessage
EOF
  fi
-----------------------------------------------------

หลังปรับ /etc/smartmontools/smartd_warning.sh ทดสอบสคริปด้วยคำสั่ง systemctl reload smartd.service แล้วรันคำสั่ง tail -f /var/log/maillog ดูว่าส่งเมลด้วย Sender ที่เราระบุไหม

vim /etc/smartmontools/smartd.conf
vim /etc/smartmontools/smartd.conf
2. sudo apt-get install lshw
#lshw -class disk
  *-disk                
       description: ATA Disk
       product: ST31500341AS
       vendor: Seagate
       physical id: 0.0.0
       bus info: scsi@2:0.0.0
       logical name: /dev/sda
       version: CC1H
       serial: 9VS1LZJJ
       size: 1397GiB (1500GB)
       capabilities: partitioned partitioned:dos
       configuration: ansiversion=5 signature=1e5b6b6d

Ref: 1.smartd
       2. how-to-monitor-disk-health-with-smartd-s-m-a-r-t

3. df -aTh

Ref:
smartctl

4. check disk health with Graphic mode
on ubuntu install package gsmartcontrol

sudo apt-get install gsmartcontrol

sudo gsmartcontrol






Ref:
gsmartcontrol

No comments: