Centos部署nagios+apache实现服务器监控

1.Nagios介绍

  nagios是 一款功能强大的网络监视工具,它可以有效的监控windows、linux、unix主机状态以及路由器交换机的网络设置,打印机工作状态等,并将状态出 现异常的服务及时以邮件、msn短信等形式第一时间通告管理员。由于它是一款遵循GPLv2的开源网络监控软件,以其出色的性能低廉的使用成本,深受广大 用户的好评。

2.安装前提

2. 1确定是否有以下组件:

gcc glibc glibc-common gd gd-devel xinetd openssl-devel

  proc-devel pcre-devel perl  libxml2-devel

  直接通过yum安装:

yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel proc-devel pcre-devel perl libxml2-devel

3.安装nagios,nagios-plugin

  创建nagios用户

  #  adduser nagios

  安装nagios

  #  tar xvf nagios-cn-3.2.0.tar

  #  cd nagios-cn-3.2.0

  #  ./configure –prefix=/usr/local/nagios

  #  make all

  #  make install

  #  make install-init

  #  make install-commandmode

  #  make install-config

  安装nagios-plugin

  #  tar xvf nagios-plugins-2.0.tar.gz

  #  cd  nagios-plugins-2.0

  #  ./configure –prefix=/usr/local/nagios

  # make && make install

4.安装apache

  # tar xvf httpd-2.4.9.tar.gz

  #cd httpd-2.4.9

  #./configure --prefix=/usr/local/apache2

  # make && make install

  如果安装提示缺少apr和apr-util包

  #tar xvf apr-1.5.0.tar.gz

  #cd apr-1.5.0

  #./configure  –prefix=/usr/local/apr

  #make && make install

  #tar xvf apr-1.5.0.tar.gz

  #cd apr-1.5.0

  #./configure  –prefix=/usr/local/apr-util –with-apr=/usr/local/apr

  #make && make install

  安装好了之后在安装apache

  #./configure --prefix=/usr/local/apache2 –with-apr-util=/usr/local/apr-util

  #make && make install

5.安装php

  #tar xvf php-5.4.10.tar.gz

  #cd php-5.4.10

  #./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs

  #make && make install

6.配置apahe

  找到apache 的配置文件/usr/local/apache2/conf/httpd.conf

  找到:

User daemon

Group daemon

修改为

User nagios

Group nagios

然后找到

<IfModule dir_module>

  DirectoryIndex index.html

</IfModule>

修改为

<IfModule dir_module>

  DirectoryIndex index.html index.php

  AddType application/x-httpd-php .php

</IfModule>

  为了安全起见,一般情况下要让nagios 的web 监控页面必须经过授权才能访问,这需要增加验证配置,即在httpd.conf 文件最后添加如下信息:

#setting for nagios

ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"

<Directory "/usr/local/nagios/sbin">

AuthType Basic

Options ExecCGI

AllowOverride None

Order allow,deny

Allow from all

AuthName "Nagios Access"

AuthUserFile /usr/local/nagios/etc/htpasswd

Require valid-user

</Directory>

Alias /nagios "/usr/local/nagios/share"

<Directory "/usr/local/nagios/share">

AuthType Basic

Options None

AllowOverride None

Order allow,deny

Allow from all

AuthName "nagios Access"

AuthUserFile /usr/local/nagios/etc/htpasswd

Require valid-user

</Directory>

  创建apache目录验证文件

  # /usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd ssap

7.启动apache和nagios

  启动apache

  # /usr/local/apache2/bin/apachectl start

  启动nagios

  Service nagios start

nagios登录

nagios首页

8.配置nagios

  Nagios安装完毕后,需要配置nagios,配置文件在/usr/local/nagios/etc目录下。


文件名或目录名


用途


cgi.cfg


控制CGI访问的配置文件


nagios.cfg


Nagios 主配置文件


resource.cfg


变量定义文件,又称为资源文件,在些文件中定义变量,以便由其他配置文件引用,如$USER1$


objects


objects 是一个目录,在此目录下有很多配置文件模板,用于定义Nagios 对象


objects/commands.cfg


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


objects/contacts.cfg


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


objects/localhost.cfg


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


objects/printer.cfg


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


objects/switch.cfg


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


objects/templates.cfg


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


objects/timeperiods.cfg


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


objects/windows.cfg


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

  假设我们nagios安装在IP为192.168.195.136的服务器上,需要监控192.168.195.136服务器,将对配置文件做以下修改:

  修改localhost.cfg

  define host{

  use                             linux-server

  host_name               Nagios-Server

  alias                           Nagios-Server

  address                     127.0.0.1

  }

  define hostgroup{

  hostgroup_name    linux-servers

  alias                           Linux Servers

  members                  Nagios-Server

  }

  define service{

  use                                     local-service

  host_name                       Nagios-Server

  service_description        PING

  check_command            check_ping!100.0,20%!500.0,60%

  }

  define service{

  use                                     local-service

  host_name                       Nagios-Server

  service_description        Root Partition

  check_command             check_local_disk!20%!10%!/

  }

  define service{

  use                                     local-service

  host_name                       Nagios-Server

  service_description         Current Users

  check_command              check_local_users!20!50

  }

  define service{

  use                                     local-service

  host_name                       Nagios-Server

  service_description        Total Processes

  check_command             check_local_procs!250!400!RSZDT

  }

  define service{

  use                                     local-service,srv-pnp

  host_name                       Nagios-Server

  service_description        Current Load

  check_command             check_local_load!5.0,4.0,3.0!10.0,6.0,4.0

  }

  define service{

  use                                     local-service

  host_name                       Nagios-Server

  service_description        Swap Usage

  check_command             check_local_swap!20!10

  }

  define service{

  use                                     local-service

  host_name                       Nagios-Server

  service_description        SSH

  check_command             check_ssh

  notifications_enabled     0

  }

  define service{

  use                                     local-service

  host_name                       Nagios-Server

  service_description         HTTP

  check_command              check_http

  notifications_enabled      0

  }

  新增hosts.cfg

  define host{

  use                     linux-server

  host_name       test-Linux

  alias                   test-Linux

  address             192.168.195.137

  }

  新增service.cfg

  define service{

  use                                 local-service

  host_name                   test-Linux

  service_description     check-host-alive

  check_command          check-host-alive

  }

  修改nagios.cfg

  添加配置文件hosts.cfg,service.cfg

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

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

  检测修改的配置

  /usr/local/nagios/bin/nagios –v /usr/local/nagios/etc/nagios.cfg

  检测无误后,重新启动nagios服务

  Service nagios restart

nagios监控页

注意事项:

1) 如果设置的用户名不是nagiosadmin,会存在权限问题,不能访问监控页面,需要修改cgi.cfg,在nagiosadmin后追加自己设置的用户名。

nagios登录用户权限配置

2)Nagios乱码问题

  主要是apache没有开启cgi脚本的缘故,进入apache的主配置文件httpd.conf;

  #LoadModule cgid_module modules/mod_cgid.so;

  #LoadModule actions_module modules/mod_actions.so;

  将上面2行的#去掉,重启apache就OK了。

时间: 2025-01-08 09:30:54

Centos部署nagios+apache实现服务器监控的相关文章

部署监控三剑客 Nagios 服务器监控

Nagios 简介 : Nagios是一款开源的免费网络监视工具,能有效监控Windows.Linux和Unix的主机状态,交换机路由器等网络设备,打印机等.在系统或服务状态异常时发出邮件或短信报警第一时间通知网站运维人员,在状态恢复后发出正常的邮件或短信通知. Nagios 可以监控的功能有: 1.监控网络服务(SMTP.POP3.HTTP.NNTP.PING等): 2.监控主机资源(处理器负荷.磁盘利用率等): 3.简单地插件设计使得用户可以方便地扩展自己服务的检测方法: 4.并行服务检查机

盘点:zabbix、cacti、nagios,服务器监控哪个好?

目前使用比较多的服务器监控软件有这三款:zabbix.cacti.nagios,简单介绍一下这三个软件. 1.zabbixzabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案.zabbix能监视各种网络参数,保证服务器系统的安全运营:并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题. 2.cactiCacti是一套基于PHP,MySQL,SNMP及RRDTool开发的网络流量监测图形工具. 3.nagiosNagios是一款开源的免费网络监视工

Django部署到Apache服务器

Django项目本身就可以启动运行,为什么还需要部署到Apache或者Nginx上呢?初学者都会遇到这个问题,我们来看看官方解释:It's intended only for use while developing. (We're in the business of making Web frameworks, not Web servers.),意思是django的业务是制作Web框架,而不是Web服务器.自带的web server只是方便开发,并不能直接放到生产环境,有兴趣的同学可以自己

阿里云centos部署apache+php

经过一个下午的尝试,终于完成了阿里云apache+php服务器的搭建,我的数据库用的是阿里云的RDS,不需要在服务器中安装mysql了.在我的服务器中最后部署了phpMyAdmin,测试可以管理RDS上的数据库.服务器的搭建宣布完成.留下了做个记录.下次再部署的话就不用大量的搜索和尝试了. 一.下载Xshell+xftp,安装xftp. 二.Xshell新建连接,服务器的外网IP,用户名:root,密码:连接服务的密码 三.打开刚创建的连接,确保成功连接到服务器 四.因为我没有买数据盘,所以数据

阿里云云服务器CentOS上安装Apache

云服务器操作系统:CentOS 6.2 64位 客户端操作环境:Putty 操作步骤: 1. 运行 Putty,输入用户名,然后输入密码. 2. 安装 Apache 软件:yum install httpd 3. 设置 Apache 在服务器启动时运行:chkconfig --levels 235 httpd on 4. 在 Apache 配置文件中配置域名:vi /etc/httpd/conf/httpd.conf,找到 ServerName ,添加“域名:80”,保存并退出. 5. 重启 A

centos 搭建 nagios 监控系统.

linux下搭建nagios监控 一.什么是nagios 1.nagios 简介 Nagios是一个监视系统运行状态和网络信息的监视系统. Nagios能监视所指定的本地或远程主机以及服务,同时提供异常通知功能等. Nagios可运行在Linux/Unix平台之上,同时提供一个可选的基于浏览器的WEB界面以方便系统管理人员查看网络状态, 各种系统问题,以及日志等等. Nagios是十分受欢迎的.开源且免费的计算机及网络系统监控软件. Nagios是"Nagios Ain't Gonna Insi

Ubuntu Server 安装部署 Cacti 服务器监控

Ubuntu Server 安装部署 Cacti 服务器监控 form :http://www.cnblogs.com/xuri/p/3379337.html

服务器监控-nagios安装篇

一:安装前准备 nagios server:192.168.1.10 nagios client:192.168.1.11 该博文安装nagios只使用nagios邮件报警功能,如需画图另外安装cacti,或其他插件 二:安装服务 在nagios server上操作: 安装Apache+php yum install httpd httpd-devel php php-mysql php-common php-gd php-mbstring php-mcrypt php-devel php-xm

CentOS下nagios报警飞信部署四步走

CentOS下nagios报警飞信部署四步走 今天 帮群里一兄弟配了下nagios上的飞信,这个东西 我个人感觉还是很实用的,不过好久没配了,今天配置了一遍,顺便 就把过程记录下来了,供大家学习!!! 一.安装飞信 cd /root/toolswget http://ebook.elain.org/tools/fetion20101205.tar.gz 安装步骤略,软件包中有添加要接收报警短信的手机号为飞信好友 /usr/local/fetion/fetion --mobile=137xxxxx