物理服务器硬件磁盘监控:
第一:安装Megacli 和 zabbix_sender
MegaCli
参考:http://tenderrain.blog.51cto.com/9202912/1639865
rpm -ivh megacli-8.02.21-1-mdv2012.0.x86_64.rpm
查看安装路径(不同的安装包路径可能不同);
rpm -ql megacli-8.02.21-1.x86_64
/sbin/megacli
/usr/share/doc/megacli
/usr/share/doc/megacli/8.02.21_MegaCLI.txt
zabbix_sender
默认已安装,如果没有这个命令,可从其他服务器拷贝
第二:
#部署脚本
文件一:/usr/local/raid_and_disk_check.sh
#/bin/bash
#Function:
#1.check raid Degraded
#2.check Failed Disks
zabbix_sender -c /etc/zabbix/zabbix_agentd.conf -k "raid_degraded" -o `sudo megacli -AdpAllInfo -aALL -NoLog | grep "Degraded" |awk '{print $NF}'` -r
zabbix_sender -c /etc/zabbix/zabbix_agentd.conf -k "raid_failed_disks" -o `sudo megacli -AdpAllInfo -aALL -NoLog | grep "Failed Disks" |awk '{print $NF}'` -r
chown zabbix.zabbix /usr/local/raid_and_disk_check.sh
chmod +x /usr/local/raid_and_disk_check.sh
文件二:/usr/local/disk_id_discover.sh
#!/bin/bash
#Function:
#1.check Disk of Slot Number
num=0
RAID_stats() {
DISK=($(sudo megacli -pdlist -aALL | grep "Slot Number" | awk -F":" '{print $2}'))
printf '{\n\t"data":[\n'
for key in ${DISK[@]};do
if [[ "${#DISK[@]}" -gt "$num" && "$num" -ne "$((${#DISK[@]}-1))" ]];then
printf "\t\t{\"{#RAID_ID}\":\"$key\"},\n"
let "num++"
elif [[ "$((${#DISK[@]}-1))" -eq "$num" ]];then
printf "\t\t{\"{#RAID_ID}\":\"$key\"}\n"
fi
done
printf '\t]\n}\n'
}
RAID_stats
chown zabbix.zabbix /usr/local/disk_id_discover.sh
chmod +x /usr/local/disk_id_discover.sh
备注:
- megacli:改成正确的路径
- 确保zabbix用户有权限使用这个命令
- disk_id_discover.sh 生成的数据是字典的格式
第三:修改zabbix的配置文件:
备份:
\cp -r /etc/zabbix/zabbix_agentd.conf /etc/zabbix/zabbix_agentd.conf.bak
修改:
cat >> /etc/zabbix/zabbix_agentd.conf << EOF
UnsafeUserParameters=1
UserParameter=raid_discover,bash /usr/local/raid_id_discover.sh
UserParameter=raid_degraded,sudo /usr/local/MegaCli -AdpAllInfo -aALL -NoLog | grep "Degraded" |awk '{print \$NF}'
UserParameter=raid_failed_disks,sudo /usr/local/MegaCli -AdpAllInfo -aALL -NoLog | grep "Failed Disks" |awk '{print \$NF}'
UserParameter=raid_MEC[*],sudo /usr/local/MegaCli -PDList -aAll -NoLog | grep -A 8 "Slot Number: \$1" | grep "Media Error Count" | awk '{print \$NF}'
UserParameter=raid_OEC[*],sudo /usr/local/MegaCli -PDList -aAll -NoLog | grep -A 8 "Slot Number: \$1" | grep "Other Error Count" | awk '{print \$NF}'
EOF
第四:给zabbix添加sudo权限(这块可以优化,有风险)
echo "zabbix ALL=(root) NOPASSWD:ALL" >> /etc/sudoers
sed -i 's/^Defaults.*.requiretty/#Defaults requiretty/' /etc/sudoers
第五:
重启zabbix服务
第六:添加至crontab
echo "01 02 * * * root /usr/local/raid_and_disk_check.sh >/dev/null 2>&1 " >> /etc/crontab
echo "01 02 * * * root /usr/local/disk_id_discover.sh >/dev/null 2>&1" >> /etc/crontab
第七:zabbix模板设置,此处省略,补充下模板参考附件RAID_and_disk_check_for_dell(可能需要微微修改)