Nagios简介
Nagios原名为Netsaint,由Ethan Galstad开发并维护至今。NAGIOS是一个缩写形式: "Nagios Ain't Gonna Insist On Sainthood" ,Sainthood 翻译为圣徒,而"Agios"是"saint"的希腊表示方法。Nagios被开发在Linux下使用,但在Unix下也工作得非常好。
主要功能
主机资源监控(CPU load、disk usage、system logs),也包括Windows主机(使用NSClient++ plugin)
可以指定自己编写的Plugin通过网络收集数据来监控任何情况(温度、警告……)
可以通过配置Nagios远程执行插件远程执行脚本
远程监控支持SSH或SSL加通道方式进行监控
简单的plugin设计允许用户很容易的开发自己需要的检查服务,支持很多开发语言(shell scripts、C++、Perl、ruby、Python、PHP、C#等)
包含很多图形化数据Plugins(Nagiosgraph、Nagiosgrapher、PNP4Nagios等)
可并行服务检查
能够定义网络主机的层次,允许逐级检查,就是从父主机开始向下检查
当服务或主机出现问题时发出通告,可通过email, pager, sms 或任意用户自定义的plugin进行通知
能够自定义事件处理机制重新激活出问题的服务或主机
自动日志循环
支持冗余监控
包括Web界面可以查看当前网络状态,通知,问题历史,日志文件等
工作原理
启动Nagios后,它会周期性的自动调用插件去检测服务器状态,同时Nagios会维持一个队列,所有插件返回来的状态信息都进入队列,Nagios每次都从队首开始读取信息,并进行处理后,把状态结果通过web显示出来。
Nagios提供了许多插件,利用这些插件可以方便的监控很多服务状态。安装完成后,在nagios主目录下的/libexec里放有nagios自带的可以使用的所有插件,如,check_disk是检查磁盘空间的插件,check_load是检查CPU负载的,等等。每一个插件可以通过运行./check_xxx –h 来查看其使用方法和功能。
Nagios可以识别4种状态返回信息,即 0(OK)表示状态正常/绿色、1(WARNING)表示出现警告/黄色、2(CRITICAL)表示出现非常严重的错误/红色、3(UNKNOWN)表示未知错误/深黄色。Nagios根据插件返回来的值,来判断监控对象的状态,并通过web显示出来,以供管理员及时发现故障。
再说报警功能,如果监控系统发现问题不能报警那就没有意义了,所以报警也是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服务端(192.168.0.182)安装
首先查看系统是否安装这些基础套件:
[root@nagios ~]# rpm -q gcc glibc glibc-common gd gd-devel xinetd openssl-devel
package gcc is not installed
glibc-2.12-1.107.el6.x86_64
glibc-common-2.12-1.107.el6.x86_64
package gd is not installed
package gd-devel is not installed
package xinetd is not installed
package openssl-devel is not installed
可以看出有很多还是没有安装的,安装:
[root@nagios ~]# yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel
创建Nagios用户和用户组
[root@nagios ~]# mkdir /usr/local/nagios
[root@nagios ~]# chown -R nagios.nagios /usr/local/nagios/
查看Nagios目录的权限
drwxr-xr-x. 2 nagios nagios 4096 11月 28 19:13 /usr/local/nagios/
编译安装Nagios
[root@nagios src]# tar xzvf nagios-3.4.3.tar.gz
[root@nagios nagios]# ./configure --prefix=/usr/local/nagios
*** Configuration summary for nagios 3.4.3 11-30-2012 ***:
General Options:
-------------------------
Nagios executable: nagios
Nagios user/group: nagios,nagios
Command user/group: nagios,nagios
Embedded Perl: no
Event Broker: yes
Install ${prefix}: /usr/local/nagios
Lock file: ${prefix}/var/nagios.lock
Check result directory: ${prefix}/var/spool/checkresults
Init directory: /etc/rc.d/init.d
Apache conf.d directory: /etc/httpd/conf.d
Mail program: /bin/mail
Host OS: linux-gnu
Web Interface Options:
------------------------
HTML URL: http://localhost/nagios/
CGI URL: http://localhost/nagios/cgi-bin/
Traceroute (used by WAP):
Review the options above for accuracy. If they look okay,
type 'make all' to compile the main program and CGIs.
编译完成以后,依据提示,运行make all:
*** Compile finished ***
If the main program and CGIs compiled without any errors, you
can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):
make install
- This installs the main program, CGIs, and HTML files
make install-init
- This installs the init script in /etc/rc.d/init.d
make install-commandmode
- This installs and configures permissions on the
directory for holding the external command file
make install-config
- This installs *SAMPLE* config files in /usr/local/nagios/etc
You'll have to modify these sample files before you can
use Nagios. Read the HTML documentation for more info
on doing this. Pay particular attention to the docs on
object configuration files, as they determine what/how
things get monitored!
make install-webconf
- This installs the Apache config file for the Nagios
web interface
make install-exfoliation
- This installs the Exfoliation theme for the Nagios
web interface
make install-classicui
- This installs the classic theme for the Nagios
web interface
按照提示一步一步安装,并添加Nagios服务:
[root@nagios nagios]# make install-init
[root@nagios nagios]# make install-commandmode
[root@nagios nagios]# make install-config
[root@nagios nagios]# chkconfig --add nagios
[root@nagios nagios]# chkconfig --level 35 nagios on
[root@nagios nagios]# chkconfig --list nagios
nagios 0:关闭1:关闭2:关闭3:启用4:启用5:启用6:关闭
验证程序是否被正确安装
[root@nagios ~]# cd /usr/local/nagios/
[root@nagios nagios]# ls
bin etc libexec sbin share var
Nagios各个目录用途说明如下:
bin Nagios可执行程序所在目录
etc Nagios配置文件所在目录
sbin Nagios CGI文件所在目录,也就是执行外部命令所需文件所在的目录
share Nagios网页文件所在的目录
libexec Nagios外部插件所在目录
var Nagios日志文件、lock 等文件所在的目录
var/archives Nagios日志自动归档目录
var/rw 用来存放外部命令文件的目录
安装Nagios插件
[root@nagios src]# wget https://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz [root@nagios src]# tar xzvf nagios-plugins-1.5.tar.gz [root@nagios src]# cd nagios-plugins-1.5 [root@nagios nagios-plugins-1.5]# ./configure --prefix=/usr/local/nagios/ [root@nagios nagios-plugins-1.5]# make && make install
安装Apache和Php
Apache和Php不是安装nagios所必须的,但是nagios提供了web监控界面,通过web监控界面可以清晰的看到被监控主机、资源的运行状态,因此,安装一个web服务是很必要的。需要注意的是,nagios在nagios3.1.x版本以后,配置web监控界面时需要php的支持。这里我们下载的nagios版本为nagios-3.4.3,因此在编译安装完成apache后,还需要编译php模块,这里选取的php版本为php5.5.6。
安装Apache
[root@nagios src]# tar xzvf httpd-2.2.26.tar.gz
[root@nagios src]# cd httpd-2.2.26
[root@nagios httpd-2.2.26]# ./configure --prefix=/usr/local/apache2
[root@nagios httpd-2.2.26]# make && make install
安装Php
[root@nagios src]# tar xzvf php-5.5.6.tar.gz
[root@nagios src]# cd php-5.5.6
[root@nagios php-5.5.6]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs
编译时出现报错:
checking libxml2 install dir... no
checking for xml2-config path...
configure: error: xml2-config not found. Please check your libxml2 installation.
安装Libxml2和libxml-devel后再编译就可以了:
[root@nagios apache2]# yum install libxml2 libxml2-devel -y
编译成功以后,再安装:
[root@nagios php-5.5.6]# make && make install
配置Apache
[root@nagios php-5.5.6]# vim /usr/local/apache2/conf/httpd.conf
修改如下:
User nagios
Group nagios
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
增加的内容:
AddType application/x-httpd-php .php
安全
#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目录验证文件,在上面的配置中,指定了目录验证文件htpasswd,下面要创建这个文件:
[root@nagios bin]# /usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd eminum
检测Apache配置文件,并启动Apache:
httpd: apr_sockaddr_info_get() failed for nagios.localdomain
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
Syntax OK
[root@nagios php-5.5.6]# /usr/local/apache2/bin/apachectl start
httpd: apr_sockaddr_info_get() failed for nagios.localdomain
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
打开浏览器输入192.168.0.182/nagios,出现报错,于是猜测可能是Selinux和Iptables的问题,关闭:
[root@nagios bin]# setenforce 0
[root@nagios bin]# getenforce
Permissive
[root@nagios bin]# service iptables stop
iptables: Flushing firewall rules: [ OK ]
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Unloading modules: [ OK ]
再打开浏览器,就可以访问Nagios了:
配置Nagios
Nagios 主要用于监控一台或者多台本地主机及远程的各种信息,包括本机资源及对外的服务等。默认的Nagios 配置没有任何监控内容,仅是一些模板文件。若要让Nagios 提供服务,就必须修改配置文件,增加要监控的主机和服务,下面将详细介绍。
默认配置文件介绍
Nagios安装完毕后,默认的配置文件在/usr/local/nagios/etc目录下:
[root@nagios bin]# cd /usr/local/nagios/etc/
[root@nagios etc]# ls
cgi.cfg htpasswd nagios.cfg objects resource.cfg
[root@nagios etc]# cd objects/
[root@nagios objects]# ls
commands.cfg localhost.cfg switch.cfg timeperiods.cfg
contacts.cfg printer.cfg templates.cfg windows.cfg
[root@nagios objects]#
每个文件或目录含义如下表所示:
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的配置过程中涉及到的几个定义有:主机、主机组,服务、服务组,联系人、联系人组,监控时间,监控命令等,从这些定义可以看出,nagios各个配置文件之间是互为关联,彼此引用的。
成功配置出一台nagios监控系统,必须要弄清楚每个配置文件之间依赖与被依赖的关系,最重要的有四点:
第一:定义监控哪些主机、主机组、服务和服务组;
第二:定义这个监控要用什么命令实现;
第三:定义监控的时间段;
第四:定义主机或服务出现问题时要通知的联系人和联系人组。
配置Nagios
创建hosts.cfg文件来定义主机和主机组
创建services.cfg文件来定义服务
用默认的contacts.cfg文件来定义联系人和联系人组
用默认的commands.cfg文件来定义命令
用默认的timeperiods.cfg来定义监控时间段
用默认的templates.cfg文件作为资源引用文件
templates.cfg文件
nagios主要用于监控主机资源以及服务,在nagios配置中称为对象,为了不必重复定义一些监控对象,Nagios引入了一个模板配置文件,将一些共性的属性定义成模板,以便于多次引用。这就是templates.cfg的作用。
resource.cfg文件
resource.cfg是nagios的变量定义文件,文件内容只有一行:
# Sets $USER1$ to be the path to the plugins
$USER1$=/usr/local/nagios/libexec
其中,变量$USER1$指定了安装nagios插件的路径,如果把插件安装在了其它路径,只需在这里进行修改即可。需要注意的是,变量必须先定义,然后才能在其它配置文件中进行引用
commands.cfg 文件
此文件默认是存在的,无需修改即可使用,当然如果有新的命令需要加入时,在此文件进行添加即可。
hosts.cfg 文件
此文件默认不存在,需要手动创建,hosts.cfg主要用来指定被监控的主机地址以及相关属性信息,要根据项目要求配置。
相关推荐
centos6.3下如何安装和配置nagios。
CentOS配置Nagios监控平台,监控Linux客户端,Windows客户端详细配置,以及如何设置微信报警
CENTOS 5_NAGIOS的安装与配置
nagios监控,邮件告警、图文教程、内容详细易懂。 包含nagios的安装部署、nconf的安装部署、nconf与nagios联动实现nagios的监控项图像化配置,邮件告警配置等。
centos6.4系统环境下的nagios监控配置
这里对cacti和nagios做了整合,整合原理其实很简单,就是在cacti中安装nagios for cacti插件,nagios的数据通过ndo2db保存到mysql中,cacti读取mysql数据进行展示。 该文档包含的内容: 1.nagios的基本安装 2.msn...
服务器监控软件nagios安装及配置,centos6.5安装环境。已部署在本单位主控机房。
目录1. nagios简介2. 服务器准备2.1 主机信息+IP地址2.2 查看主机的系统版本信息2.3 暂时关掉... nagios服务端程序安装部署5.1 安装部署nagios服务端主程序5.1.1 解压安装包5.1.2 配置编译5.1.3 编译安装5.1.4 设置nag
目录1. 写在前面2. nagois服务端各配置文件之间的关系3. 编辑/usr/local/nagios/etc/objects/hosts.cfg4.... 配置/usr/local/nagios/etc/nagios.cfg8. 验证配置文件的正确性9. 重启nagios-server 1. 写在前面 nag
nagios升级版icinga,本人试用过效果还不错
centos 下配置nagios,按照这个配过,是可行的,就是变化少了些。大家有好的,记得要分享出来啊
CentOS+Cacti安装配置 (很完整且简单..可以试试效果
基于CentOs的ganglia监控配置,配合Nagios进行分布式监控预警
所有 CentOS 软件包仍然可用,这样您就可以在为您安装和配置 Nagios 工具的同时保留 CentOS 的所有优势。 FAN 提供的工具:Linux、MySQL、Nagios、Nagios Plugins、NagVis、Centreon、Net-SNMP 和 NDOUtils...
环境:Oracle 10g CentOS 4.6 i386 由于 nagios 脚本需要读取 oracle 相关文件。所以运行 nagios 的用户需要定义为 oracle 服务用户。并且修改 /etc/xinted.d/nrpe 中的配置
所有CentOS软件包仍然可用,因此您可以在已为您安装和配置Nagios工具的同时保留CentOS的所有优点。 FAN提供的工具:Linux,MySQL,Nagios,Nagios插件,NagVis,Centreon,Net-SNMP和NDOUtils ...
在CentOS7或RHEL7上自动部署Nagios Server 在CentOS6 / 7/8,RHEL6、7、8,Fedora和FreeBSD上自动部署Nagios客户端从Ansible清单生成服务检查和受监视的主机为Nagios服务器本身生成全面检查通过NRPE为所有主机/服务...
网络监控软件cacti,nagios整合配置,可同时监控路由器、交换机、服务器等网络设备的状态,centos6.5环境安装。已部署在本单位主控机房。
主要介绍了MySQL性能监控软件Nagios的安装及配置教程,这里以CentOS操作系统为环境进行演示,需要的朋友可以参考下
编写的脚本用来监控... 在从服务器安装 nrpe,然后在配置文件nrpe.cfg加入一行 command[check_mysql_slave]=/usr/local/nagios/libexec/check_mysql_slave 添加这个文件内容 #!/bin/sh declare -a slave_is