建湖做网站哪家最好,计算机网络中小型企业网络设计方案,北京网站建设公司哪些好,建筑工程网站建设其实上篇Nogios安装只是安装了Nagios基本组件#xff0c;虽然能够打开主页#xff0c;但是如果不配置相关配置文件文件#xff0c;那么左边菜单很多页面都打不开#xff0c;相当于只是一个空壳子。接下来#xff0c;我们来学习研究一下Nagios的配置,了解一下基本的配置和了…其实上篇Nogios安装只是安装了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 如下所示 [rootbogon etc]# cd /usr/local/nagios/etc/ [rootbogon etc]# ls cgi.cfg htpasswd nagios.cfg objects resource.cfg [rootbogon etc]# cd objects/ [rootbogon objects]# ls commands.cfg contacts.cfg localhost.cfg printer.cfg switch.cfg templates.cfg timeperiods.cfg windows.cfg [rootbogon objects]# 1)先修改cgi.cfg 在cgi.cfg文件中找到下面一些参数配置 default_user_nameguest authorized_for_system_informationnagiosadmin authorized_for_configuration_informationnagiosadmin authorized_for_system_commandsnagiosadmin authorized_for_all_servicesnagiosadmin authorized_for_all_hostsnagiosadmin authorized_for_all_service_commandsnagiosadmin authorized_for_all_host_commandsnagiosadmin 将这些参数配置修改为如下如果不清楚为什么是kerry参见上篇博客Nagios学习实践系列——基本安装篇解说 default_user_namekerry authorized_for_system_informationnagiosadmin,kerry authorized_for_configuration_informationnagiosadmin,kerry authorized_for_system_commandsnagiosadmin,kerry authorized_for_all_servicesnagiosadmin,kerry authorized_for_all_hostsnagiosadmin,kerry authorized_for_all_service_commandsnagiosadmin,kerry authorized_for_all_host_commandsnagiosadmin,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_interval1 #此参数暂时不配置 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 machinedefine 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 machinesdefine 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 machinedefine 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 freedefine 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服务 [rootbogon conf]# /usr/local/apache/bin/apachectl start 启动Nagios服务 [rootbogon conf]# service nagios start 如图所示就可监控当前服务器的负载、当前用户数、HTTP服务、SSH服务…. 配置问题汇总 在配置Nagios的过程中、总会碰到千奇百怪、各式各样的问题下面我慢慢收集整理碰到过得的一些问题当然这是我碰到没有碰到过得问题不做收录。 问题1Nagios配置好后启动了Apache、Nagios服务后进入Hosts、Services等界面时出现乱码如下图所示 这个问题是由于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包。 问题3Error: 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 startdaemon 50298 50297 0 21:42 ? 00:00:00 /usr/local/apache//bin/httpd -k startdaemon 50299 50297 0 21:42 ? 00:00:00 /usr/local/apache//bin/httpd -k startdaemon 50300 50297 0 21:42 ? 00:00:00 /usr/local/apache//bin/httpd -k startdaemon 50301 50297 0 21:42 ? 00:00:00 /usr/local/apache//bin/httpd -k startdaemon 50425 50297 0 21:43 ? 00:00:00 /usr/local/apache//bin/httpd -k startroot 50909 3194 0 22:02 pts/1 00:00:00 grep http 注意这里指的是守护进程而不是root运行的那个起始进程。然后怎么做呢如果你运行的nagios进程的用户是nagios,组也是nagios,则:usermod -G nagios daemonchmod gs /path/to/nagiosdir/var/rw转载于:https://www.cnblogs.com/Yongzhouunknown/p/4885749.html