nagios搭建配置
一、需要的软件包
1、nagios-3.2.3.tar.gz nagios主监控包
tar -zxvf nagios-3.2.3.tar.gz
cd nagios-3.2.3
./configure --prefix=/usr/local/nagios
make all
make install
命令对主程序,cgi及html进行安装
make install-init
命令在/etc/rc.d/init.d/目录中安装启动脚本
make install-commandmode
命令来安装和配置外部命令对Nagios主路径操作的权限。(这里所谓的外部命令主要是指Apache服务通过CGI来对
Nagios的进行的操作。用户将通过Web以执行CGI程序脚本的方式来对Nagios的检测结果进行读取和调用。)
make install-config
命令在/usr/local/nagios/etc/下安装nagios配置文件示例模版
chkconfig --add nagios on 开机启动nagios
chkconfig --level 35 nagios on
useradd nagios
创建nagios用户
chown -R nagios.nagios /usr/local/nagios
权限设置
nagios-plugins-1.4.15.tar.gz 监控插件
2、tar -zxvf nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15
./configure --prefix=/usr/local/nagios
make && make install
nagios-cn-3.2.3.tar.bz2 汉化包
tar -jxvf nagios-cn-3.2.3.tar.bz2
cd nagios-cn-3.2.3
./configure
make && make install
3、httpd-2.2.14.tar.gz 安装apache
tar -zxvf httpd-2.2.14.tar.gz
cd httpd-2.2.14
./configure --prefix=/usr/local/apache
make
make install
4、php-5.4.0.tar.gz 安装php
tar -zxvf php-5.4.0.tar.gz
cd php-5.4.0
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/aache/bin/apxs(apache可以调用php)
make
make install
二、修改apache配置文件
1、修改:
User nagios
Group nagios
修改为:
DirectoryIndex index.html index.php
增加:
AddType application/x-httpd-php .php
设置apache授权访问在配置文件最后添加:
#setting for nagios
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
AuthType Basic
Options ExecCGI
AllowOverride AuthConfig
Order allow,deny
Allow from all
AuthName "Welcome to user nagios"
AuthUserFile /usr/local/apache/conf/htpasswd
Require valid-user
Alias /nagios "/usr/local/nagios/share"
AuthType Basic
Options ExecCGI
AllowOverride AuthConfig
Order allow,deny
Allow from all
AuthName "Welcome to user nagios"
AuthUserFile /usr/local/apache/conf/htpasswd
Require valid-user
localhost.cfg 具体应用实例配置分析
define host{
use linux-server 引用linux-server类
host_name localhost 被监控主机名,报警时会提示,根据业务定
alias localhost 描述主机应用
address 127.0.0.1 主机ip
}
define hostgroup{
hostgroup_name linux-servers
alias Linux Servers
members localhost
}
四、nrpe包的安装
1、nagios监控主程序可以理解为一个监控平台,Nagios监测服务只能是本地系统监测以及对远程主机的连通性监测。为了使Nagios
的监测服务器能够远程对被监测主机系统上的信息进行获取,比如远程系统上的进程数、磁盘空间使用状况、所运行的服务等等
这些必须要登录远程主机系统上才能了解的信息的话,就必须要依靠NRPE这个核心扩展插件程序,NRPE作为中间的代理程序,扮
演着一手接受着Nagios监测服务器发来的请求,另一手在远程主机系统上获取指定的信息的中间人角色。
如以上提到的实现Nagios对远程系统的监测,那么首先必须要在被监测的远程主机上除了安装Nagios-plugins插件程序之外还
必须安装 NRPE核心扩展插件程序,并将NRPE在被监测的远程主机系统上以守护进程的方式运行起来,开放指定的NRPE监听端口
监听着Nagios监测服务器发送过来的所有监测请求。另外,在Nagios监测服务器上,在必须要安装Nagios-plugins插件程序和
NRPE核心扩展插件程序。唯一不同的是,Nagios监测服务器不需要将NRPE作为守护进程运行着,因为它本身一般不需要被别人
监测着而是去监测别人,对Nagios监测服务器而言,它只需要使用到Nagio-plugins插件程序和NRPE扩展插件程序就足够了。
在被监控主机上安装Nagios-plugins插件程序
首先要添加用户useradd nagios 这是必须的
tar -zxvf nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15
./configure --prefix=/usr/local/nagios
make && make install
chown -R nagios.nagios /usr/local/nagios
安装nrpe包
tar -zxvf nrpe-2.13.tar.gz
cd nrpe-2.13
./configure
make all
make install-plugin 安装nrpe插件程序
make isntall-daemon 安装nrpe守护程序
make install-daemon-config 安装nrpe守护进程配置文件
五、在监控主机上安装nrpe程序
tar -zxvf nrpe-2.13.tar.gz
cd nrpe-2.13
./configure
make all
安装NRPE扩展插件程序
make install-plugin
Nagios只要拥有NRPE的扩展插件功能就可以了,所以在Nagios监测服务器安装NRPE工作到这步就可以了。接下来要
做的就是在Nagios监测服务器上配置NRPE的扩展插件命令,使得Nagios监测服务器能够定义nrpe命令,从而可以定
义出“远程系统监测服务”。
在监控主机上配置NRPE的服务
1.查看新扩展插件check_nrpe的使用方法
/usr/local/nagios/libexec/check_nrpe -h|less
-------------------------------------------------------
Usage: check_nrpe -H [-n] [-u] [-p ] [-t ] [-c ]
使用方式:check_nrpe -H 主机名 -p NRPE端口 -c NRPE命令名
Options:
选项:
= The address of the host running the NRPE daemon
主机,运行着NRPE守护进程的远程被监测主机名,并且该主机名必须在host里定义过。
[port] = The port on which the daemon is running (default=5666)
端口,被监测的远程主机上运行NRPE的端口,默认是5666,如果是默认就不用指定。
[command] = The name of the command that the remote daemon should run
命令,这些命令名必须是被监测主机上NRPE守护进程运行着的。
-------------------------------------------------------
2.在command.cfg命令定义文件中添加NRPE命令。
vi /usr/local/nagios/etc/commands.cfg
-------------------------------------------------------
# NRPE Command
添加NRPE功能命令。
3.添加NRPE监控服务
-------------------------------------------------------
#Define Remote Current Users
定义监测远程系统当前登录用户数量服务。
define service{
use remote-service
host_name KCentOS5A
service_description Current Users On Remote System
check_command nrpe!check_users
}
#Define Remote System Loads
定义监测远程系统当前负载服务。
define service{
use remote-service
host_name KCentOS5A
service_description Current System Loads
check_command nrpe!check_load
}
#Define Remote Zombie Processes
定义监测远程系统僵尸进程数服务。
define service{
use remote-service
host_name KCentOS5A
service_description Zombie Processes On Remote System
check_command nrpe!check_zombie_procs
}
#Define Remote System Total Processes
定义监测远程系统进程总数服务。
define service{
use remote-service
host_name KCentOS5A
service_description Total Processes On Remote System
check_command nrpe!check_total_procs
}
-------------------------------------------------------
再强调一遍:
(1)这里check_command后面的nrpe是commands.cfg里定义的命令名。
(2)而nrpe命令名后用感叹号“!”分隔的是NRPE命令名,这些NRPE命令是在远端被监测主机上nrpe.cfg中command后方括号“[]”
中定义的命令名,并且被远程NRPE守护进程运行着。
6.在Nagios监控服务器上然后按照NRPE命令定义来添加NRPE远程监控服务:
vi /usr/local/nagios/etc/localhost.cfg
-------------------------------------------------------
#Define Remote System Disk Using
定义监测远程系统磁盘使用状况。
define service{
use remote-service
host_name KCentOS5A
service_description Disk Using Of Remote System
check_command nrpe!disk_observer
}
#Define Remote System Swap Using
定义监测远程系统交换分区使用状况。
define service{
use remote-service
host_name KCentOS5A
service_description Swap Using Of Remote System
check_command nrpe!swap_observer
}
-------------------------------------------------------
7、重新启动Nagios监测服务器的监测程序:
service nagios restart
Running configuration check...done
Stopping nagios: .done.
Starting nagios: done.