monicazhang 发表于 2016-1-16 14:00:02

从nagios上安装配置

来自:网络
第一步:安装软件:分为nagios监控端和nagios被监控端监控端软件列表uploads/img/201511/05030030_5Yxe.jpgNagios安装包uploads/img/201511/05030030_tg29.jpgNagios插件安装包uploads/img/201511/05030030_SXjZ.jpgNagios中文支持包uploads/img/201511/05030030_T7ZK.jpgNrpe软件包uploads/img/201511/05030030_TvLO.jpgnagios通过nrpe来远端管理服务1. nagios执行安装在它里面的check_nrpe 插件,并告诉check_nrpe 去检测哪些服务。               nagios培训2. 通过ssl,check_nrpe 连接远端机子上的nrpe daemon3. nrpe运行本地的各种插件去检测本地的服务和状态4. nrpe把检测的结果传给主机端的check_nrpe, 主机端的check_nrpe再把结果送到nagios状态队列中。5. nagios 依次读取队列中的信息,再把结果显示出来。解决编译软件时需要的依赖@www ~]# yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel添加nagios用户添加目录 mkdir /usr/local/nagios修改权限 chown -R nagios.nagios /usr/local/nagios解压软件包 tar -xzvf nagios-3.2.0.tar.gz开始安装1.   ./configure --prefix=/usr/local/nagios2.   make all3.   make install4.   make install-init5.    make install-commandmode6.    make install-config7.    chkconfig --add nagios8.    chkconfig --level 35 nagios on9.    tar -xzvf nagios-plugins-1.4.14.tar.gz10.   ./configure --prefix=/usr/local/nagios11.   make && make install12.   yum install httpd13.   yum install php14.   vim /etc/httpd/conf/httpd.conf添加以下内容uploads/img/201511/05030030_VizB.jpg修改用户uploads/img/201511/05030030_rUum.jpg15.   添加密码htpasswd -c /usr/local/nagios/etc/htpasswd oracle16.   /etc/init.d/httpd start17.   tar -xjvf nagios-cn-3.2.0.tar.bz218.   ./configure 19.   make && make install监控端nagios安装完毕重启httpd和启动nagios可以看到以下画面uploads/img/201511/05030030_DmRk.jpg这里你要输入刚才设置的用户和密码
在没有修改配置的情况下,默认只能查看到本机uploads/img/201511/05030031_Eehy.jpg好的 下面来添加主机会用到以下几个文件,其他文件就由各位下去自己慢慢研究了,我手懒uploads/img/201511/05030031_Lnd6.jpg其中以下两个文件需要手动创建uploads/img/201511/05030031_8PXl.jpg定义被监控主机@www objects]# cat hosts.cfgdefine host{      use                     linux-server   使用templates.cfg定义的       host_name             Nagios-Linux    自己取的名字并不一定是主机名                                  nagios实施      alias                  Nagios-Linux    别名         address               192.168.1.201被监控主机            }定义监控内容也就是监控命令@www objects]# cat services.cfgdefine service{      use                     local-service      host_name               Nagios-Linux      service_description   Current Load      check_command         check_nrpe!check_load      }define service{      use                     local-service      host_name               Nagios-Linux      service_description   Check Disk sda1      check_command         check_nrpe!check_sda1      }define service{      use                     local-service      host_name               Nagios-Linux      service_description   Total Processes      check_command         check_nrpe!check_total_procs      }define service{      use                     local-service      host_name               Nagios-Linux      service_description   Current Users      check_command         check_nrpe!check_users      }define service{      use                     local-service      host_name               Nagios-Linux      service_description   Check Zombie Procs      check_command         check_nrpe!check_zombie_procs      }define service{      use                     local-service      host_name               Nagios-Linux      service_description   Check Swap      check_command         check_nrpe!check_swap      }define service{      use                     local-service      host_name               Nagios-Linux      service_description   HTTP      check_command         check_nrpe!check_http      }define service{      use                     local-service      host_name               Nagios-Linux      service_description   MYSQL      check_command         check_nrpe!check_mysql      }define service{      use                     local-service      host_name               Nagios-Linux      service_description   MYLOG      check_command         check_nrpe!check_mylog被监控端主机安装nrep、nagi-plugin软件包与监控端安装类似,注意最好是以xinetd的方式来启动安装nrep161./configure162make all163make install-plugin164make install-daemon-config165make install-xinetdvim /etc/xinetd.d/nrpe# default: on# description: NRPE (Nagios Remote Plugin Executor)service nrpe{      flags         = REUSE      socket_type   = stream      port            = 5666      wait            = no      user            = nagios      group         = nagios      server          = /usr/local/nagios/bin/nrpe      server_args   = -c /usr/local/nagios/etc/nrpe.cfg --inetd                        监控软件      log_on_failure+= USERID      disable         = no      only_from       = 127.0.0.1 192.168.1.200#服务器地址测试/usr/local/nagios/libexec/check_nrpe -H localhost@www libexec]# vim /usr/local/nagios/etc/nrpe.cfglog_facility=daemonpid_file=/var/run/nrpe.pidserver_port=5666nrpe_user=nagiosnrpe_group=nagiosallowed_hosts=127.0.0.1dont_blame_nrpe=0debug=0command_timeout=60connection_timeout=300command=/usr/local/nagios/libexec/check_users -w 5 -c 10command=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20command=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1command=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Zcommand=/usr/local/nagios/libexec/check_procs -w 150 -c 200command=/usr/local/nagios/libexec/check_swap -w 20% -c 10%command=/usr/local/nagios/libexec/check_http -I 127.0.0.1command=/usr/local/nagios/libexec/check_mysqlcommand=/usr/local/nagios/libexec/check_mylog自己定义的插件@www libexec]# cat check_mylog#!/bin/bash##myfiles="`date +%F`.txt"count=`sed -n '/fail/p' /tmp/$myfiles|wc -l`if [ $count -eq 0 ];then       echo "MYLOG IS OK"       exit 0elif [ $count -ge 1 -a $count -le 10 ] ;then       echo "MYLOG IS WARNING"       exit 1elif [ $count -ge 11 ];then       echo "MYLOG IS CRITICAL"       exit 2elif [ $count -lt 0 ];then       echo "UNKNOWN"       exit 3If0 表示OK1 表示WARNNING2 表示 CRITICAL3 表示UNKNOWN在服务端的services.cfg中使用这两个自己定义的插件define service{      use                     local-service      host_name               Nagios-Linux      service_description   MYSQL      check_command         check_nrpe!check_mysql      }define service{      use                     local-service      host_name               Nagios-Linux      service_description   MYLOG      check_command         check_nrpe!check_mylog最后要在command.cfg中加入check_nrpe命令# 'check_nrpe' command definitiondefine command{      command_name    check_nrpe         command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$               nagios配置                           }重启服务端服务uploads/img/201511/05030031_blx2.jpg就会出现我们定义的主机uploads/img/201511/05030031_cUAn.jpg例如我现在关闭mysqluploads/img/201511/05030031_YScC.jpguploads/img/201511/05030031_xVPi.jpg这里就可以看到mysql的监控状态为紧急现在恢复mysqluploads/img/201511/05030031_Zdag.jpguploads/img/201511/05030031_wvKW.jpg可以看到mysql监控状态为ok下面我来实现故障告警功能使用邮件告警# cat contacts.cfg################################################################################ CONTACTS.CFG - SAMPLE CONTACT/CONTACTGROUP DEFINITIONS## Last Modified: 05-31-2007## NOTES: This config file provides you with some example contact and contact#      group definitions that you can reference in host and service#      definitions.#      #      You don't need to keep these definitions in a separate file from your                                     开源监控软件#      other object definitions.This has been done just to make things#      easier to understand.################################################################################################################################################################################################################################################ CONTACTS################################################################################################################################################################ Just one contact defined by default - the Nagios admin (that's you)# This contact definition inherits a lot of default values from the 'generic-contact'# template which is defined elsewhere.define contact{      contact_name            nagiosadmin                         use                                    generic-contact                     alias                           Nagios Admin                                                                              
      service_notification_period   24x7      host_notification_period         24x7      service_notification_options    w,u,c,r,f,s      host_notification_options      d,u,r,f,s      service_notification_commands   notify-service-by-email                                 host_notification_commands      notify-host-by-email       email                           15882026924@139.com       ;      }################################################################################################################################################################ CONTACT GROUPS################################################################################################################################################################ We only have one contact in this simple configuration file, so there is# no need to create more than one contact group.define contactgroup{      contactgroup_name       admins      alias                   Nagios Administrators      members               nagiosadmin      }# tail -20 services.cfg      }define service{      use                     local-service      host_name               Nagios-Linux      service_description   HTTP      check_command         check_nrpe!check_http      }define service{      use                     local-service      host_name               Nagios-Linux      service_description   MYSQL      check_command         check_nrpe!check_mysql            contact_groups            admins      }define service{      use                     local-service      host_name               Nagios-Linux      service_description   MYLOG      check_command         check_nrpe!check_mylog      }Cat command.cfg# 'notify-host-by-email' command definitiondefine command{       command_name       notify-host-by-email       command_line       /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$       }# 'notify-service-by-email' command definition                                                 nagios安装define command{       command_name       notify-service-by-email       command_line       /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$       }默认是配置好了这里就不用配置直接在contact和services中使用就好了把mysql停了uploads/img/201511/05030032_cpxO.jpg
验证成功,但是要注意需要把发件人的地址设置为白名单才可以收到uploads/img/201511/05030032_dWR4.jpg由于是手机邮件就实现了邮件短信同时提醒的功能,当然有邮件达到短信提醒的邮箱都能实现这个功能不一定是手机邮箱


想做Nagios, Zabbix,Cacti,iTop各种交流的,可以进入开源监控工具Nagios交流QQ群号 :476809427
页: [1]
查看完整版本: 从nagios上安装配置