其实上篇Nagios学习实践系列——基本安装篇只是安装了Nagios基本组件,虽然能够打开主页,但是如果不配置相关配置文件文件,那么左边菜单很多页面都打不开,相当于只是一个空壳子。接下来,我们来学习研究一下Nagios的配置,了解一下基本的配置和了解各类配置文件。

Nagios配置目录

Nagios的配置文件位于etc目录下(/usr/local/nagios/etc)如下图所示:

配置文件简介

配置文件名

功能描述

cgi.cfg

控制CGI访问的配置文件

nagios.cfg

主配置文件:主配置文件包括了一系列的设置,它们会影响Nagios守护进程

resource.cfg

资源配置文件:资源文件可以保存用户自定义的宏。资源文件的一个主要用途是保存一些敏感的配置信息,不能让CGIS程序模块获取到的信息

objects

objects是一个目录,在此目录下有很多配置文件,用于定义Nagios对象:commands.cfg、contacts.cfg、localhost.cfg

objects目录下的配置文件描述

配置文件名

功能描述

commands.cfg

命令定义配置文件,其中定义的命令可以被其他配置文件引用

contacts.cfg

定义联系人和联系人组的配置文件

localhost.cfg

定义监控本地主机的配置文件

printer.cfg

定义监控打印机的一个配置文件模板,默认没有启用此文件

switch.cfg

定义监控路由器的一个配置文件模板,默认没有启用此文件

templates.cfg

定义主机和服务的一个模板配置文件,可以在其他配置文件中引用

timeperiods.cfg

定义Nagios 监控时间段的配置文件

windows.cfg

监控Windows 主机的一个配置文件模板,默认没有启用此文件

实践配置步骤

下面修改配置信息,首先让Nagios监控本机的各种资源消耗。修改下面配置文件前,首先将各类配置文件备份一份,以免修改过程出现重大问题时,还能回滚到修改前版本(修改前先将配置文件copy一份,命名为xxxx.bak  如下所示)

[root@bogon etc]# cd /usr/local/nagios/etc/

[root@bogon etc]# ls

cgi.cfg  htpasswd  nagios.cfg  objects  resource.cfg

[root@bogon etc]# cd objects/

[root@bogon objects]# ls

commands.cfg  contacts.cfg  localhost.cfg  printer.cfg  switch.cfg  templates.cfg  timeperiods.cfg  windows.cfg

[root@bogon objects]#

1)先修改cgi.cfg

在cgi.cfg文件中,找到下面一些参数配置:

default_user_name=guest

authorized_for_system_information=nagiosadmin

authorized_for_configuration_information=nagiosadmin

authorized_for_system_commands=nagiosadmin

authorized_for_all_services=nagiosadmin

authorized_for_all_hosts=nagiosadmin

authorized_for_all_service_commands=nagiosadmin

authorized_for_all_host_commands=nagiosadmin

将这些参数配置修改为如下:(如果不清楚为什么是kerry,参见上篇博客Nagios学习实践系列——基本安装篇解说)

default_user_name=kerry

authorized_for_system_information=nagiosadmin,kerry

authorized_for_configuration_information=nagiosadmin,kerry

authorized_for_system_commands=nagiosadmin,kerry

authorized_for_all_services=nagiosadmin,kerry

authorized_for_all_hosts=nagiosadmin,kerry

authorized_for_all_service_commands=nagiosadmin,kerry

authorized_for_all_host_commands=nagiosadmin,kerry

2)修改resource.cfg配置文件。

如图所示,找到$USER1$=/usr/local/nagios//libexec 将其改为$USER1$=/usr/local/nagios/libexec

3)修改nagios.cfg配置文件

修改一系列的参数配置,将那些多余的/去掉

log_file=/usr/local/nagios/var/nagios.log

cfg_file=/usr/local/nagios/etc/objects/commands.cfg

cfg_file=/usr/local/nagios/etc/objects/contacts.cfg

cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg

cfg_file=/usr/local/nagios/etc/objects/templates.cfg

cfg_file=/usr/local/nagios/etc/objects/localhost.cfg

cfg_file=/usr/local/nagios/etc/objects/services.cfg

object_cache_file=/usr/local/nagios/var/objects.cache

precached_object_file=/usr/local/nagios/var/objects.precache

resource_file=/usr/local/nagios/etc/resource.cfg

status_file=/usr/local/nagios/var/status.dat

command_check_interval=1

command_file=/usr/local/nagios/var/rw/nagios.cmd

lock_file=/usr/local/nagios/var/nagios.lock

temp_file=/usr/local/nagios/var/nagios.tmp

log_archive_path=/usr/local/nagios/var/archives

check_result_path=/usr/local/nagios/var/spool/checkresults

state_retention_file=/usr/local/nagios/var/retention.dat

4)修改localhost.cfg配置文件

首先通过命令 hostname查看你监控主机的机器名,例如这次测试环境的主机名为bogon,进入localhost.cfg配置文件,将相应的

host_name或member等配置修改过来。

localhost.cfg文件的内容如下:

###############################################################################
# LOCALHOST.CFG - SAMPLE OBJECT CONFIG FILE FOR MONITORING THIS MACHINE
#
# Last Modified: 05-31-2007
#
# NOTE: This config file is intended to serve as an *extremely* simple
# example of how you can create configuration entries to monitor
# the local (Linux) machine.
#
############################################################################### ###############################################################################
###############################################################################
#
# HOST DEFINITION
#
###############################################################################
############################################################################### # Define a host for the local machine define host{
use linux-server ; Name of host template
to use
; This host definition w
ill inherit all variables that are defined
; in (or inherited by) t
he linux-server host template definition.
host_name bogon
alias bogon
address 127.0.0.1
} ###############################################################################
###############################################################################
#
# HOST GROUP DEFINITION
#
###############################################################################
############################################################################### # Define an optional hostgroup for Linux machines define hostgroup{
hostgroup_name linux-servers ; The name of the hostgroup
alias Linux Servers ; Long name of the group
members bogon ; Comma separated list of hosts that belong to
this group
} ###############################################################################
###############################################################################
#
# SERVICE DEFINITIONS
#
###############################################################################
############################################################################### # Define a service to "ping" the local machine define service{
use local-service ; Name of service
template to use
host_name bogon
service_description PING
check_command check_ping!100.0,20%!500.0,60%
} # Define a service to check the disk space of the root partition
# on the local machine. Warning if < 20% free, critical if
# < 10% free space on partition. define service{
use local-service ; Name of service
template to use
host_name bogon
service_description Root Partition
check_command check_local_disk!20%!10%!/
} # Define a service to check the number of currently logged in
# users on the local machine. Warning if > 20 users, critical
# if > 50 users. define service{
use local-service ; Name of service
template to use
host_name bogon
service_description Current Users
check_command check_local_users!20!50
} # Define a service to check the number of currently running procs
# on the local machine. Warning if > 250 processes, critical if
# > 400 users. define service{
use local-service ; Name of service
template to use
host_name bogon
service_description Total Processes
check_command check_local_procs!250!400!RSZDT
} # Define a service to check the load on the local machine. define service{
use local-service ; Name of service
template to use
host_name bogon
service_description Current Load
check_command check_local_load!5.0,4.0,3.0!10.0,6.0,4.
0
} # Define a service to check the swap usage the local machine.
# Critical if less than 10% of swap is free, warning if less than 20% is free define service{
use local-service ; Name of service
template to use
host_name bogon
service_description Swap Usage
check_command check_local_swap!20!10
} # Define a service to check SSH on the local machine.
# Disable notifications for this service by default, as not all users may have S
SH enabled. define service{
use local-service ; Name of service
template to use
host_name bogon
service_description SSH
check_command check_ssh
notifications_enabled 0
} # Define a service to check HTTP on the local machine.
# Disable notifications for this service by default, as not all users may have H
TTP enabled. define service{
use local-service ; Name of service
template to use
host_name bogon
service_description HTTP
check_command check_http
notifications_enabled 0
}

基本配置完成后,我们启动Nagios、Apache服务

启动Apache服务

[root@bogon conf]# /usr/local/apache/bin/apachectl start

启动Nagios服务

[root@bogon conf]# service nagios start

如图所示,就可监控当前服务器的负载、当前用户数、HTTP服务、SSH服务….

配置问题汇总:

在配置Nagios的过程中、总会碰到千奇百怪、各式各样的问题,下面我慢慢收集整理碰到过得的一些问题,当然这是我碰到,没有碰到过得问题,不做收录。

问题1:Nagios配置好后,启动了Apache、Nagios服务后,进入Hosts、Services等界面时,出现乱码,如下图所示:

这个问题是由于Apache没有开启cgi脚本的缘故,进入apache的主配置文件目录,修改配置文件httpd.conf,将下面两行的注释取消,重启服务即可解决问题。

#LoadModule cgid_module modules/mod_cgid.so

#LoadModule alias_module modules/mod_alias.so

问题2:点击Map页面,出现下面错误信息(红色部分):

Not Found

The requested URL /nagios/cgi-bin/statusmap.cgi was not found on this server.

出现这个错误,是因为没有安装gd-devel包导致,需要安装gd-devel包。

Nagios学习实践系列——配置研究[监控当前服务器]的更多相关文章

  1. Nagios学习实践系列——基本安装篇

    开篇介绍 最近由于工作需要,学习研究了一下Nagios的安装.配置.使用,关于Nagios的介绍,可以参考我上篇随笔Nagios学习实践系列——产品介绍篇 实验环境 操作系统:Red Hat Ente ...

  2. Nagios学习实践系列

    其实上篇Nagios学习实践系列--基本安装篇只是安装了Nagios基本组件,虽然能够打开主页,但是如果不配置相关配置文件文件,那么左边菜单很多页面都打不开,相当于只是一个空壳子.接下来,我们来学习研 ...

  3. Nagios学习实践系列——产品介绍篇

    Nagios介绍 Nagios是一款功能强大.优秀的开源监控系统,它能够让你发现和解决IT架构中存在的问题,避免这些问题影响到关键业务流程. Nagios最早于1999年发布,它在开源社区的影响力是相 ...

  4. 深度学习实践系列(2)- 搭建notMNIST的深度神经网络

    如果你希望系统性的了解神经网络,请参考零基础入门深度学习系列,下面我会粗略的介绍一下本文中实现神经网络需要了解的知识. 什么是深度神经网络? 神经网络包含三层:输入层(X).隐藏层和输出层:f(x) ...

  5. 深度学习实践系列(3)- 使用Keras搭建notMNIST的神经网络

    前期回顾: 深度学习实践系列(1)- 从零搭建notMNIST逻辑回归模型 深度学习实践系列(2)- 搭建notMNIST的深度神经网络 在第二篇系列中,我们使用了TensorFlow搭建了第一个深度 ...

  6. Nagios学习笔记四:基于NRPE监控远程Linux主机

    1.NRPE简介 Nagios监控远程主机的方法有多种,其方式包括SNMP.NRPE.SSH和NCSA等.这里介绍其通过NRPE监控远程Linux主机的方式. NRPE(Nagios Remote P ...

  7. .NET Core on K8S学习实践系列文章索引(Draft版)

    一.关于这个系列 自从去年(2018年)底离开工作了3年的M公司加入X公司之后,开始了ASP.NET Core的实践,包括微服务架构与容器化等等.我们的实践是渐进的,当我们的微服务数量到了一定值时,发 ...

  8. Nagios学习笔记三:配置Nagios

    1.Nagios的主配置文件 Nagios的主配置文件为nagios.cfg,其语法非常简洁,通常#开头的行为注释行,而参数的设置格式为<parameter>=<value>: ...

  9. 深度学习实践系列(1)- 从零搭建notMNIST逻辑回归模型

    MNIST 被喻为深度学习中的Hello World示例,由Yann LeCun等大神组织收集的一个手写数字的数据集,有60000个训练集和10000个验证集,是个非常适合初学者入门的训练集.这个网站 ...

随机推荐

  1. php+phpStorm+xdebug配置方法

    1.下载xdebug文件 http://xdebug.org/wizard.php 将phpinfo()的源代码复制到文本框中,xdebug会提示如何配置和下载哪个版本的xdebug. 全部下载地址: ...

  2. DOM 节点的克隆与删除

    无奈的开头 关于DOM节点操作,如果仅仅是根据标准API来操作,那是最简单不过的了.但是现实中却哪有这么容易的问题让我们解决,其实不仅仅是节点的克隆与删除,节点的添加也是如此,而且添加节点需要考虑的情 ...

  3. 非对称技术栈实现AES加密解密

    非对称技术栈实现AES加密解密 正如前面的一篇文章所述,https协议的SSL层是实现在传输层之上,应用层之下,也就是说在应用层上看到的请求还是明码的,对于某些场景下要求这些http请求参数是非可读的 ...

  4. 敏捷开发Scrum

  5. 优化MySchool数据库设计

    第一章 数据库的设计 1.E-R图中: 矩形:实体 椭圆:属性 菱形:关系 直线:连接实体,属性和关系 2.映射基数 一对多 多对一 多对多 3.范式: 第一范式:确保每列的原子性 第二范式:确保表中 ...

  6. C#基础知识一之base关键字

    前言 其实很早就想写关于C#基础,总是自己给自己找借口,或者去网上搜搜看看,现在想想觉得自己有点懒惰...  作为开发人员,基础知识是重中之重的,只有巩固.理解.实践才能提高自身的技能.同时也希望通过 ...

  7. ASP.NET MVC 之自定义HtmlHelper

    前言 HtmlHelper方法为我们提供很多html标签,只需在页面调用就行了,但是微软并没有把所有的html标签都对应有了扩展方法,需要我们重新自定义HtmlHelper,来满足我们需要. 方法 如 ...

  8. Android开发之重力传感器

    重力传感器与方向传感器的开发步骤类似,只要理清了期中的x,y,z的值之后就可以根据他们的变化来进行编程了,首先来看一副图 假设当地的重力加速度值为g 当手机正面朝上的时候,z的值为q,反面朝上的时候, ...

  9. svn提交时出现很多乱文件怎么解决

    在我们开发项目中的时候经常使用到svn,有时候我们commit的时候回出现很多无用的文件,这些文件就是未版本化的文件,怎么解决这些乱文件的问题呢? svn commit提交的时候有个"sho ...

  10. Lind.DDD.Repositories.Redis层介绍

    回到目录 之前已经发生了 大叔之前介绍过关于redis的文章,有缓存,队列,分布式pub/sub,数据集缓存以及仓储redis的实现等等,而今天在Lind.DDD的持久化组件里,redis当然也有一席 ...