对于想了解CentOSsmartctl硬盘检测的读者,本文将是一篇不可错过的文章,我们将详细介绍centos硬盘检测工具,并且为您提供关于CentOS使用Smartmontools检测磁盘状态、Cen
对于想了解CentOS smartctl 硬盘检测的读者,本文将是一篇不可错过的文章,我们将详细介绍centos硬盘检测工具,并且为您提供关于CentOS 使用 Smartmontools 检测磁盘状态、Centos 怎么用 parted 分区超过 2TB 硬盘、CentOS7 中 systemctl 的使用与 CentOS6 中 service 的区别、CentOS7 硬盘检测的有价值信息。
本文目录一览:- CentOS smartctl 硬盘检测(centos硬盘检测工具)
- CentOS 使用 Smartmontools 检测磁盘状态
- Centos 怎么用 parted 分区超过 2TB 硬盘
- CentOS7 中 systemctl 的使用与 CentOS6 中 service 的区别
- CentOS7 硬盘检测
CentOS smartctl 硬盘检测(centos硬盘检测工具)
什么是S.M.A.R.T.
SMART是一种磁盘自我分析检测技术,早在90年代末就基本得到了普及
每一块硬盘(包括IDE、SCSI)在运行的时候,都会将自身的若干参数记录下来
这些参数包括型号、容量、温度、密度、扇区、寻道时间、传输、误码率等
硬盘运行了几千小时后,很多内在的物理参数都会发生变化
某一参数超过报警阈值,则说明硬盘接近损坏
此时硬盘依然在工作,如果用户不理睬这个报警继续使用
那么硬盘将变得非常不可靠,随时可能故障
启用SMART
SMART是和主板BIOS上相应功能配合的
要使用SMART,必须先进入到主板BIOS设置里边启动相关设置
一般从Pentium2级别起的主板,都支持SMART
BIOS启动以后,就是操作系统级别的事情了
很遗憾,Windows没有内置SMART相关工具(需要安装第三方工具软件)
好在Linux上很早就有了SMART支持了
如果把Linux装在VMware等虚拟机上,在系统启动时候可以看到有个服务启动报错:smartd
这个服务器就是smart的daemon进程(因为vmware虚拟机的硬盘不支持SMART,所以报错)
首先通过dmesg工具,确认一下硬盘的设备符号
例如一个IDE硬盘连接到Primary IDE 总线上的Slave位置,硬盘设备符号是/dev/hdb
hdb中的h代表IDE,如果显示为sdb,则代表SATA和SCSI
最后一个字幕b代表Primary总线,第二块硬盘即Slave位置
确认硬盘是否打开了SMART支持
smartctl -i /dev/hdb
例如看到如下返回结果
[root@3.6.0Biz-46 ~]# smartctl -i /dev/hdb
smartctl version 5.33 [i386-redhat-linux-gnu] copyright (C) 2002-4 Bruce Allen
Home page is http://smartmontools.sourceforge.net/
=== START OF informatION SECTION ===
Device Model: ST380011A
Serial Number: 3JVAPRGH
Firmware Version: 3.04
User Capacity: 80,026,361,856 bytes
Device is: In smartctl database [for details use: -P show]
ATA Version is: 6
ATA Standard is: ATA/ATAPI-6 T13 1410D revision 2
Local Time is: Tue Apr 3 15:39:52 2007 CST
SMART support is: Available ? device has SMART capability.
SMART support is: disabled
SMART disabled. Use option -s with argument ‘on’ to enable it.
[root@3.6.0Biz-46 ~]#
我们可以看到SMART support is: disabled表示SMART未启用
执行如下命令,启动SMART:
smartctl ?smart=on ?offlineauto=on ?saveauto=on /dev/hdb
例如看到如下返回结果
[root@3.6.0Biz-46 ~]# smartctl ?smart=on ?offlineauto=on ?saveauto=on /dev/hdb
smartctl version 5.33 [i386-redhat-linux-gnu] copyright (C) 2002-4 Bruce Allen
Home page is http://smartmontools.sourceforge.net/
=== START OF ENABLE/disABLE COMMANDS SECTION ===
SMART Enabled.
SMART Attribute Autosave Enabled.
SMART Automatic Offline Testing Enabled every four hours.
[root@3.6.0Biz-46 ~]#
现在硬盘的SMART功能已经被打开
执行如下命令查看硬盘的健康状况:
smartctl -H /dev/hda
例如可以看到如下结果:
[root@3.6.0Biz-46 ~]# smartctl -H /dev/hdb
smartctl version 5.33 [i386-redhat-linux-gnu] copyright (C) 2002-4 Bruce Allen
Home page is http://smartmontools.sourceforge.net/
=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED
[root@3.6.0Biz-46 ~]#
请注意result后边的结果:PASSED,这表示硬盘健康状态良好
如果这里显示Failure,那么最好立刻给服务器更换硬盘
SMART只能报告磁盘已经不再健康,但是报警后还能继续运行多久是不确定的
通常,SMART报警参数是有预留的,磁盘报警后,不会当场坏掉,一般能坚持一段时间
有的硬盘SMART报警后还继续跑了好几年,有的硬盘SMART报错后几天就坏了
但是一旦出现报警,侥幸心里是万万不能的……
执行如下命令可以看到详细的参数:
smartctl -A /dev/hdb
例如可以看到如下结果:
[root@3.6.0Biz-46 ~]# smartctl -A /dev/hdb
smartctl version 5.33 [i386-redhat-linux-gnu] copyright (C) 2002-4 Bruce Allen
Home page is http://smartmontools.sourceforge.net/
=== START OF READ SMART DATA SECTION ===
SMART Attributes Data Structure revision number: 10
vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_Failed RAW_VALUE
1 Raw_Read_Error_Rate 0x000f 053 051 006 Pre-fail Always ? 11338710
3 Spin_Up_Time 0×0003 098 097 000 Pre-fail Always ? 0
4 Start_Stop_Count 0×0032 100 100 020 Old_age Always ? 17
5 Reallocated_Sector_Ct 0×0033 100 100 036 Pre-fail Always ? 0
7 Seek_Error_Rate 0x000f 087 060 030 Pre-fail Always ? 610059516
9 Power_On_Hours 0×0032 087 087 000 Old_age Always ? 11974
10 Spin_Retry_Count 0×0013 100 100 097 Pre-fail Always ? 0
12 Power_Cycle_Count 0×0032 100 100 020 Old_age Always ? 110
194 Temperature_Celsius 0×0022 045 052 000 Old_age Always ? 45
195 Hardware_ECC_Recovered 0x001a 053 051 000 Old_age Always ? 11338710
197 Current_Pending_Sector 0×0012 100 100 000 Old_age Always ? 0
198 Offline_Uncorrectable 0×0010 100 100 000 Old_age Offline ? 0
199 UDMA_CRC_Error_Count 0x003e 200 200 000 Old_age Always ? 0
200 Multi_Zone_Error_Rate 0×0000 100 253 000 Old_age Offline ? 0
202 TA_Increase_Count 0×0032 100 253 000 Old_age Always ? 0
[root@3.6.0Biz-46 ~]#
上边列出的参数表中可供进行技术分析和参考,使用下边的命令可以输出完整结果:
smartctl -a /dev/hdb
定期登录到服务器上运行smartctl是比较麻烦的,linux提供了系统进程smartd
编辑配置文件:
vi /etc/smartd.conf
这个配置文件中大部分可能是注释掉的说明,只需要和当前硬盘相关的一行写入正确即可:
/dev/hdb -H -m test@test123123.com
上边的配置表示smartd以静默状态工作,当SMART中报告PASSED的时候不理睬
一旦出现Failure,立刻用邮件通知用户指定的邮箱
修改配置后重启服务:
/etc/init.d/smartd
即可完成对SMART的全部配置。
CentOS 使用 Smartmontools 检测磁盘状态
参考:https://help.ubuntu.com/community/Smartmontools
https://wiki.gentoo.org/wiki/Smartmontools
https://www.smartmontools.org/browser/trunk/smartmontools/smartd.conf.5.in
在此之前需要配置好 mail (参考:Linux 通过命令发送邮件 ),以便发送邮件。
修改 /etc/smartmontools/smartd.conf,删除之前的规则,加入自定义的规则。
- DEVICESCAN -H -m root -M exec /usr/libexec/smartmontools/smartdnotify -n standby,10,q
+ # xjn add
+ # 每周六1点:Offline Immediate Test,5点:Long Self-Test,9点:Conveyance Self-Test
+ DEVICESCAN -H -l error -l selftest -f -s (O/../../6/1|L/../../6/5|C/../../6/9) -m igiantpanda@163.com -M exec /usr/share/smartmontools/smartd-runner
+ # 这个是用于测试邮件发送功能的,执行"service smartd restart"就会发送邮件
+ # DEVICESCAN -H -m mailname@163.com -M test
Centos 怎么用 parted 分区超过 2TB 硬盘
1、查看 parted 命令是否安装 rpm -qa | grep parted
如果没有安装执行 yum install parted
2、使用 fdisk -l 查看当前所有硬盘
3、开始分区 parted /dev/sdb 进入分区命令
print 显示当前分区设备的容量大小
mklabel gpt 设分区为 GPT 模式
mkpart primary 0 -1 0 起始位置,-1 为最大值。注:0 和 - 1 之间有空格
print 再次查看当前分区容量大小
quit 退出
4、进行分区格式化 mkfs.ext4 /dev/sdb1
5、进行分区挂载 mount -t ext4 /dev/sdb1/home/sdb1
CentOS7 中 systemctl 的使用与 CentOS6 中 service 的区别
https://blog.csdn.net/u012834750/article/details/80501440
从 CentOS 7.x 开始,CentOS 开始使用 systemd 服务来代替 daemon,
原来管理系统启动和管理系统服务的相关命令全部由 systemctl 命令来代替。
1、原来的 service 命令与 systemctl 命令对比
daemon 命令 | systemctl 命令 | 说明 |
---|---|---|
service [服务] start | systemctl start [unit type] | 启动服务 |
service [服务] stop | systemctl stop [unit type] | 停止服务 |
service [服务] restart | systemctl restart [unit type] | 重启服务 |
此外还是二个 systemctl 参数没有与 service 命令参数对应
- status:参数来查看服务运行情况
- reload:重新加载服务,加载更新后的配置文件(并不是所有服务都支持这个参数,比如 network.service)
应用举例:
#启动网络服务
systemctl start network.service
#停止网络服务
systemctl stop network.service
#重启网络服务
systemctl restart network.service
#查看网络服务状态
systemctl status network.serivce
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
2、原来的 chkconfig 命令与 systemctl 命令对比
2.1、设置开机启动 / 不启动
daemon 命令 | systemctl 命令 | 说明 |
---|---|---|
chkconfig [服务] on | systemctl enable [unit type] | 设置服务开机启动 |
chkconfig [服务] off | systemctl disable [unit type] | 设备服务禁止开机启动 |
应用举例:
#停止cup电源管理服务
systemctl stop cups.service
#禁止cups服务开机启动
systemctl disable cups.service
#查看cups服务状态
systemctl status cups.service
#重新设置cups服务开机启动
systemctl enable cups.service
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
2.2、查看系统上上所有的服务
命令格式:
systemctl [command] [–type=TYPE] [–all]
- 1
参数详解:
command – list-units:依据 unit 列出所有启动的 unit。加上 –all 才会列出没启动的 unit; – list-unit-files: 依据 /usr/lib/systemd/system/ 内的启动文件,列出启动文件列表
–type=TYPE – 为 unit type, 主要有 service, socket, target
应用举例:
systemctl 命令 | 说明 |
---|---|
systemctl | 列出所有的系统服务 |
systemctl list-units | 列出所有启动 unit |
systemctl list-unit-files | 列出所有启动文件 |
systemctl list-units –type=service –all | 列出所有 service 类型的 unit |
systemctl list-units –type=service –all grep cpu | 列出 cpu 电源管理机制的服务 |
systemctl list-units –type=target –all | 列出所有 target |
3、systemctl 特殊的用法
systemctl 命令 | 说明 |
---|---|
systemctl is-active [unit type] | 查看服务是否运行 |
systemctl is-enable [unit type] | 查看服务是否设置为开机启动 |
systemctl mask [unit type] | 注销指定服务 |
systemctl unmask [unit type] | 取消注销指定服务 |
应用举例:
#查看网络服务是否启动
systemctl is-active network.service
#检查网络服务是否设置为开机启动
systemctl is-enable network.service
#停止cups服务
systemctl stop cups.service
#注销cups服务
systemctl mask cups.service
#查看cups服务状态
systemctl status cups.service
#取消注销cups服务
systemctl unmask cups.service
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
4、init 命令与 systemctl 命令对比
init 命令 | systemctl 命令 | 说明 |
---|---|---|
init 0 | systemctl poweroff | 系统关机 |
init 6 |systemctl reboot | 重新启动
与开关机相关的其他命令:
systemctl 命令 | 说明 |
---|---|
systemctl suspend | 进入睡眠模式 |
systemctl hibernate | 进入休眠模式 |
systemctl rescue | 强制进入救援模式 |
systemctl emergency | 强制进入紧急救援模式 |
5、设置系统运行级别
5.1、运行级别对应表
init 级别 | systemctl target |
---|---|
0 | shutdown.target |
1 | emergency.target |
2 | rescure.target |
3 | multi-user.target |
4 | 无 |
5 | graphical.target |
6 | 无 |
此外还是一个 getty.target 用来设置 tty 的数量。
5.2、设置运行级别
命令格式:
systemctl [command] [unit.target]
- 1
参数详解:
command:
- 1
- get-default : 取得当前的 target
- set-default : 设置指定的 target 为默认的运行级别
- isolate : 切换到指定的运行级别
- unit.target : 为 5.1 表中列出的运行级别
systemctl 命令 | 说明 |
---|---|
systemctl get-default | 获得当前的运行级别 |
systemctl set-default multi-user.target | 设置默认的运行级别为 mulit-user |
systemctl isolate multi-user.target | 在不重启的情况下,切换到运行级别 mulit-user 下 |
systemctl isolate graphical.target | 在不重启的情况下,切换到图形界面下 |
6、使用 systemctl 分析各服务之前的依赖关系
命令格式:
systemctl list-dependencies [unit] [–reverse]
- 1
–reverse 是用来检查寻哪个 unit 使用了这个 unit
应用举例:
#获得当前运行级别的target
[root@www ~]# systemctl get-default
multi-user.target
#查看当前运行级别target(mult-user)启动了哪些服务
[root@www ~]# systemctl list-dependencies
default.target
├─abrt-ccpp.service
├─abrt-oops.service
├─vsftpd.service
├─basic.target
│ ├─alsa-restore.service
│ ├─alsa-state.service
.....(中间省略).....
│ ├─sockets.target
│ │ ├─avahi-daemon.socket
│ │ ├─dbus.socket
.....(中间省略).....
│ ├─sysinit.target
│ │ ├─dev-hugepages.mount
│ │ ├─dev-mqueue.mount
.....(中间省略).....
│ └─timers.target
│ └─systemd-tmpfiles-clean.timer
├─getty.target
│ └─getty@tty1.service
└─remote-fs.target
#查看哪些target引用了当前运行级别的target
[root@www ~]# systemctl list-dependencies --reverse
default.target
└─graphical.target
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
7、关闭网络服务
在使用 systemctl 关闭网络服务时有一些特殊 需要同时关闭 unit.servce 和 unit.socket
使用 systemctl 查看开启的 sshd 服务
[root@www system]# systemctl list-units --all | grep sshd
sshd-keygen.service loaded inactive dead OpenSSH Server Key Generation
sshd.service loaded active running OpenSSH server daemon
sshd.socket loaded inactive dead OpenSSH Server Socket
- 1
- 2
- 3
- 4
- 5
可以看到系统同时开启了 sshd.service 和 sshd.socket , 如果只闭关了 sshd.service 那么 sshd.socket 还在监听网络,在网络上有要求连接 sshd 时就会启动 sshd.service 。因此如果想完全关闭 sshd 服务的话,需要同时停用 sshd.service 和 sshd.socket 。
systemctl stop sshd.service
systemctl stop sshd.socket
systemctl disable sshd.service sshd.socket
- 1
- 2
- 3
由于 centos 7.x 默认没有安装 net-tools,因此无法使用 netstat 来查看主机开发的商品。需要通过 yum 安装来获得该工具包:
yum -y install net-tools
- 1
查看是否关闭 22 端口
netstat -lnp |grep sshd
- 1
8、关闭防火墙 firewall
Centos 7.x 中取消了 iptables, 用 firewall 取而代之。要关闭防火墙并禁止开机启动服务使用下面的命令:
systemctl stop firewalld.service
systemctl disable firewalld.service
- 1
- 2
原文地址:https://www.nmbhost.com/archives/3900
CentOS7 硬盘检测
一、测试硬盘健康状态
安装相关工具:yum -y install smartmontools
SMART 是一种磁盘自我分析检测技术,早在 90 年代末就基本得到了普及每一块硬盘(包括 IDE、SCSI),在运行的时候都会将自身的若干参数记录下来,这些参数包括型号、容量、温度、密度、扇区、寻道时间、传输、误码率等。硬盘运行了几千小时后,很多内在的物理参数都会发生变化,某一参数超过报警阈值,则说明硬盘接近损坏,此时硬盘依然在工作,如果用户不理睬这个报警继续使用,那么硬盘将变得非常不可靠,随时可能故障。
启用 SMART
SMART 是和主板 BIOS 上相应功能配合的,要使用 SMART,必须先进入到主板 BIOS 设置里边启动相关设置。一般从 Pentium2 级别起的主板,都支持 SMART,BIOS 启动以后,就是操作系统级别的事情了(Windows 没有内置 SMART 相关工具,需要安装第三方工具软件),好在 Linux 上很早就有了 SMART 支持了,如果把 Linux 装在 VMware 等虚拟机上,在系统启动时候可以看到有个服务启动报错:smartd。这个服务器就是 smart 的 daemon 进程(因为 vmware 虚拟机的硬盘不支持 SMART,所以报错)。smartd 是一个守护进程(一个帮助程序), 它能监视拥有自我监视,分析和汇报技术 (Self-Monitoring, Analysis, and Reporting Technology - SMART) 的硬盘。SMART 体系使得硬盘能监视并汇报自己的运行状况。它的一个重要特性是能够预测失败,使得系统管理员能避免数据丢失。
1、smartctl -i <device> :显示设备的身份信息,检查硬盘是否打开了 SMART 支持。
看到有:
SMART support is: Enabled
说明硬盘支持 SMART。
如果为 Disabled,使用:
smartctl --smart=on --offlineauto=on --saveauto=on <device>
启用 SMART。
2、smartctl -H <device> :查看硬盘的健康状况。
=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED
PASSED 表示硬盘健康状态良好,如果为 Failure 那就要立刻更换硬盘。
3、smartctl -A <device> :显示设备 SMART 厂商属性和值。
我们关心的几个参数:
-
SMART 005 (0x05) - Reallocated Sectors Count:是并被成功重新分配了的坏扇区计数。每个厂家的不同型号硬盘都可能会有一个保留扇区池,这个池中会有不同数量的扇区以供重分配,如果池中所有的都被使用了,那么再有坏扇区就无法分配。这个数值太大就会有问题。
-
SMART 187 (0xBB) - Reported_Uncorrectable_Errors:对于读取的区块的硬件 ECC 校验错误的计数。一般应该为 0,如果非零,就该考虑换硬盘了。
SMART 188 (0xBC) - Command_Timeout:硬盘命令超时而放弃的计数。正常值应该是 0,如果远大于 0,那么可能是电源或者数据线有问题。 -
SMART 197 (0xC5) - Current Pending Sector Count:这些 “不稳定” 扇区,有可能使用写操作使其恢复读写校验正常,这样他们就会被从这个技术中减去。如果写操作也失败,那么固件程序就可能会对其重分配。
-
SMART 198 (0xC6) - Offline_Uncorrectable:读写扇区数据错误的总计数。正常值为 0,否则说明此硬盘的磁盘表面或者机械可能出现问题。
4、smartctl -l error <device> :显示硬盘历史错误信息。
5、smartctl --test=TEST <device> :硬盘自测。
TEST 可取值:offline, short, long, conveyance, select,M-N, pending,N, afterselect,[on|off], scttempint,N [,p]
此时可以用 smartctl -X 中断后台测试。
6、smartctl -l selftest <device> :显示硬盘测试信息。
7、smartctl -a <device> :显示硬盘 SMART 的全部信息。
二 、测试硬盘读写速度
安装相关工具:yum -y install hdparm
1、hdparm -Tt <device> :测试读取速度
其它测试读写速度方法:
测试写速度:dd if=/dev/zero bs=1k count=1000000 of=1Gb.file
测试读速度:dd if=1Gb.file bs=64k |dd of=/dev/null
今天的关于CentOS smartctl 硬盘检测和centos硬盘检测工具的分享已经结束,谢谢您的关注,如果想了解更多关于CentOS 使用 Smartmontools 检测磁盘状态、Centos 怎么用 parted 分区超过 2TB 硬盘、CentOS7 中 systemctl 的使用与 CentOS6 中 service 的区别、CentOS7 硬盘检测的相关知识,请在本站进行查询。
本文标签: