在Linux中使用Smartctl监控磁盘性能的方法
程序员文章站
2022-06-20 08:32:47
这篇文章主要介绍了在Linux中使用Smartctl监控磁盘性能的方法,特别对于服务器来说,磁盘的健康度信息非常重要,需要的朋友可以参考下... 15-06-12...
smartctl(s.m.a.r.t 自监控,分析和报告技术)是类unix系统下实施smart任务命令行套件或工具,它用于打印smart自检和错误日志,启用并禁用smrat自动检测,以及初始化设备自检。
smartctl对于linux物理服务器十分有用,在这些服务器上,可以对智能磁盘进行错误检查,并将与硬件raid相关的磁盘信息摘录下来。
在本帖中,我们将讨论smartctl命令的一些实用样例。如果你的linux上海没有安装smartctl,请按以下步骤来安装。
安装 smartctl
对于 ubuntu
复制代码
代码如下:$ sudo apt-get install smartmontools
对于 centos & rhel
复制代码
代码如下:# yum install smartmontools
启动smartctl服务
对于 ubuntu
复制代码
代码如下:$ sudo /etc/init.d/smartmontools start
对于 centos & rhel
复制代码
代码如下: # service smartd start ; chkconfig smartd on
样例
样例:1 检查磁盘的 smart 功能是否启用
复制代码
代码如下: root@linuxtechi:~# smartctl -i /dev/sdb
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.13.0-32-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: st9320325as
serial number: 5vd2v59t
lu wwn device id: 5 000c50 020a37ec4
firmware version: 0002bsm1
user capacity: 320,072,933,376 bytes [320 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, 1.5 gb/s
local time is: sun nov 16 12:32:09 2014 ist
smart support is: available - device has smart capability.
smart support is: enabled
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.13.0-32-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: st9320325as
serial number: 5vd2v59t
lu wwn device id: 5 000c50 020a37ec4
firmware version: 0002bsm1
user capacity: 320,072,933,376 bytes [320 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, 1.5 gb/s
local time is: sun nov 16 12:32:09 2014 ist
smart support is: available - device has smart capability.
smart support is: enabled
这里‘/dev/sdb’是你的硬盘。上面输出中的最后两行显示了smart功能已启用。
样例:2 启用磁盘的 smart 功能
复制代码
代码如下:root@linuxtechi:~# smartctl -s on /dev/sdb
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.13.0-32-generic] (local build)
copyright (c) 2002-13, bruce allen, christian franke, www.smartmontools.org
=== start of enable/disable commands section ===
smart enabled.
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.13.0-32-generic] (local build)
copyright (c) 2002-13, bruce allen, christian franke, www.smartmontools.org
=== start of enable/disable commands section ===
smart enabled.
样例:3 禁用磁盘的 smart 功能
复制代码
代码如下: root@linuxtechi:~# smartctl -s off /dev/sdb
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.13.0-32-generic] (local build)
copyright (c) 2002-13, bruce allen, christian franke, www.smartmontools.org
=== start of enable/disable commands section ===
smart disabled. use option -s with argument 'on' to enable it.
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.13.0-32-generic] (local build)
copyright (c) 2002-13, bruce allen, christian franke, www.smartmontools.org
=== start of enable/disable commands section ===
smart disabled. use option -s with argument 'on' to enable it.
样例:4 显示磁盘的详细 smart 信息
复制代码
代码如下:root@linuxtechi:~# smartctl -a /dev/sdb // for ide drive
root@linuxtechi:~# smartctl -a -d ata /dev/sdb // for sata drive
root@linuxtechi:~# smartctl -a -d ata /dev/sdb // for sata drive
样例:5 显示磁盘总体健康状况
复制代码
代码如下:root@linuxtechi:~# smartctl -h /dev/sdb
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.13.0-32-generic] (local build)
copyright (c) 2002-13, bruce allen, christian franke, www.smartmontools.org
=== start of read smart data section ===
smart overall-health self-assessment test result: passed
warning: this result is based on an attribute check.
please note the following marginal attributes:
id# attribute_name flag value worst thresh type updated when_failed raw_value
190 airflow_temperature_cel 0x0022 067 045 045 old_age always in_the_past 33 (min/max 25/33)
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.13.0-32-generic] (local build)
copyright (c) 2002-13, bruce allen, christian franke, www.smartmontools.org
=== start of read smart data section ===
smart overall-health self-assessment test result: passed
warning: this result is based on an attribute check.
please note the following marginal attributes:
id# attribute_name flag value worst thresh type updated when_failed raw_value
190 airflow_temperature_cel 0x0022 067 045 045 old_age always in_the_past 33 (min/max 25/33)
样例:6 使用long和short选项测试硬盘
long测试
复制代码
代码如下:root@linuxtechi:~# smartctl --test=long /dev/sdb
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.13.0-32-generic] (local build)
copyright (c) 2002-13, bruce allen, christian franke, www.smartmontools.org
=== start of offline immediate and self-test section ===
sending command: "execute smart extended self-test routine immediately in off-line mode".
drive command "execute smart extended self-test routine immediately in off-line mode" successful.
testing has begun.
please wait 102 minutes for test to complete.
test will complete after sun nov 16 14:29:43 2014
use smartctl -x to abort test.
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.13.0-32-generic] (local build)
copyright (c) 2002-13, bruce allen, christian franke, www.smartmontools.org
=== start of offline immediate and self-test section ===
sending command: "execute smart extended self-test routine immediately in off-line mode".
drive command "execute smart extended self-test routine immediately in off-line mode" successful.
testing has begun.
please wait 102 minutes for test to complete.
test will complete after sun nov 16 14:29:43 2014
use smartctl -x to abort test.
或者,我们可以重定向测试输出到日志文件,就像下面这样
复制代码
代码如下:root@linuxtechi:~# smartctl --test=long /dev/sdb > /var/log/long.text
short测试
复制代码
代码如下:root@linuxtechi:~# smartctl --test=short /dev/sdb
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.13.0-32-generic] (local build)
copyright (c) 2002-13, bruce allen, christian franke, www.smartmontools.org
=== start of offline immediate and self-test section ===
sending command: "execute smart short self-test routine immediately in off-line mode".
drive command "execute smart short self-test routine immediately in off-line mode" successful.
testing has begun.
please wait 1 minutes for test to complete.
test will complete after sun nov 16 12:51:45 2014
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.13.0-32-generic] (local build)
copyright (c) 2002-13, bruce allen, christian franke, www.smartmontools.org
=== start of offline immediate and self-test section ===
sending command: "execute smart short self-test routine immediately in off-line mode".
drive command "execute smart short self-test routine immediately in off-line mode" successful.
testing has begun.
please wait 1 minutes for test to complete.
test will complete after sun nov 16 12:51:45 2014
use smartctl -x to abort test.
或
复制代码
代码如下:root@linuxtechi:~# smartctl --test=short /dev/sdb > /var/log/short.text
注意:short测试将花费最多2分钟,而在long测试中没有时间限制,因为它会读取并验证磁盘的每个段。
样例:7 查看驱动器的自检结果
复制代码
代码如下:root@linuxtechi:~# smartctl -l selftest /dev/sdb
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.13.0-32-generic] (local build)
copyright (c) 2002-13, bruce allen, christian franke, www.smartmontools.org
=== start of read smart data section ===
smart self-test log structure revision number 1
num test_description status remaining lifetime(hours) lba_of_first_error
# 1 short offline completed: read failure 90% 492 210841222
# 2 extended offline completed: read failure 90% 492 210841222
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.13.0-32-generic] (local build)
copyright (c) 2002-13, bruce allen, christian franke, www.smartmontools.org
=== start of read smart data section ===
smart self-test log structure revision number 1
num test_description status remaining lifetime(hours) lba_of_first_error
# 1 short offline completed: read failure 90% 492 210841222
# 2 extended offline completed: read failure 90% 492 210841222
样例:8 计算测试时间估值
复制代码
代码如下:root@linuxtechi:~# smartctl -c /dev/sdb
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.13.0-32-generic] (local build)
copyright (c) 2002-13, bruce allen, christian franke, www.smartmontools.org
=== start of read smart data section ===
general smart values:
offline data collection status: (0x00) offline data collection activity
was never started.
auto offline data collection: disabled.
self-test execution status: ( 121) the previous self-test completed having
the read element of the test failed.
total time to complete offline
data collection: ( 0) seconds.
offline data collection
capabilities: (0x73) smart execute offline immediate.
auto offline data collection on/off support.
suspend offline collection upon new
command.
no 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: ( 102) 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.
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.13.0-32-generic] (local build)
copyright (c) 2002-13, bruce allen, christian franke, www.smartmontools.org
=== start of read smart data section ===
general smart values:
offline data collection status: (0x00) offline data collection activity
was never started.
auto offline data collection: disabled.
self-test execution status: ( 121) the previous self-test completed having
the read element of the test failed.
total time to complete offline
data collection: ( 0) seconds.
offline data collection
capabilities: (0x73) smart execute offline immediate.
auto offline data collection on/off support.
suspend offline collection upon new
command.
no 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: ( 102) 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.
样例:9 显示磁盘错误日志
复制代码
代码如下:root@linuxtechi:~# smartctl -l error /dev/sdb
sample output
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.13.0-32-generic] (local build)
copyright (c) 2002-13, bruce allen, christian franke, www.smartmontools.org
=== start of read smart data section ===
smart error log version: 1
ata error count: 5
cr = command register [hex]
fr = features register [hex]
sc = sector count register [hex]
sn = sector number register [hex]
cl = cylinder low register [hex]
ch = cylinder high register [hex]
dh = device/head register [hex]
dc = device command register [hex]
er = error register [hex]
st = status register [hex]
powered_up_time is measured from power on, and printed as
ddd+hh:mm:ss.sss where dd=days, hh=hours, mm=minutes,
ss=sec, and sss=millisec. it "wraps" after 49.710 days.
commands leading to the command that caused the error were:
cr fr sc sn cl ch dh dc powered_up_time command/feature_name
-- -- -- -- -- -- -- -- ---------------- --------------------
25 da 08 e7 e5 a5 4c 00 00:30:44.515 read dma ext
25 da 08 df e5 a5 4c 00 00:30:44.514 read dma ext
25 da 80 5f e5 a5 4c 00 00:30:44.502 read dma ext
25 da f0 5f e6 a5 4c 00 00:30:44.496 read dma ext
25 da 10 4f e6 a5 4c 00 00:30:44.383 read dma ext
sample output
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.13.0-32-generic] (local build)
copyright (c) 2002-13, bruce allen, christian franke, www.smartmontools.org
=== start of read smart data section ===
smart error log version: 1
ata error count: 5
cr = command register [hex]
fr = features register [hex]
sc = sector count register [hex]
sn = sector number register [hex]
cl = cylinder low register [hex]
ch = cylinder high register [hex]
dh = device/head register [hex]
dc = device command register [hex]
er = error register [hex]
st = status register [hex]
powered_up_time is measured from power on, and printed as
ddd+hh:mm:ss.sss where dd=days, hh=hours, mm=minutes,
ss=sec, and sss=millisec. it "wraps" after 49.710 days.
commands leading to the command that caused the error were:
cr fr sc sn cl ch dh dc powered_up_time command/feature_name
-- -- -- -- -- -- -- -- ---------------- --------------------
25 da 08 e7 e5 a5 4c 00 00:30:44.515 read dma ext
25 da 08 df e5 a5 4c 00 00:30:44.514 read dma ext
25 da 80 5f e5 a5 4c 00 00:30:44.502 read dma ext
25 da f0 5f e6 a5 4c 00 00:30:44.496 read dma ext
25 da 10 4f e6 a5 4c 00 00:30:44.383 read dma ext
上一篇: Python—闭包和装饰器
推荐阅读
-
在Linux中使用Smartctl监控磁盘性能的方法
-
Linux中在不破坏磁盘的情况下使用dd命令
-
在 Linux 中不使用 CD 命令进入目录/文件夹的方法
-
在Linux中使用Smartctl监控磁盘性能的方法
-
在Linux系统中安装配置性能监控软件Munin的教程
-
在Linux中安装是使用系统性能监控软件Nmon
-
性能监控 - 如何检测PHP某个方法 在一次请求中调用了多少次,每次的耗时和耗内存情况?
-
Linux中在不破坏磁盘的情况下使用dd命令
-
性能监控 - 如何检测PHP某个方法 在一次请求中调用了多少次,每次的耗时和耗内存情况?
-
window phone7开发中的性能、内存使用监控方法