Linux下服務(wù)器做了硬件raid之后,磁盤的狀態(tài)比較難定位,windows則可以通過MegaRAID來檢測(cè),此腳本通過MegaCli來達(dá)到定位raid下哪塊磁盤是壞塊的功能,在nagios上面可以實(shí)現(xiàn)通過定期通過檢測(cè)以郵箱或者短信等形式,來達(dá)到預(yù)警的功能,腳本在幾臺(tái)物理機(jī)上面測(cè)試過,是沒問題的,分享給各位,也希望大家能相互討論,學(xué)習(xí)。
一、安裝Megacli:
rpm-ivh megacli-8.00.46-2.x86_64.rpm
二、添加腳本到nagios監(jiān)控:
執(zhí)行visudo,然后在文件中root ALL=(ALL) ALL下面加入如下一行:
nagios ALL=(ALL)NOPASSWD:/usr/local/nagios/libexec/check_raid.sh
并注釋以下一行
#Defaults requiretty
把腳本放在/usr/local/nagios/libexec目錄下,chmod +x check_raid.sh,賦予x權(quán)限,并編輯/usr/local/nagios/etc/nrpe.cfg加入
command[check_raid]=/usr/bin/sudo/usr/local/nagios/libexec/check_raid.sh
重啟nrpe(根據(jù)安裝方式的不同,可能有差異)
#pkill nrpe #/usr/local/nagios/bin/nrpe -c/usr/local/nagios/etc/nrpe.cfg -d
三、監(jiān)控腳本說明:
#!/bin/sh #Program: # for monitor raid disk state #history: #------ First release #檢測(cè)是否是LSI卡 rcexist=`dmesg| grep RAID | grep LSI` if [ ! -n"$rcexist" ]; then echo "not LSI or no raid" exit 2 fi OUTPUT='' #判斷raid類型 R1=`/usr/sbin/MegaCli-cfgdsply -aALL | grep "RAID Level" |awk -F: '{print $2}' | sed -e"s/^[ ]*//" | grep -c "Primary-1, Secondary-0, RAID LevelQualifier-0"` R0=`/usr/sbin/MegaCli-cfgdsply -aALL | grep "RAID Level" |awk -F: '{print $2}' | sed -e"s/^[ ]*//" | grep -c "Primary-0, Secondary-0, RAID LevelQualifier-0"` R5=`/usr/sbin/MegaCli-cfgdsply -aALL | grep "RAID Level" |awk -F: '{print $2}' | sed -e"s/^[ ]*//" | grep -c "Primary-5, Secondary-0, RAID LevelQualifier-3"` R10=`/usr/sbin/MegaCli-cfgdsply -aALL | grep "RAID Level" |awk -F: '{print $2}' | sed -e"s/^[ ]*//" | grep -c "Primary-1, Secondary-3, RAID LevelQualifier-0"` if [ $R1-ge 2 ];then OUTPUT+="RAID10 " elif [ $R1-eq 1 ];then OUTPUT+="RAID1 " fi if [ $R0-ne 0 ];then OUTPUT+="RAID0 " fi if [ $R5-ne 0 ];then OUTPUT+="RAID5 " fi if [ $R10-ne 0 ];then OUTPUT+="RAID10 " fi #以上的if是根據(jù)資料和實(shí)際情況做了微調(diào) #raid下面總的磁盤數(shù) DiskNum=`/usr/sbin/MegaCli-cfgdsply -aALL | grep -c "Non Coerced Size"` OUTPUT+="TotalDisk:$DiskNum" #處于raid中的正常的盤數(shù) OnlineDisk=`/usr/sbin/MegaCli-cfgdsply -aALL | grep "Online" | wc -l` OUTPUT+="online: $OnlineDisk" if [$DiskNum -ne $OnlineDisk ];then echo "CRITICAL:$OUTPUT" exit 2 fi #是否有壞的盤 FailDisk=`/usr/sbin/MegaCli-AdpAllInfo -aALL | grep "Failed Disks" | awk '{print $4}'` if [$FailDisk -eq 0 ];then OUTPUT+=" failed disk:0 " else OUTPUT+=" failed disk:$FailDisk" echo "CRITICAL: $OUTPUT" exit 2 fi #預(yù)警的盤以及位置 CriticalDisk=`/usr/sbin/MegaCli-AdpAllInfo -aALL | grep "Critical Disks" | awk '{print $4}'` if [$CriticalDisk -eq 0 ];then OUTPUT+="critiDisk is 0" else CriDisk=`/usr/sbin/MegaCli -cfgdsply -aALL| grep -E 'Predictive|Slot' | awk \ '{if(NR%3){printf$0":"}else{print $0}}'|awk -F':' '{if($4!=0){print $2+1}}'` OUTPUT+=" critidisk in $CriDiskslot" echo "WARNING: $OUTPUT" exit 1 fi #MediaErrcount檢測(cè)壞塊和哪塊盤 MediaErrcount=`/usr/sbin/MegaCli-pdlist -aALL | grep -E "Media Error" |awk -F’:’ -v errcount=0 \ '{errcount+=$2}END{printerrcount}'` OtherErrcount=`/usr/sbin/MegaCli-pdlist -aALL | grep -E "Other Error" |awk -F’:’ -v errcount=0 \ '{errcount+=$2}END{printerrcount}'` #壞盤的位置 if [ $MediaErrcount-ne 0 -o $OtherErrcount -ne 0 ];then mDoD=`/usr/sbin/MegaCli -pdlist -aALL |grep -E "Media Error|Other Error|Slot" | awk \ '{if(NR%3){printf$0":"}else{print $0}}' | awk -F':' '{if($4!=0||$6!=0){print $2+1}}'` OUTPUT+=" bad block in $mDoD" echo "CRITICAL: $OUTPUT" exit 2 else OUTPUT+=" mediaerr:0 othererr:0" fi #raid狀態(tài)是否正常 raidstate=`/usr/sbin/MegaCli-LDInfo -Lall -aAll | grep 'State' |awk -F':' '{print $2}' | \ sort |uniq | sed -e "s/^[ ]*//" | awk '{if($0 != "Optimal"){print"bad"}}'` if ["$raidstate" != "bad" ];then OUTPUT+=" raidstate:ok" else OUTPUT+=" raidstate:bad" echo "CRITICAL: $OUTPUT" exit 2 fi rm -rf./MegaSAS.log echo$OUTPUT
檢測(cè)結(jié)果如下:
RAID5 Total Disk: 4 online: 4 failed disk:0 critidisk is 0 mediaerr:0 othererr:0 raidstate:ok
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
網(wǎng)頁(yè)標(biāo)題:nagios監(jiān)控raid下磁盤和raid狀態(tài)腳本實(shí)現(xiàn)-創(chuàng)新互聯(lián)
URL地址:http://chinadenli.net/article36/djgppg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營(yíng)銷、用戶體驗(yàn)、品牌網(wǎng)站設(shè)計(jì)、定制開發(fā)、響應(yīng)式網(wǎng)站、網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容