nagios安装配置

第一步:

安装软件:分为nagios监控端和nagios被监控端

监控端软件列表

05030030_5Yxe.jpg

Nagios安装包05030030_tg29.jpg

Nagios插件安装包05030030_SXjZ.jpg

Nagios中文支持包05030030_T7ZK.jpg

Nrpe软件包05030030_TvLO.jpg

nagios通过nrpe来远端管理服务

1. nagios执行安装在它里面的check_nrpe 插件,并告诉check_nrpe 去检测哪些服务。

2. 通过ssl,check_nrpe 连接远端机子上的nrpe daemon

3. nrpe运行本地的各种插件去检测本地的服务和状态

4. nrpe把检测的结果传给主机端的check_nrpe, 主机端的check_nrpe再把结果送到nagios状态队列中。

5. nagios 依次读取队列中的信息,再把结果显示出来。

解决编译软件时需要的依赖

[root@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/nagios

2.   make all

3.   make install

4.   make install-init

5.    make install-commandmode

6.    make install-config

7.    chkconfig --add nagios

8.    chkconfig --level 35 nagios on

9.    tar -xzvf nagios-plugins-1.4.14.tar.gz

10.   ./configure --prefix=/usr/local/nagios

11.   make && make install

12.   yum install httpd

13.   yum install php

14.   vim /etc/httpd/conf/httpd.conf

添加以下内容

05030030_VizB.jpg

修改用户

05030030_rUum.jpg

 

15.   添加密码

htpasswd -c /usr/local/nagios/etc/htpasswd oracle

 

16.   /etc/init.d/httpd start

17.   tar -xjvf nagios-cn-3.2.0.tar.bz2

18.   ./configure 

19.   make && make install

监控端nagios安装完毕

重启httpd和启动nagios

可以看到以下画面

05030030_DmRk.jpg

这里你要输入刚才设置的用户和密码


在没有修改配置的情况下,默认只能查看到本机

05030031_Eehy.jpg

好的 下面来添加主机

会用到以下几个文件,其他文件就由各位下去自己慢慢研究了,我手懒

05030031_Lnd6.jpg

其中以下两个文件需要手动创建

05030031_8PXl.jpg

 

定义被监控主机

[root@www objects]# cat hosts.cfg

define host{  

        use                     linux-server     使用templates.cfg定义的 

        host_name             Nagios-Linux    自己取的名字并不一定是主机名

        alias                    Nagios-Linux    别名     

        address                 192.168.1.201  被监控主机      

        }  

定义监控内容也就是监控命令

[root@www objects]# cat services.cfg

define 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的方式来启动

安装nrep

  161  ./configure

  162  make all

  163  make install-plugin

  164  make install-daemon-config

  165  make install-xinetd

 

 

 

vim /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

[root@www libexec]# vim /usr/local/nagios/etc/nrpe.cfg

log_facility=daemon

pid_file=/var/run/nrpe.pid

server_port=5666

nrpe_user=nagios

nrpe_group=nagios

allowed_hosts=127.0.0.1

dont_blame_nrpe=0

debug=0

command_timeout=60

connection_timeout=300

command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10

command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20

command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1

command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z

command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200

command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%

command[check_http]=/usr/local/nagios/libexec/check_http -I 127.0.0.1

command[check_mysql]=/usr/local/nagios/libexec/check_mysql

command[check_mylog]=/usr/local/nagios/libexec/check_mylog

自己定义的插件

[root@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 0

elif [ $count -ge 1 -a $count -le 10 ] ;then

       echo "MYLOG IS WARNING"

       exit 1

elif [ $count -ge 11 ];then

       echo "MYLOG IS CRITICAL"

       exit 2

elif [ $count -lt 0 ];then

       echo "UNKNOWN"

       exit 3

If

0 表示OK

1 表示WARNNING

2 表示 CRITICAL

3 表示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 definition

define command{

        command_name    check_nrpe     

        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ 

                       

        }

 

 

重启服务端服务

05030031_blx2.jpg

就会出现我们定义的主机

05030031_cUAn.jpg

例如我现在关闭mysql

05030031_YScC.jpg

05030031_xVPi.jpg

这里就可以看到mysql的监控状态为紧急

 

现在恢复mysql

05030031_Zdag.jpg

05030031_wvKW.jpg

可以看到mysql监控状态为ok

下面我来实现故障告警功能

使用邮件告警

[root@www objects]# 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

        }

 

 

 

[root@www objects]# 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 definition

define 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

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停了

05030032_cpxO.jpg

 


验证成功,但是要注意需要把发件人的地址设置为白名单才可以收到

05030032_dWR4.jpg

由于是手机邮件就实现了邮件短信同时提醒的功能,当然有邮件达到短信提醒的邮箱都能实现这个功能不一定是手机邮箱

 


转载于:https://my.oschina.net/eddylinux/blog/526082

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
智慧校园整体解决方案是响应国家教育信息化政策,结合教育改革和技术创新的产物。该方案以物联网、大数据、人工智能和移动互联技术为基础,旨在打造一个安全、高效、互动且环保的教育环境。方案强调从数字化校园向智慧校园的转变,通过自动数据采集、智能分析和按需服务,实现校园业务的智能化管理。 方案的总体设计原则包括应用至上、分层设计和互联互通,确保系统能够满足不同用户角色的需求,并实现数据和资源的整合与共享。框架设计涵盖了校园安全、管理、教学、环境等多个方面,构建了一个全面的校园应用生态系统。这包括智慧安全系统、校园身份识别、智能排课及选课系统、智慧学习系统、精品录播教室方案等,以支持个性化学习和教学评估。 建设内容突出了智慧安全和智慧管理的重要性。智慧安全管理通过分布式录播系统和紧急预案一键启动功能,增强校园安全预警和事件响应能力。智慧管理系统则利用物联网技术,实现人员和设备的智能管理,提高校园运营效率。 智慧教学部分,方案提供了智慧学习系统和精品录播教室方案,支持专业级学习硬件和智能化网络管理,促进个性化学习和教学资源的高效利用。同时,教学质量评估中心和资源应用平台的建设,旨在提升教学评估的科学性和教育资源的共享性。 智慧环境建设则侧重于基于物联网的设备管理,通过智慧教室管理系统实现教室环境的智能控制和能效管理,打造绿色、节能的校园环境。电子班牌和校园信息发布系统的建设,将作为智慧校园的核心和入口,提供教务、一卡通、图书馆等系统的集成信息。 总体而言,智慧校园整体解决方案通过集成先进技术,不仅提升了校园的信息化水平,而且优化了教学和管理流程,为学生、教师和家长提供了更加便捷、个性化的教育体验。
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值