Nagios配置

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

 

Nagios配置目录

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

clip_image002

 

配置文件简介

 

配置文件名

功能描述

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]#

clip_image004

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

clip_image006

 

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

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

clip_image008

3)修改nagios.cfg配置文件

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

clip_image010

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等配置修改过来。

clip_image012

clip_image014

 

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               bogonalias                   bogonaddress                 127.0.0.1}###############################################################################
###############################################################################
#
# HOST GROUP DEFINITION
#
###############################################################################
################################################################################ Define an optional hostgroup for Linux machines

define hostgroup{hostgroup_name  linux-servers ; The name of the hostgroupalias           Linux Servers ; Long name of the groupmembers         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 usehost_name                       bogonservice_description             PINGcheck_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 usehost_name                       bogonservice_description             Root Partitioncheck_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 usehost_name                       bogonservice_description             Current Userscheck_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 usehost_name                       bogonservice_description             Total Processescheck_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 usehost_name                       bogonservice_description             Current Loadcheck_command                   check_local_load!5.0,4.0,3.0!10.0,6.0,4.}# 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 usehost_name                       bogonservice_description             Swap Usagecheck_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 usehost_name                       bogonservice_description             SSHcheck_command                   check_sshnotifications_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 usehost_name                       bogonservice_description             HTTPcheck_command                   check_httpnotifications_enabled           0}

 

 

 

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

    启动Apache服务

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

    启动Nagios服务

    [root@bogon conf]# service nagios start

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

image

clip_image016

 

 

 

配置问题汇总:

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

 

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

clip_image018

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

#LoadModule cgid_module modules/mod_cgid.so

#LoadModule alias_module modules/mod_alias.so

#LoadModule actions_module modules/mod_actions.so   #暂未确定

在最后一行增加

AddDefaultCharset utf-8           #解决中文乱码问题

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

Not Found

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

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

问题3:Error: Could not open command file '/usr/local/nagios/var/rw/nagios.cmd'

关于这部分在nagios.cfg中有下面的内容

# EXTERNAL COMMAND FILE# This is the file that Nagios checks for external command requests.# It is also where the command CGI will write commands that are submitted# by users, so it must be writeable by the user that the web server# is running as (usually 'nobody').  Permissions should be set at the# directory level instead of on the file, as the file is deleted every# time its contents are processed.

 这段话的核心意思是apache的运行用户要有对文件写的权限.权限应该设置在目录上,因为每次文件的内容被处理后文件就会被删掉

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

首先,看一下你的进程,apache的进程,是什么用户运行,我的机器是daemon

#ps -ef | grep http

root 50297 1 0 21:42 ? 00:00:00 /usr/local/apache//bin/httpd -k start
daemon 50298 50297 0 21:42 ? 00:00:00 /usr/local/apache//bin/httpd -k start
daemon 50299 50297 0 21:42 ? 00:00:00 /usr/local/apache//bin/httpd -k start
daemon 50300 50297 0 21:42 ? 00:00:00 /usr/local/apache//bin/httpd -k start
daemon 50301 50297 0 21:42 ? 00:00:00 /usr/local/apache//bin/httpd -k start
daemon 50425 50297 0 21:43 ? 00:00:00 /usr/local/apache//bin/httpd -k start
root 50909 3194 0 22:02 pts/1 00:00:00 grep http

注意,这里指的是守护进程,而不是root运行的那个起始进程。

然后怎么做呢,如果你运行的nagios进程的用户是nagios,组也是nagios,则:

usermod -G nagios daemon
chmod g+s /path/to/nagiosdir/var/rw

转载于:https://www.cnblogs.com/Yongzhouunknown/p/4885749.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/419442.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

服务器启动时Webapp的web.xml中配置的加载顺序

一 1、启动一个WEB项目的时候&#xff0c;WEB容器会去读取它的配置文件web.xml&#xff0c;读取<listener>和<context-param>两个结点。 2、紧急着&#xff0c;容创建一个ServletContext&#xff08;servlet上下文&#xff09;&#xff0c;这个web项目的所有部分都…

JQuery.autocomplete扩展功能:实现多列自动提示

最近做一个项目&#xff0c;用到了JQuery的自动补全函数&#xff0c;但默认的是只显示一列数据&#xff0c;所以就略加修改&#xff0c;拿出来献丑了。 下面这个是默认调用本地数据&#xff1a; $("#tags").autocomplete(["c","java", &…

用java创建UDF,并用于Hive

典型代码如下&#xff1a; 导入UDF类&#xff1a; import org.apache.hadoop.hive.ql.exec.UDF; public class UpperCassUDF extends UDF{ public String evaluate(String input){ if(inputnull){ return null; } else{ return new String(input.toUpperCase()); } } } 导出jar…

单元素枚举类实现单例模式

本文转载自&#xff1a;点击打开链接 Inspired by Effective Java. Singleton模式是在编程实践中应用最广泛的几种设计模式之一。以前知道的&#xff0c;实现单例的方法有两种(下面的A、B)。刚刚在读《Effective Java的时候》学到一种新的更好的方法(E)&#xff1a;单元素的枚举…

java web开发之 spring单元测试

以前开发web项目从来不喜欢用单元测试&#xff0c;每次都需要启动服务器&#xff0c;在浏览器中调试&#xff0c;有些错误还不一定发现得到。 最近公司开发一个项目&#xff0c;任务繁重&#xff0c;不由觉得以前那种测试模式太笨拙了&#xff0c;于是学习了使用Junit&#xf…

对于SpringMVC框架使用的时候出现“警告: No mapping found for HTTP request with URI [/login]”的问题解决方案...

今天&#xff0c;在myeclipse上导入了前几天的一个项目&#xff0c;但是怎么都运行不起来&#xff0c;可是在别人的电脑上都可以。从早上一直调到了现在&#xff08;期间也看了好多关于此类的帖子&#xff0c;但是都没能解决我的问题&#xff09;&#xff0c;终于找到了解决方案…

MySQL数据库事务中的行级锁,表级锁,页级锁

锁定用于确保事务完整性和数据库一致性。 锁定可以防止用户读取其他用户正在更改的数据&#xff0c;并防止多个用户同时更改相同的数据。 如果不使用锁定&#xff0c;数据库中的数据可能在逻辑上变得不正确&#xff0c;而针对这些数据进行查询可能会产生想不到的结果。 在计算机…

#error

#define SIZE 250 #if SIZE<1 || SIZE>200 #error "SIZE must be between 1 and 200" #endif转载于:https://www.cnblogs.com/guxuanqing/p/4892802.html

搭建spring MVC项目

首先&#xff0c;是要放入spring mvc所需要的包&#xff1a; 如果不用json功能就不需要json和gson包,还有数据库驱动包&#xff0c;我这里是用的postgresql数据库&#xff0c;其他数据库需替换掉这个包 然后就是配置文件&#xff1a; 先是web.xml中需要加入以下内容&#xff…

换行的css属性

//正常换行word-break:keep-all;word-wrap:normal;//下面这行是自动换行word-break:break-all;word-wrap:break-word;word-wrap:normal | break-word; (内容换行)normal:默认的属性值.&#xff08;允许内容顶开指定的容器边界&#xff09;.break-word:内容将在边界内换行(不截断…

基于jquery.ajax的进一步封装

这是最近写项目用到的一个小功能&#xff0c;给大家分享下&#xff0c;希望对大家有帮助。 直接上代码&#xff1a; % page language"java" contentType"text/html; charsetUTF-8" pageEncoding"UTF-8"%> <!DOCTYPE html PUBLIC &quo…

Serena Dimensions 介绍

Serena Dimensions是配置管理工具&#xff0c;基于进程的软件更改和配置管理解决方案。 官方网址&#xff1a;http://www.serena.com/index.php/en/products/application-development/dimensions-cm/overview/ eclipse与Dimensions的集成 转载于:https://www.cnblogs.com/seabi…

pigeon服务

点击打开链接

使用jquery图表插件jqplot之折线图

首先一个简单的折线图&#xff1a; 直接上代码&#xff1a; <html> <head> <meta http-equiv"Content-Type" content"text/html; charsetutf-8"> <script type"text/javascript" src"js/jquery.min.js"></…

JQ调用后台方法

首先&#xff0c;先在页面上创建一个asp按钮&#xff0c;添加点击事件&#xff0c;把要在前台调用的后台方法写在这个按钮的点击事件中&#xff1a; <span style"display:none;"><asp:Button ID"btnSelectCategory" runat"server" type…

如何理解HTTP协议的 “无连接,无状态” 特点?

转载自&#xff1a;点击打开链接http://blog.csdn.net/tennysonsky/article/details/44562435 HTTP 是一个属于应用层的面向对象的协议&#xff0c;HTTP 协议一共有五大特点&#xff1a;1、支持客户/服务器模式&#xff1b;2、简单快速&#xff1b;3、灵活&#xff1b;4、无连接…

jqgrid使用

1.准备工作 首先&#xff0c;要引入基本的jquery文件&#xff0c;然后是下载jqgrid插件&#xff0c;我这里引入的有jquery.jqGrid.src.js,grid.setcolumns.js,grid.locale-en.js,jqgrid.css,ui.multiselect.css. 2.创建用来承载jqgrid的标签 <table id"gridTable"…

“睡服”面试官系列第一篇之let和const命令(建议收藏学习)

目录 1let命令 1.1基本用法 1.2for循环小案例 1.3不存在变量提升 1.4暂时性死区 1.5不允许重复声明 2块级作用域 2.1为什么需要块级作用域&#xff1f; 2.2ES6 的块级作用域 2.3块级作用域和函数声明 3const 3.1本质 4顶层对象的属性 5global对象 6总结 1let命令…

Java命名规范和代码风格

Java命名规范和代码风格 基本命名规范 包命名 包名按照域名的范围从大到小逐步列出&#xff0c;恰好和Internet上的域名命名规则相反。 由一组以“.”连接的标识符构成&#xff0c;通常第一个标识符为符合网络域名的两个或者三个英文小写字母。 例:cn.edu.xupt.JavaTest 类&…

jqgrid多选和禁止某行记录选择

在对一些特殊数据&#xff0c;我们总是要做一些防范手段。 在jqgrid中添加了多选属性后&#xff0c;默认是每一行都能自由选择。有时候&#xff0c;一些数据不满足某些情况是不让选中处理的。 怎么实现&#xff1f; 直接上代码&#xff1a; onSelectAll:function(rowid, status…