ubuntu下nagios配置
参考文献:
声明
一、Nagios简介
Nagios是一款开源的电脑系统和网络监视工具,能有效监控Windows、Linux和Unix的主机状态,交换机路由器等网络设置,打印机等。在系统或服务状态异常时发出邮件或短信报警第一时间通知网站运维人员,在状态恢复后发出正常的邮件或短信通知。
Nagios原名为NetSaint,由Ethan Galstad开发并维护至今。NAGIOS是一个缩写形式: "Nagios Ain't Gonna Insist On Sainthood" Sainthood 翻译为圣徒,而"Agios"是"saint"的希腊表示方法。Nagios被开发在Linux下使用,但在Unix下也工作得非常好。
主要功能
- 网络服务监控(SMTP、POP3、HTTP、NNTP、ICMP、SNMP、FTP、SSH)
- 主机资源监控(CPU load、disk usage、system logs),也包括Windows主机(使用NSClient++ plugin)
- 可以指定自己编写的Plugin通过网络收集数据来监控任何情况(温度、警告……)
- 可以通过配置Nagios远程执行插件远程执行脚本(这个非常意义,这样就省去了ssh连接远程服务器在执行命令的麻烦)
- 远程监控支持SSH或SSL加通道方式进行监控
- 简单的plugin设计允许用户很容易的开发自己需要的检查服务,支持很多开发语言(shell scripts、C++、Perl、ruby、Python、PHP、C#等)
- 包含很多图形化数据Plugins(Nagiosgraph、Nagiosgrapher、PNP4Nagios等)
- 可并行服务检查
- 能够定义网络主机的层次,允许逐级检查,就是从父主机开始向下检查
- 当服务或主机出现问题时发出通告,可通过email, pager, sms 或任意用户自定义的plugin进行通知(不知道是否能够支持短信包)
- 能够自定义事件处理机制重新激活出问题的服务或主机
- 自动日志循环
- 支持冗余监控
- 包括Web界面可以查看当前网络状态,通知,问题历史,日志文件等
二、Nagios工作原理
Nagios的功能是监控服务和主机,但是他自身并不包括这部分功能,所有的监控、检测功能都是通过各种插件来完成的。
启动Nagios后,它会周期性的自动调用插件去检测服务器状态,同时Nagios会维持一个队列,所有插件返回来的状态信息都进入队列,Nagios每次都从队首开始读取信息,并进行处理后,把状态结果通过web显示出来。
Nagios提供了许多插件,利用这些插件可以方便的监控很多服务状态。安装完成后,在nagios主目录下的/libexec里放有nagios自带的可以使用的所有插件,如,check_disk是检查磁盘空间的插件,check_load是检查CPU负载的,等等。每一个插件可以通过运行./check_xxx –h 来查看其使用方法和功能。比如下述代码就是check_disk的使用方法。
enadmin@ubuntu-server:/usr/local/nagios/libexec$ ./check_disk -h
check_disk v2. (nagios-plugins 2.0)
Copyright (c) Ethan Galstad <nagios@nagios.org>
Copyright (c) - Nagios Plugin Development Team
<devel@nagios-plugins.org> This plugin checks the amount of used disk space on a mounted file system
and generates an alert if free space is less than one of the threshold values Usage:
check_disk -w limit -c limit [-W limit] [-K limit] {-p path | -x device}
[-C] [-E] [-e] [-f] [-g group ] [-k] [-l] [-M] [-m] [-R path ] [-r path ]
[-t timeout] [-u unit] [-v] [-X type] [-N type] [-n] Options:
-h, --help
Print detailed help screen
-V, --version
Print version information
--extra-opts=[section][@file]
Read options from an ini file. See
https://www.nagios-plugins.org/doc/extra-opts.html
for usage and examples.
-w, --warning=INTEGER
Exit with WARNING status if less than INTEGER units of disk are free
-w, --warning=PERCENT%
Exit with WARNING status if less than PERCENT of disk space is free
-c, --critical=INTEGER
Exit with CRITICAL status if less than INTEGER units of disk are free
-c, --critical=PERCENT%
Exit with CRITICAL status if less than PERCENT of disk space is free
-W, --iwarning=PERCENT%
Exit with WARNING status if less than PERCENT of inode space is free
-K, --icritical=PERCENT%
Exit with CRITICAL status if less than PERCENT of inode space is free
-p, --path=PATH, --partition=PARTITION
Mount point or block device as emitted by the mount() command (may be repeated)
-x, --exclude_device=PATH <STRING>
Ignore device (only works if -p unspecified)
-C, --clear
Clear thresholds
-E, --exact-match
For paths or partitions specified with -p, only check for exact paths
-e, --errors-only
Display only devices/mountpoints with errors
-f, --freespace-ignore-reserved
Don't account root-reserved blocks into freespace in perfdata
-g, --group=NAME
Group paths. Thresholds apply to (free-)space of all partitions together
-k, --kilobytes
Same as '--units kB'
-l, --local
Only check local filesystems
-L, --stat-remote-fs
Only check local filesystems against thresholds. Yet call stat on remote filesystems
to test if they are accessible (e.g. to detect Stale NFS Handles)
-M, --mountpoint
Display the mountpoint instead of the partition
-m, --megabytes
Same as '--units MB'
-A, --all
Explicitly select all paths. This is equivalent to -R '.*'
-R, --eregi-path=PATH, --eregi-partition=PARTITION
Case insensitive regular expression for path/partition (may be repeated)
-r, --ereg-path=PATH, --ereg-partition=PARTITION
Regular expression for path or partition (may be repeated)
-I, --ignore-eregi-path=PATH, --ignore-eregi-partition=PARTITION
Regular expression to ignore selected path/partition (case insensitive) (may be repeated)
-i, --ignore-ereg-path=PATH, --ignore-ereg-partition=PARTITION
Regular expression to ignore selected path or partition (may be repeated)
-t, --timeout=INTEGER
Seconds before plugin times out (default: )
-u, --units=STRING
Choose bytes, kB, MB, GB, TB (default: MB)
-v, --verbose
Show details for command-line debugging (Nagios may truncate output)
-X, --exclude-type=TYPE
Ignore all filesystems of indicated type (may be repeated)
-N, --include-type=TYPE
Check only filesystems of indicated type (may be repeated)
-n, --newlines
Multi-line output of each disk's status information on a new line Examples:
check_disk -w % -c % -p /tmp -p /var -C -w -c -p /
Checks /tmp and /var at % and %, and / at 100MB and 50MB
check_disk -w -c -C -w -c -g sidDATA -r '^/oracle/SID/data.*$'
Checks all filesystems not matching -r at 100M and 50M. The fs matching the -r regex
are grouped which means the freespace thresholds are applied to all disks together
check_disk -w -c -C -w -c -p /foo -C -w % -c % -p /bar
Checks /foo for 1000M/500M and /bar for /%. All remaining volumes use 100M/50M Send email to help@nagios-plugins.org if you have questions regarding use
of this software. To submit patches or suggest improvements, send email to
devel@nagios-plugins.org
Nagios可以识别4种状态返回信息,即 0(OK)表示状态正常/绿色、1(WARNING)表示出现警告/黄色、2(CRITICAL)表示出现非常严重的错误/红色、3(UNKNOWN)表示未知错误/深黄色。Nagios根据插件返回来的值,来判断监控对象的状态,并通过web显示出来,以供管理员及时发现故障。
四种监控状态

再说报警功能,如果监控系统发现问题不能报警那就没有意义了,所以报警也是nagios很重要的功能之一。但是,同样的,Nagios 自身也没有报警部分的代码,甚至没有插件,而是交给用户或者其他相关开源项目组去完成的。(我使用的是ubuntu下msmtp+mutt的安装和配置这个方法)
Nagios 安装,是指基本平台,也就是Nagios软件包的安装。它是监控体系的框架,也是所有监控的基础。
打开Nagios官方的文档,会发现Nagios基本上没有什么依赖包,只要求系统是Linux或者其他Nagios支持的系统。不过如果你没有安装apache(http服务),那么你就没有那么直观的界面来查看监控信息了,所以apache姑且算是一个前提条件。关于apache的安装,网上有很多,照着安装就是了。安装之后要检查一下是否可以正常工作。
知道Nagios 是如何通过插件来管理服务器对象后,现在开始研究它是如何管理远端服务器对象的。Nagios 系统提供了一个插件NRPE。Nagios 通过周期性的运行它来获得远端服务器的各种状态信息。它们之间的关系如下图所示:

Nagios 通过NRPE 来远端管理服务
1. Nagios 执行安装在它里面的check_nrpe 插件,并告诉check_nrpe 去检测哪些服务。
2. 通过SSL,check_nrpe 连接远端机子上的NRPE daemon
3. NRPE 运行本地的各种插件去检测本地的服务和状态(check_disk,..etc)
4. 最后,NRPE 把检测的结果传给主机端的check_nrpe,check_nrpe 再把结果送到Nagios状态队列中。
5. Nagios 依次读取队列中的信息,再把结果显示出来。
nagios配置
创建用户
# useradd -s /sbin/nologin nagios
修改nagios密码
# sudo passwd nagios
密码设置为nagios
2.创建目录并设定权限
# mkdir /usr/local/nagios
# ls -al --查看目录权限
# chown -R nagios.nagios /usr/local/nagios
# ls -al --再次查看目录权限
# mkdir /home/nagios
# chown -R nagios.nagios /home/nagios
# su nagios
# echo "test" |mutt -s "my_first_test" aaa@126.com --测试mutt发送邮件
3.下载安装
tar -zxf nagios-4.0.4.tar.gz
进入根目录
cd nagios-4.0.4/
配置
enadmin@cgnmon:~/software/nagios-4.0.4$ ./configure --prefix=/usr/local/nagio
./configure --prefix 作用
不指定prefix,则可执行文件默认放在/usr/local/bin,库文件默认放在/usr/local/lib,配置文件默认放在/usr/local/etc。其它的资源文件放在/usr/local/share。你要卸载这个程序,要么在原来的make目录下用一次make uninstall(前提是make文件指定过uninstall),要么去上述目录里面把相关的文件一个个手工删掉。
指定prefix,直接删掉一个文件夹就够了。
编译安装
make all
make install && make install-init && make install-commandmode && make install-config
4. 安装Nagios 插件
# wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz
# tar zxvf nagios-plugins-1.4.16.tar.gz
# cd nagios-plugins-1.4.16
# ./configure --prefix=/usr/local/nagios
# make && make install
6.使用chkconfig管理服务
sudo ln -s /usr/lib/insserv/insserv /sbin/insserv
root@ubuntu-server:/sbin# ll /sbin/insserv
lrwxrwxrwx 1 root root 24 Mar 28 09:21 /sbin/insserv -> /usr/lib/insserv/insserv*
7.常见故障处理
7.1Nagios 启动时告警:
Starting nagios:No directory, logging in with HOME=/
done.
解决方法
修改/etc/passwd
将nagios:x:1001:1001::/home/nagios:/bin/sh
修改为:
nagios:x:1001:1001::/usr/local/nagios:/bin/sh
* Restarting web server apache2
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
...done.
修改 httpd.conf 文件
打开终端,输入以下命令:
sudo vim /etc/apache2/httpd.conf
默认情况下,这个是一个空文件,在文件中加入以下内容:
ServerName localhost
保存文件退出,再次重启apache,错误提示没有了。
ubuntu下nagios配置的更多相关文章
- Opencv 2.4.9在Ubuntu下的配置与安装
[原]Opencv 2.4.9在Ubuntu下的配置安装 Opencv 2.4.9在Ubuntu下的配置与安装 surgewong@gmail.com http://blog.csdn.net/su ...
- Ubuntu下MySql配置
Ubuntu下MySql配置 安装MySQL 命令: sudo apt-get install mysql-server MySQL初始配置及管理 启动MySQL mysql start : mysq ...
- Ubuntu下Maven配置与Maven项目创建教程
一. Ubuntu下Maven配置 windows下Maven配置参考http://www.cnblogs.com/LexMoon/p/JavaMaven.html ubuntu下Maven地址htt ...
- Ubuntu下nagios安装(来源官网)
Ubuntu下nagios安装(来源官网) https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/toc.html h ...
- Ubuntu下HTTPS配置
Ubuntu下HTTPS配置非常简单,对大部分用户而言,使用普通的自签名证书,只需按照步骤进行就可以了,无需了解密钥.证书的更多知识,更深的背景知识还有RSA算法.DES算法.X509规范.CA机构. ...
- Ubuntu下Linux配置内核各种常见错误和解决办法
镜像下载.域名解析.时间同步请点击阿里云开源镜像站 这篇把Ubuntu下Linux配置内核各种常见错误和解决办法给大家讲解一下,希望可以帮助到大家. 一.Ubuntu系统中缺少各种依赖包导致的问题 1 ...
- ubuntu下安装配置OpenCV
Cmake的安装 我用的是ubuntu-software自动下载安装的. Ubuntu 下安装 OpenCV 首先下载安装相关包,然后下载OpenCV 系统:ubuntu16.04 OpenCV:2. ...
- CentOS和Ubuntu下安装配置Greenplum数据库集群(包括安装包和源码编译安装)
首先说一下,无论是CentOS/RedHat还是Ubuntu都可以按源码方式.安装包方式编译安装. 1. 规划 192.168.4.93(h93) 1个主master 2个主segm ...
- ubuntu下安装配置minicom(解决默认的端口/dev/tty8,改不过来的问题)
Minicom是linux下串口通信的软件,下面讲下ubuntu Minicom的安装和配置. 安装: sudo apt-get install minicom 或在新立得软件包管理器中搜索“mini ...
随机推荐
- C float与char数组 互转
//转换float数据到字节数组 unsigned char i; float floatVariable; unsigned ]; (unsigned char) *pdata = ((unsign ...
- VS2012未找到与约束ContractName...匹配的导出
用VS2012创建ARCGIS插件项目时,提示“未找到与约束ContractName...匹配的导出”,此前一直都是正常的额 经查,发现是近期系统相关更新导致,解决办法有两种途径: 一是删除近期更新的 ...
- Javascript倒计时组件new TimeSpan(hours, minutes, minutes)
function TimeSpan(h, m, s) { this.h = Number(h); this.m = Number(m); this.s = Number(s); } TimeSpan. ...
- 【问题与思考】1+"1"=?
概述 在数学中1+1=2,在程序中1+1=2,而1+"1"=? 围绕着1+"1"的问题,我们来思考下这个问题. 目录: 一.在.Net代码中 二.在JavaSc ...
- [linux]scp指令
实例1:从远处复制文件到本地目录 $scp root@10.6.159.147:/opt/soft/demo.tar /opt/soft/ 说明: 从10.6.159.147机器上的/opt/soft ...
- 分享一个ASP.NET 文件压缩解压类 C#
需要引用一个ICSharpCode.SharpZipLib.dll using System; using System.Collections.Generic; using System.Linq; ...
- 转载:第三弹!全球首个微信小程序(应用号)开发教程!通宵吐血赶稿,每日更新!
感谢朋友们的支持!这两天博卡君收到了很多支持和安慰,也认识了很多志同道合的朋友.目前微信公布的工具和代码都不是正式版,随时有可能调整,大家先体验和学习为主吧.最近这个教程搞得我也心力交瘁了,虽然苦逼, ...
- Mysql数据库安全管理配置
1.删除test库 原因: The default MySQL installation comes with a database named test that anyone can access ...
- SpringMVC核心——参数获取与Servlet资源获取问题
一.SpringMVC 使用 @PathVariable.@RequestParam.@RequestHeader.@CookieValue 等来解决参数获取问题. 1. @PathVariable: ...
- Gradle学习系列之二——创建Task的多种方法
在本系列的上篇文章中,我们讲到了Gradle入门,在本篇文章中我们将讲到创建Task的多种方法. 请通过以下方式下载本系列文章的Github示例代码: git clone https://github ...