專注于為中小企業(yè)提供成都網(wǎng)站設(shè)計(jì)、網(wǎng)站建設(shè)服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)淮上免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了1000多家企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過(guò)網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
1.下載MegaCLI
- #mkdir -p /opt/build/
- #cd /opt/build/
- 在http://www.lsi.com 網(wǎng)站下載MegaCLI - 5.3
- #unzip 8.04.07_MegaCLI.zip
- 解壓出來(lái)安裝里面linux(這兩個(gè)文件見(jiàn)附件)
#rpm -ivh Lib_Utils-1.00-09.noarch.rpm
#rpm -ivh MegaCli-8.04.07-1.noarch.rpm
2.編寫插件
- #vim /usr/lib64/nagios/plugins/check_raid
- #!/bin/bash
- STATE_OK=0
- STATE_WARNING=1
- STATE_CRITICAL=2
- STATE_UNKNOWN=3
- Optimal=" Optimal"
- VDSTATE=$(/opt/MegaRAID/MegaCli/MegaCli64 -cfgdsply -aALL | /bin/grep "^State")
- STATE=$(/opt/MegaRAID/MegaCli/MegaCli64 -cfgdsply -aALL | /bin/grep "^State" | /bin/awk -F\: '{print $2}')
- #echo $? >> /tmp/vdiskstatus.log
- #echo $STATE >> /tmp/vdiskstatus.log
- if [ $STATE = $Optimal ];then
- echo OK -- "Virtual Disk : $STATE"
- exit $STATE_OK
- else
- echo CRITICAL -- "Virtual Disk : $STATE"
- exit $STATE_CRITICAL
- fi
3.更改插件的權(quán)限
- #chown nagios.nagios /usr/lib64/nagios/plugins/check_raid
- #chmod 755 /usr/lib64/nagios/plugins/check_raid
4.測(cè)試插件是否正常工作
#/usr/lib64/nagios/plugins/check_raid
OK -- Virtual Disk : Optimal
5.給nagios用戶增加sudo權(quán)限
由于MegaCli命令執(zhí)行時(shí)需要root權(quán)限,所以我們需要為nagios用戶創(chuàng)建一個(gè)sudo使nagios用戶可以執(zhí)行check_raid。
#visudo
增加以下行:
- # Allow nagios to run certain plugins as root
- nagios ALL=(ALL) NOPASSWD: /usr/lib64/nagios/plugins/
注釋以下行:
- #Defaults requiretty
啟用以下行:
- %wheel ALL=(ALL) NOPASSWD: ALL
由于nrpe在傳輸?shù)倪^(guò)程中也要用到root權(quán)限所以把nrpe加入到wheel組中
- #usermod -a -G wheel nrpe
6.編輯被監(jiān)控服務(wù)器的nrpe.cfg
增加一個(gè)新的命令:
- #vim /etc/nagios/nrpe.cfg
- command[check_raid]=/usr/bin/sudo /usr/lib64/nagios/plugins/check_raid
重啟nrpe:
- #/etc/init.d/nrpe restart
7.在nagios服務(wù)器端添加服務(wù)
- define service{
- host_name test
- service_description raid_status
- check_period 24x7
- normal_check_interval 5
- retry_check_interval 2
- max_check_attempts 5
- notification_period 24x7
- contact_groups admins
- check_command check_nrpe!check_raid
- }
驗(yàn)證配置文件并重啟服務(wù)。
- #nagios -v /etc/nagios/nagios.cfg
- #/etc/init.d/nagios restart