服务器磁盘出问题的征兆通常是 IO 变慢、日志报 ext4 error,等到完全挂掉再处理,数据恢复成本极高。SMART 数据是硬盘自己暴露的健康指标,smartctl 能把它读出来,是站长最应该掌握的监控手段之一。
smartmontools 7.5 是当前稳定版本,支持 SATA、NVMe、SAS 设备,新增 JSON 输出、NVMe 命名空间健康信息、可用备用块检查等。smartctl 做一次性检查,smartd 做后台守护监控,两者配合使用最好。
# 安装 smartmontools
# Debian/Ubuntu: apt install smartmontools
# CentOS/RHEL: yum install smartmontools
# 1. 查看磁盘基本信息
smartctl -i /dev/sda
# 2. 完整健康报告(关键命令)
smartctl -H -a /dev/sda
# 3. 重点关注属性(输出示例)
# Reallocated_Sector_Ct 重映射扇区数 >0 要警惕
# Current_Pending_Sector 待映射扇区数 >0 尽快备份
# Power_On_Hours 通电时间,判断寿命
# Temperature_Celsius 温度过高会加速老化
# Percentage_Used NVMe 剩余寿命百分比
# 4. 配置 smartd 自动监控(/etc/smartd.conf 示例)
# 每天凌晨 2 点自检,异常时发邮件
DEVICESCAN -a -o on -S on -s (S/../.././02|L/../../6/03) -m admin@example.com
# 5. 手动触发短自检
smartctl -t short /dev/sda
# 查看结果
smartctl -l selftest /dev/sda
机械硬盘看 Reallocated_Sector_Ct 和 Current_Pending_Sector,SSD 看 Wear_Leveling_Count 或 NVMe 的 Percentage_Used。任何一项开始计数异常,都要立即备份并准备换盘。
磁盘监控最忌讳“看了没行动”。建议把 smartctl 的结果写进每日巡检脚本,配合邮件或企业微信告警。数据无价,硬盘却是消耗品,早发现早处理。
数据来源:smartmontools官方文档
申请创业报道,分享创业好点子。点击此处,共同探讨创业新机遇!

