zoukankan      html  css  js  c++  java
  • smartmontools的安装使用和实现对磁盘的Nagios监控

    安装

    • 首先从sourceforge下载最新的安装版本。

    • 解压编译

        $ tar -zxvf smartmontools-6.4.tar.gz
        $ cd smartmontools-6.4
        $ ./configure
      
    • 若出现checking for g++... no问题

    原因是缺少C++编译器,在CentOS上使用yum install gc-c++安装编译器。问题解决参考了这篇博客

    • make & make install

        $ make
        $ make install
      

    常规用法

    • 使用-i参数查询硬盘信息,并且查看SMART support是否打开

        `# smartctl -i /dev/sdb
        smartctl 5.43 2012-06-30 r3573 [x86_64-linux-2.6.32-358.el6.x86_64] (local build)
        Copyright (C) 2002-12 by Bruce Allen, http://smartmontools.sourceforge.net
        	
        === START OF INFORMATION SECTION ===
        Model Family:     Seagate xxxxxxx
        Device Model:     xxxxxxxx
        Serial Number:    xxxxxxxxxx
        LU WWN Device Id: xxxxxxxxxx
        Firmware Version: SC13
        User Capacity:    500,107,862,016 bytes [500 GB]
        Sector Size:      512 bytes logical/physical
        Device is:        In smartctl database [for details use: -P show]
        ATA Version is:   8
        ATA Standard is:  ATA-8-ACS revision 4
        Local Time is:    Wed Jan 20 09:04:20 2016 CST
        SMART support is: Available - device has SMART capability.
        SMART support is: Enabled
      
    • 使用-H查看健康状态

        `# smartctl -H /dev/sda
         smartctl 5.43 2012-06-30 r3573 [x86_64-linux-2.6.32-358.el6.x86_64] (local build)
         Copyright (C) 2002-12 by Bruce Allen, http://smartmontools.sourceforge.net
        	
         === START OF READ SMART DATA SECTION ===
         SMART overall-health self-assessment test result: PASSED
      

    简单的Nagios监控脚本

    因为我使用的服务器采用RAID1,因此使用SMARTCTL来检查每个磁盘的状态,一旦有问题就可以提前对问题磁盘进行更换。

    #! /bin/sh
    SDA=`/usr/sbin/smartctl -H /dev/sda | grep 'test result'|cut -d':' -f 2`
    SDB=`/usr/sbin/smartctl -H /dev/sdb | grep 'test result'|cut -d':' -f 2`
    OUTPUT=''
    if [ "$SDA" = " PASSED" ];then
    	if [ "$SDB" = " PASSED" ];then
    		OUTPUT+="OK: SDA is$SDA and SDB is$SDB"
    	fi
    else
    	OUTPUT+="CRITICAL: SDA is$SDA and SDB is$SDB"
    fi
    echo $OUTPUT
    

    将上面这段脚本保存为check_disk_health.sh,并保存到Nagios的脚本目录/usr/local/nagios/libexec

    因为调用smartctl需要root权限,因此需要在/etc/sudoers文件中增加一行。

    `nagios ALL=(ALL) NOPASSWD:/usr/local/nagios/libexec/check_disk_health.sh`
    

    同时注释掉Defaults requiretty这一行。

    然后在nrpe.cfg文件中增加check_disk_health命令。

    command[check_disk_health]=/usr/bin/sudo /usr/local/nagios/libexec/check_disk_health.sh
    

    最后可以使用chek_nrpe对命令进行检测。

        $ ./check_nrpe -H localhost -c check_disk_health
        OK: SDA is PASSED and SDB is PASSED
    

    Nagios snapshot

  • 相关阅读:
    C#三元运算符
    WIN系统查询版本
    C# switch 语句
    C#反编译
    AssemblyInfo.cs 文件信息
    win系统如何在桌面显示我的电脑
    MVC传值前台
    js去除html标记
    打开页面跳转到区域下的控制器
    Hive常用操作之数据导入导出
  • 原文地址:https://www.cnblogs.com/shenfeng/p/smartmontools_nagios.html
Copyright © 2011-2022 走看看