萨尔法保护 发表于 2019-1-13 12:35:18

nagios图形监控和管理

  1、Pnp安装图形监控曲线(服务器端)
  Pnp出图软件官方站点:http://docs.pnp4nagios.org/

  2、执行yum安装基础pnp软件需要依赖的包:
  yum install cairo pango zlib zlib-devel freetype freetype-devel gd dg-devel -y
  

  3、安装libart_lgpl
  tar xf libart_lgpl-2.3.17.tar.gz
   cd libart_lgpl-2.3.17
   ./configure
   make
   make install
   /bin/cp -r /usr/local/include/libart-2.0 /usr/include/
   cd ../
   # 原理:利用rrdtool (轮询数据库工具)出图
  

  4、安装rrdtool
  tar xf rrdtool-1.2.14.tar.gz
    cd rrdtool-1.2.14
    ./configure --prefix=/usr/local/rrdtool --disable-python --disable-ct1
        ##WARNING: The RRDs Perl Modules are not found on your System
      #Using RRDs will speedup things in larger Installtions.
      #configure后出现上面的提示可以不用理会。
  make
    make install
    cd ..
      #关注:ls /usr/local/rrdtool/bin/
            rrdcgirrdtoolrrdupdate 表示成功

  5、安装负责图形展示的pnp-0.4.14.tar.gz
     tar zxf pnp-0.4.14.tar.gz
    cd pnp-0.4.14
    ./configure \
    --with-rrdtool=/usr/local/rrdtool/bin/rrdtool --with-perfdata-dir=/usr/local/nagios/share/perfdata/
  问题:configure报错(一般不会发生)
    checking for linker flags for loadable modules... -shared
    checking for Perl Module Time::HiRes... no
    configure: error: Perl Module Time::HiRes not available
    解决:yum install perl-Time-HiRes -y
      #################
    #WARNING: The RRDs Perl Modules are not found on your System
    #         Using RRDs will speedup things in larger Installtions.
    #####################
    make all
    make install
    make install-config
    make install-init
    ll /usr/local/nagios/libexec/ |grep process #(用来搜集数据)
  

  6、出图的配置
     vi nagios.cfg +833

833 process_performance_data=1    

      #1记录数据,0不记录数据
    837 # HOST AND SERVICE PERFORMANCE DATA PROCESSING COMMANDS
    838 # These commands are run after every host and service check is
    839 # performed.These commands are executed only if the
    840 # enable_performance_data option (above) is set to 1.The command
    841 # argument is the short name of a command definition that you
    842 # define in your host configuration file.Read the HTML docs for
    843 # more information on performance data.
    844
845 host_perfdata_command=process-host-perfdata
  #主机记录数据

  846 service_perfdata_command=process-service-perfdata
#服务记录数据

执行编辑命令 vi /usr/local/nagios/etc/objects/commands.cfg +227,修改commands.cfg配置文件。
    #修改commands.cfg 配置文件,约227-238行
    #默认配置为(如果没有直接添加即可)
    #-----------------------------------------------------------------   
    # 'process-host-perfdata' command definition
    define command{
            command_name    process-host-perfdata
            command_line    /usr/bin/printf "%b"         "$LASTHOSTCHECK$\t$HOSTNAME$\t$HOSTSTATE$\t$HOSTATTEMPT$\t$HOSTSTATETYPE$\t$HOSTEXECUTIONTIME$\t$HOSTOUTPUT$\t$HOSTPERFDAT    A$\n" >> /usr/local/nagios/var/host-perfdata.out
      }
    # 'process-service-perfdata' command definition
    define command{
            command_name    process-service-perfdata
            command_line    /usr/bin/printf "%b"   "$LASTSERVICECHECK$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICESTATE$\t$SERVICEATTEMPT$\t$SERVICESTATETYPE$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$\n" >> /usr/local/nagios/var/service-perfdata.out
      }
    修改成如下配置
    # 'process-host-perfdata' command definition
    define command{
            command_name    process-host-perfdata
         command_line    /usr/local/nagios/libexec/process_perfdata.pl
            }

    # 'process-service-perfdata' command definition
    define command{
            command_name    process-service-perfdata
command_line    /usr/local/nagios/libexec/process_perfdata.pl
            }
    也可以用nagios变量$USER1$替代/usr/local/nagios/libexec/路径
    执行检查语法命令/etc/init.d/nagios checkconfig
    Total Warnings: 0
    Total Errors:   0
    根据提示,配置通过。重启。
  

  7、   vitemplates.cfg
  58         process_perf_data               1               ; Process performance data
   #出图控制,可以在服务、主机、模版添加;
  

  8、绑定主机出图整合nagios
  define host{
      use                     linux-server
      host_name               nagios
      alias                   nagios-01
      address               10.0.0.23
      action_url            /nagios/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$
      }
  #可以在 模版vi templates.cfg 里linux-server里添加
  /nagios/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$
         #重启服务后观察主机的监控,如图,点人即可:    http://s3.运维网.com/wyfs02/M02/59/24/wKioL1TIolWwPcwZAABMDsVCusM976.jpg

  

  9、绑定服务出图整合nagios
      vi services.cfg
    define service{
      use                      generic-service
      host_name                nagios,C
      service_description      Disk Partition
      check_command            check_nrpe!check_disk
      action_url            /nagios/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$
   }
  

  10、出图的数据路径:/usr/local/nagios/share/perfdata/
      出图地址:http://10.0.0.22/nagios/pnp/index.php
     http://s3.运维网.com/wyfs02/M01/59/27/wKiom1TIqCnAqpjHAAM1y72iYxA992.jpg
  
  




页: [1]
查看完整版本: nagios图形监控和管理