按照常理说,硬盘故障了,会自动亮红灯,故障消除后会自动恢复正常,这个本来是服务器自带的功能。但现实情况往往不是这样,即使硬盘故障了,现场通过外观也看不出来。
在运维的工作中,很大也是很重要的一项工作就是故障处理,而故障处理中以硬盘故障最为常见。如果更换错误,可能会造成数据丢失,后果很严重。那么如何能够准确快速的更换硬盘呢?给故障的硬盘点灯是一个非常好的选择。
无论是raid卡还是HBA卡,每块硬盘都有对应的LED灯,这些LED灯常用来指示磁盘的状态和行为。例如正常状态显示绿色,故障状态显示红色,rebuild状态显示粉色等等。
通过控制这些硬盘灯颜色的变化,现场操作时一眼就能定位到是哪块盘故障了,非常的直观(当然色盲可能有点难度,不过控制闪烁也能区分出来)。
除了定位故障硬盘更加直观以后,也减少了我们误操作的概率。因为这个点灯操作是在操作系统里触发的,在操作系统里定位的故障硬盘是要更准确的。为什么这么说呢?因为有些厂商服务器标识的硬盘ID号是错误的,尤其是国产的服务器。例如我在系统下看到的id号是[32:1],而服务器物理机上标识得可能是5号盘。
这里我只针对LSI的RAID卡和HBA卡进行讲解。
Raid卡的点灯操作用到如下命令:
[root@idc-center009 ~]# /opt/MegaRAID/MegaCli/MegaCli64 -h |grep PdLocate
MegaCli -PdLocate {[-start] | -stop} -physdrv[E0:S0,E1:S1,...] -aN|-a0,1,2|-aALL
MegaCli PdLocate start physdrv[32:1] -a0
使用如下命令可以查看到每块硬盘的具体信息。
[root@idc-center009 ~]# /opt/MegaRAID/MegaCli/MegaCli64 pdlist a0 |more
Adapter #0
Enclosure Device ID: 252
Slot Number: 0
Enclosure position: 0
Device Id: 2
Sequence Number: 2
Media Error Count: 0
Other Error Count: 0
Predictive Failure Count: 0
Last Predictive Failure Event Seq Number: 0
PD Type: SAS
Raw Size: 279.460 GB [0x22eec130 Sectors]
Non Coerced Size: 278.960 GB [0x22dec130 Sectors]
Coerced Size: 278.937 GB [0x22de0000 Sectors]
Firmware state: Online, Spun Up
SAS Address(0): 0x5000cca0301d11d1
SAS Address(1): 0x0
Connected Port Number: 0(path0)
Inquiry Data: HGST HUC101830CSS200 A3F002GHZLSB
FDE Capable: Not Capable
FDE Enable: Disable
Secured: Unsecured
Locked: Unlocked
Needs EKM Attention: No
Foreign State: None
Device Speed: Unknown
Link Speed: Unknown
Media Type: Hard Disk Device
Drive: Not Certified
Drive Temperature :29 Celsius
不过信息有点多,我们过滤一下信息,得到我们关心的数据。
[root@idc-center009 ~]# /opt/MegaRAID/MegaCli/MegaCli64 pdlist a0 |egrep 'Enclosure Device ID:|Slot|Fir|Raw' |sed 's/En/\n---------\nEn/g'
---------
Enclosure Device ID: 252
Slot Number: 0
Raw Size: 279.460 GB [0x22eec130 Sectors]
Firmware state: Online, Spun Up
---------
Enclosure Device ID: 252
Slot Number: 1
Raw Size: 279.460 GB [0x22eec130 Sectors]
Firmware state: Online, Spun Up
---------
Enclosure Device ID: 252
Slot Number: 2
Raw Size: 279.460 GB [0x22eec130 Sectors]
Firmware state: Online, Spun Up
---------
Enclosure Device ID: 252
Slot Number: 3
Raw Size: 279.460 GB [0x22eec130 Sectors]
Firmware state: Online, Spun Up
有了这些信息就可以给硬盘进行点灯了,例如我想给Enclosure Device ID: 252,Slot Number: 1的硬盘点灯。
那么只需要执行如下命令:
[root@idc-center009 ~]# /opt/MegaRAID/MegaCli/MegaCli64 PdLocate start physdrv[252:1] -a0
Adapter: 0: Device at EnclId-252 SlotId-1 -- PD Locate Start Command was successfully sent to Firmware
Exit Code: 0x00
关灯使用如下命令:
[root@idc-center009 ~]# /opt/MegaRAID/MegaCli/MegaCli64 PdLocate stop physdrv[252:1] -a0
Adapter: 0: Device at EnclId-252 SlotId-1 -- PD Locate Stop Command was successfully sent to Firmware
Exit Code: 0x00
这里我通过倒叙的方式讲解容易理解一些,也就是结果导向进行思考。
当然,我们先把必要的软件安装上再讲。可以直接通过yum安装两个软件lsscsi、sg3_utils。
[root@idc-pxe009 ~]# yum install lsscsi sg3_utils
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
Setting up Install Process
Package lsscsi-0.23-3.el6.x86_64 already installed and latest version
Package sg3_utils-1.38-1.x86_64 already installed and latest version
Nothing to do
2.2.1 点灯的最终命令
获取硬盘灯的状态使用如下命令:sg_ses --dev-slot-num=1 --get=ident /dev/sg12
The sg_ses utility is found in the sg3_utils package.
The sg_ses utility enables a user "to manage and sense the state of the power supplies, cooling devices, displays, indicators, individual drives, and other non-SCSI elements installed in an enclosure".
一个整体的点灯例子如下:
[root@idc-pxe009 ~]# sg_ses --dev-slot-num=1 --get=ident /dev/sg12
0
[root@idc-pxe009 ~]# sg_ses --dev-slot-num=1 --set=ident /dev/sg12
[root@idc-pxe009 ~]# sg_ses --dev-slot-num=1 --get=ident /dev/sg12
1
[root@idc-pxe009 ~]# sg_ses --dev-slot-num=1 --clear=ident /dev/sg12
[root@idc-pxe009 ~]# sg_ses --dev-slot-num=1 --get=ident /dev/sg12
0
2.2.2 获取点灯的参数
2.2.2.1 定位需要点灯盘的enclosu信息
使用lsscsi -gt获取硬盘信息和enclosu信息,确定故障硬盘的sg信息。这里我这台机器上有12块盘,并且都在都在/dev/sg12上。
[root@idc-pxe009 ~]# lsscsi -gt
[0:0:0:0] disk sas:0x500e004aaaaaaa00 /dev/sda /dev/sg0
[0:0:1:0] disk sas:0x500e004aaaaaaa01 /dev/sdb /dev/sg1
[0:0:2:0] disk sas:0x500e004aaaaaaa02 /dev/sdc /dev/sg2
[0:0:3:0] disk sas:0x500e004aaaaaaa03 /dev/sdd /dev/sg3
[0:0:4:0] disk sas:0x500e004aaaaaaa04 /dev/sde /dev/sg4
[0:0:5:0] disk sas:0x500e004aaaaaaa05 /dev/sdf /dev/sg5
[0:0:6:0] disk sas:0x500e004aaaaaaa06 /dev/sdg /dev/sg6
[0:0:7:0] disk sas:0x500e004aaaaaaa07 /dev/sdh /dev/sg7
[0:0:8:0] disk sas:0x500e004aaaaaaa08 /dev/sdi /dev/sg8
[0:0:9:0] disk sas:0x500e004aaaaaaa09 /dev/sdj /dev/sg9
[0:0:10:0] disk sas:0x500e004aaaaaaa0a /dev/sdk /dev/sg10
[0:0:11:0] disk sas:0x500e004aaaaaaa0b /dev/sdl /dev/sg11
[0:0:12:0] enclosu sas:0x500e004aaaaaaa3e - /dev/sg12
2.2.2.2 获取硬盘的dev-slot-num
根据上面的lsscsi -gt的显示结果,例如我们要给/dev/sdc点灯,那么我们在找到/dev/sdc的dev-slot-num。查找这个信息的命令如下:sg_ses --sas-addr=0x500e004aaaaaaa02 /dev/sg12
[root@idc-pxe009 ~]# sg_ses --sas-addr=0x500e004aaaaaaa02 /dev/sg12
LENOVO TUNA-HB12Gen2i 0009
Primary enclosure logical identifier (hex): 500e004aaaaaaa00
[0,2] Element type: Array device slot
Enclosure Status:
Predicted failure=0, Disabled=0, Swap=0, status: OK
OK=1, Reserved device=0, Hot spare=0, Cons check=0
In crit array=0, In failed array=0, Rebuild/remap=0, R/R abort=0
App client bypass A=0, Do not remove=0, Enc bypass A=0, Enc bypass B=0
Ready to insert=0, RMV=0, Ident=0, Report=0
App client bypass B=0, Fault sensed=0, Fault reqstd=0, Device off=0
Bypassed A=0, Bypassed B=0, Dev bypassed A=0, Dev bypassed B=0
Additional Element Status:
Transport protocol: SAS
number of phys: 1, not all phys: 1, device slot number: 2
phy index: 0
device type: no SAS device attached
initiator port for:
target port for: SATA_device
attached SAS address: 0x500e004aaaaaaa3f
SAS address: 0x500e004aaaaaaa02
phy identifier: 0x0
[root@idc-pxe009 ~]# sg_ses --sas-addr=0x500e004aaaaaaa02 /dev/sg12 |grep 'device slot number:'
number of phys: 1, not all phys: 1, device slot number: 2
其实sg_ses还有一些其它参数进行显示,可以了解一下。
sg_ses --join /dev/sg3
sg_ses --join --filter /dev/sg3
sg_ses -j -ff /dev/sg3
这3条命令可以把所有硬盘的信息显示出来,从上到下,每条信息的显示结果越来越精简。官方的解释是:
The first command will list information on all disks, fans, power supplies etc, even for disks and fans not installed. The second command attempts to filter out some less relevant information. The third command tries harder to filter out some less relevant information.
2.2.2.3 设置硬盘灯的状态
通过这三个参数(clear、get、set)来控制和查看硬盘灯的状态。如何使用就不多解释了,相信大家都能知道。不过要了解一下get到的数字,这里找了一张官方的表格,虽然我也没看懂。
硬盘点灯这个操作其实不难,稍微学习一下就能掌握。关键是如果把这个功能做成自动化的,减少人为干预,减少劳动力,这就需要动动脑子了。
例如可以写成一个脚本,做成定时任务,有故障后自动点灯,故障消除后自动关灯。再关联一下监控报警,再关联一下流程,做到自动报修等等。