自建私有云服务器,运行的服务比较多,但是硬件是一台淘汰的家庭台式机,硬件是不可靠的。
由于硬件不可靠,那么硬件损坏可以接受,但是数据不能丢失。
关于数据备份,可参考 自建NAS,如何备份数据?
所以需要增加硬盘健康监控的功能,当硬盘告警时,立刻发送邮件进行提醒。
1. 安装smartmontools
sudo apt install smartmontools
2. 修改 /etc/default/smartmontools 文件,启用smartd(开机启动)
start_smartd=yes
3. 修改 /etc/smartd.conf 文件,定时每天凌晨1点~2点检测硬盘监控状况
/dev/sda -H -l error -l selftest -f -s (S/../.././01) -m \
yourname@serv.com -M exec /usr/share/smartmontools/smartd-runner
4. 最后重启smart服务
sudo service smartmontools restart
编辑文件 /etc/smartd.conf ,修改 -M 参数 为 test,如下
/dev/sda -H -l error -l selftest -f -s (S/../.././01) -m yourname@serv.com -M test
然后重启服务
service smartmontools restart
此时如果能收到类似如下内容的邮件,说明正常运行
This message was generated by the smartd daemon running on:
host name: yxhserver
DNS domain: [Empty]
The following warning/error was logged by the smartd daemon:
TEST EMAIL from smartd for device: /dev/sda [SAT]
Device info:
WDC WD10EZEX-22MFCA0, S/N:WD-WCC6Y6CU80EV, WWN:5-0014ee-2bdc7e682, FW:01.01A01, 1.00 TB
For details see host's SYSLOG.
smartd参数说明:
-H : 磁盘健康状况 ([ATA only] Check the SMART health status of the disk)
-l selftest : 磁盘自检日志
-l error : 磁盘错误日志
-f : 检测所有属性值,如果属性值大于阈值,则报警。
-s : 定时执行 ,格式 T/MM/DD/d/HH ; (类型/月份/日期/星期几/小时), 这里的S代表短检测,月份、日期、小时是两位,星期几是一位
-m: 发送邮件
-M: 修改邮件的行为,必须和-m选项一起用。
-M 参数有点难描述,看原文吧:
These Directives modify the behavior of the smartd email warnings enabled with the
´-m´ email Directive described above. These ´-M´ Directives only work in conjunction with the ´-m´ Directive and can not be used without it
注意: ubuntu20.04 里的 startd-runner 脚本也是发送邮件,去掉执行该脚本、或者修改该脚本。
注意,DEVICESCAN 命令后面所有的配置都会忽略掉,如果你的检查在此命令后面, 那就不会执行。
配置文件原注释:
# The word DEVICESCAN will cause any remaining lines in this
# configuration file to be ignored: it tells smartd to scan for all
# ATA and SCSI devices. DEVICESCAN may be followed by any of the
# Directives listed below, which will be applied to all devices that
# are found. Most users should comment out DEVICESCAN and explicitly
# list the devices that they wish to monitor.
DEVICESCAN -d removable -n standby -m root -M exec /usr/share/smartmontools/smartd-runner