在Linux服务器中,硬盘是存储数据的关键部件,为了确保硬盘的正常运行和数据的安全,我们需要定期检测硬盘的状况,Smartmontools是一款功能强大的硬盘检测工具,它可以帮助我们实时监控硬盘的状态,包括SMART信息、磁盘健康状态等,本文将介绍如何在Linux服务器上使用Smartmontools检测硬盘状况。
安装Smartmontools
在Linux服务器上安装Smartmontools之前,首先需要确认系统内核是否支持SCSI设备,可以通过以下命令查看:
grep -i scsi /boot/config-$(uname -r)
如果输出结果包含CONFIG_SCSI=y
,则表示系统内核支持SCSI设备,接下来,我们可以使用以下命令安装Smartmontools:
对于基于Debian的系统(如Ubuntu):
sudo apt-get update sudo apt-get install smartmontools
对于基于RPM的系统(如CentOS):
sudo yum install smartmontools
使用Smartmontools检测硬盘状况
1、获取硬盘信息
我们需要获取硬盘的信息,包括型号、序列号等,可以使用以下命令查看:
smartctl -i /dev/sda
/dev/sda
是硬盘的设备文件,请根据实际情况替换为你的硬盘设备文件,执行该命令后,你将看到类似以下的输出:
smartctl 6.6 2016-05-31 r3641 [x86_64-linux-4.4.0-139-generic] (local build)
Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org
START OF INFORMATION SECTION
Model Name: Western Digital WDC WD10EZEX-00BN5A0
Serial Number: 3D5XXXXXXXXXXXXXXXXXXXXXXXXX
Firmware Version: F00
SMC Version (system): 2238
Transport: serial, USB ATA bridge (compatible; MSFT50x0/MSFT51x0/SAMSUNG MPT AHCI Controller)
Standards: Intelligent Power Management version 1.1, SMART Management Protocol version 3.0b
Capabilities: Advanced Error Reporting, AAM, APM, ATAPI[m], auto-activate, auto-poweroff, context-menu, copy-only, current-read, DE_ATAPI[m], DE_MULTI_LOCK, DE_PCI_TO_USB, DE_RAID_SETTINGS, DE_REPORT_STATUS, DE_REPORT_OPTIONS, DE_SATA_DISC_OPTIONS, DE_SATA_DOWNLOAD_OPTIONS, DE_SATA_PM, DE_SATA_SMART, DE_SCAN, DE_SHUTDOWN, disk-erase, drive-locked, drive-unlocked, Eject Media, FLUSH CACHE, LEGAL_NOTICES, LOCAL_OFFLINE, NON-REMOVABLE, PERSISTENT_SECURITY, read-only, REPORT_SMART, SATA DISC CRC error correction support, SATA link power management, SATA Native Command Queuing, SATA hot plug, SATA NCQ data transfer rate enhancements, S.M.A.R.T. capabilities, security lock release, SMART self-test logging, SMART self-test save sets, SMART support is available from the command line, TRIM supported, Undelete reporting type for Mac OS X, write-cacheable
Manufacturer Specific Properties: id727badc9-4ecd-4e91-a94f-f9a0b2c788ab fwDE940AAB vrr123456789ABCDEFGH vendorWD modelWDC WD10EZEX-00BN5A0 serial3D5XXXXXXXXXXXXXXXXXXXXXXXXX blks4883 pvs32 lba5242774 alignment512 sectors/track63 sectors/allocation unit512 signature0000000000000000 firmware versionF00 not all bytes are printable! SMC Version (disk): 2D38 revision2638 standard version: not specified enhanced version: 2D38 revision2638 custom version: 2D38 revision2638 supports: not specified not supported: not specified manufacturer: Western Digital Corporation product id: WD10EZEX-00BN5A0 physical id: 1 type: IDE (ATA) partition scheme: gpt specifiers: None user label: (no label) capacity: 953.7 GB (95367716416 bytes) rotational offset: nan logical block size: 512 bytes physical block size: 4096 bytes sector size: 4096 bytes interface type: sata invariant features: (none) compatible features: (none) parts list: serial number is "3D5XXXXXXXXXXXXXXXXXXXXXXXXX" model number is "Western Digital WDC WD10EZEX-00BN5A0" firmware version is "F00" voltage is "SSTL 1.8" frequency is "5400" inductive load is "16.75" current is "1.28" out put capacitance is "16.77" SMC revision (system): 2D38 vendor specific physical id: 1 type: SMC rev id (system): 2D38 configuration id: (none) SMC revision (disk): 2D38 vendor specific physical id: 1 type: SMC rev id (disk): 2D38 configuration id: (none) smartctl version: 6.6 2016-05-31 r3641 bus info: serial@0xfd2348e8 port@o speed=1.5 Gbps (estimated) locale=en-US bits=8 data=9 stop=1 time=64 clk=664 parity=N stop=1 flow=0 compression=disabled caps=7 hwcard=internal slot=4 config={} interface={} bind={} stat={} transport={} transfersize=953GiB bandwidth=199.9Gbit/s nvme version=1.3 subsystem=pci serial@fd2348e8-WDC WD10EZEX-00BN5A0 portnum=4 state=running mode=exclusive process=2777 owner=root latency=59.9 ms path="/dev/sda" queued=false multisession=true errors=<br>...--省略部分输出信息--...</pre>
从输出信息中,我们可以得到硬盘的型号、序列号、固件版本等信息,这些信息有助于我们了解硬盘的基本情况。
2、检查硬盘健康状况
接下来,我们可以使用Smartmontools的smartctl
命令检查硬盘的健康状况,我们可以使用以下命令检查硬盘的健康状态:
smartctl -H /dev/sda
/dev/sda
是硬盘的设备文件,请根据实际情况替换为你的硬盘设备文件,执行该命令后,你将看到类似以下的输出:
smartctl 6.6 2016-05-31 r3641 [x86_64-linux-4.4.0-139-generic] (local build)
Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org
START OF INFORMATION SECTION
Model Name: Western Digital WDC WD10EZEX-00BN5A0
Serial Number: 3D5XXXXXXXXXXXXXXXXXXXXXXXXX
Firmware Version: F00
SMC Version (system): 2238
Transport: serial, USB ATA bridge (compatible; MSFT50x0/MSFT51x0/SAMSUNG MPT AHCI Controller)
Standards: Intelligent Power Management version 1.1, SMART Management Protocol version 3.0b
Capabilities: Advanced Error Reporting, AAM, APM, ATAPI[m], auto-activate, auto-poweroff, context-menu, copy-only,
原创文章,作者:K-seo,如若转载,请注明出处:https://www.kdun.cn/ask/262863.html