安装环境:
nagios服务器: RH5.4 192.168.0.25
nagios被监控服务器 RH5.4 192.168.0.28
nagios被监控服务器 RH5.4 192.168.0.26
安装前准备:安装好apache、gd库、
nagios-3.2.0.tar.gz
nagios-plugins-1.4.14.tar.gz
nrpe-2.12.tar.gz
http://ncu.dl.sourceforge.net/project/nagios/nagios-3.x/nagis-3.2.1/nagios-3.2.1.tar.gz
http://ncu.dl.sourceforge.net/project/nagiosplug/nagiosplug/.4.14/nagios-plugins-1.4.14.tar.gz
http://ncu.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-212/nrpe-2.12.tar.gz
http://blog.csdn.net/tianlesoftware/archive/2010/03/25/5417814.aspx
一、nagios服务器安装
一)、创建帐号:
[root@dns ~]#yum -y install gcc glibc glibc-common gd gd-devel
[root@dns ~]#/usr/sbin/useradd -m nagios
[root@dns ~]#passwd nagios (n123456)
[root@dns ~]# id nagios
uid=506(nagios) gid=507(nagios) groups=507(nagios)
二)、创建组
创建一个名为nagcmd的用户组用于从Web接口执行外部命令
[root@dns ~]# groupadd nagcmd
将nagios用户和Apache用户都加入到该用户组中
[root@dns ~]# usermod -a -G nagcmd nagios
[root@dns ~]# usermod -a -G nagcmd daemon
[root@dns ~]# id nagios
uid=506(nagios) gid=507(nagios) groups=507(nagios),509(nagcmd)
[root@dns ~]# id daemon
uid=2(daemon) gid=2(daemon) groups=2(daemon),1(bin),4(adm),7(lp),509(nagcmd)
//daemon为运行apache的帐号,在apache配置文档中有说明;
三)、安装nagios
#tar -zxvf nagios-3.2.1.tar.gz
[root@dns nagios]# cd nagios-3.2.0
[root@dns nagios-3.2.0]# ./configure --prefix=/usr/local/nagios --with-command-group=nagcmd
[root@dns nagios-3.2.0]# make all
[root@dns nagios-3.2.0]# make install
# 使用make install来安装主程序,CGI和HTML文件
[root@dns nagios-3.2.0]# make install-init
#使用make install-init在/etc/rc.d/init.d安装启动脚本
[root@dns nagios-3.2.0]# make install-commandmode #来配置目录权限
[root@dns nagios-3.2.0]# make install-config #安装示例配置文件,安装的路径是/usr/local/nagios/etc
nagios目录功能的简要说明:
* bin Nagios执行程序所在目录,nagios文件即为主程序
* etc Nagios配置文件位置
* sbin Nagios Cgi文件所在目录,也就是执行外部命令所需文件所在的目录
* Share Nagios网页文件所在的目录
* var Nagios日志文件、spid 等文件所在的目录
* libexec nagios 插件安装时产生的文件
四)、配置apache ,然后重启;
ScriptAlias /nagios/cgi-bin “/usr/local/nagios/sbin”
<Directory “/usr/local/nagios/sbin”>
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName “Nagios Access”
AuthType Basic
AuthUserFile /usr/www/passwd/htpasswd.users
Require valid-user
</Directory>
Alias /nagios “/usr/local/nagios/share”
<Directory “/usr/local/nagios/share”>
# SSLRequireSSL
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName “Nagios Access”
AuthType Basic
AuthUserFile /usr/www/passwd/htpasswd.users
Require valid-user
</Directory>
==================================================================================
五)、修改配置文件
1)、#vi /usr/local/nagios/etc/cgi.cfg 这一步很重要,因为这里如果不设置的话,在你访问浏览器
时会出现
如下提示
“It appears as though you do not have permission to view information for any of the hosts you requested...If you believe this is an error, check the HTTP server authentication requirements for
accessing this CGIand check the authorization options in your CGI configuration file”
编辑cgi.cfg文件,把认证的用户添加:
[root@server ~]#vi /usr/local/nagios/etc/cgi.cfg
use_authentication=1 //打开验证
default_user_name=bibi
authorized_for_system_information=nagiosadmin,bibi
authorized_for_configuration_information=nagiosadmin,bibi
authorized_for_system_commands=nagiosadmin,bibi
authorized_for_all_services=nagiosadmin,bibi
authorized_for_all_hosts=nagiosadmin,bibi
authorized_for_all_service_commands=nagiosadmin,bibi
authorized_for_all_host_commands=nagiosadmin,bibi
或者把use_authentication=1(表示打开认证) 设置成use_authentication=0 取消认证;
这里添加的用户"bibi"可以通过浏览器对nagios服务进行关闭.重启等操作.在这里为了安全也可以把nagiosadmin这一个用户删除.如果有多个用户,用逗号隔开.如: ngaiosadmin,bibi,...
2)、vi /usr/loca/nagios/etc/objects/contacts.cfg 把邮件地址修改为自己的邮件地址;
3)、修改commands.cfg 定义check_nrpe命令;
#vi /usr/loca/nagios/etc/objects/commands.cfg
###########################################################################
#2010.7.15 add by summer
#NRPE COMMAND
#
##########################################################################
#'check_nrpe' command definition
define command {
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
服务器端的主程序安装到此结束,打开浏览器输入:http://ip (or url)/nagios应该要能访问nagios主页面,同时,apache需要支持php扩展;
4)、把nagios 加入到服务列表中使之在系统启动时自动启动
#chkconfig --add nagios
#chkconfig nagios on
验证nagios的样例配置文件
[root@dns init.d]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Total Warnings: 0
Total Errors: 0
Things look okay - No serious problems were detected during the pre-flight check
如果没有报错,可以启动nagios服务
#service nagios start
=======================================================================
如果出现如下的提示修改nagios的shell
Starting nagios:This account is currently not available.
root@bzrWeb1 etc]# service nagios start
Starting nagios:This account is currently not available.
done.
修改/etc/passwd
将/sbin/nologin改成/bin/bash
=======================================================================
六)、安装nagios插件
# tar -zxvf nagios-plugins-1.4.14.tar.gz
#cd nagios-plugins-1.4.14
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
#make
#make install
#chown nagios.nagios /usr/local/nagios
#chown nagios.nagios /usr/local/nagios/libexec
七)、安装第nrpe插件
1)、编译nrpe
# tar -xvf nrpe-2.12.tar.gz
# cd nrpe-2.12
#./configure (如果这步报错:configure: error: Cannot find ssl headers ,则需安装openssl-devel)
#make all //安装NRPE插件,daemon和daemon样本配置文件;
# make install-plugin // 在Nagios服务器端只要安装nrpe监控插件就行
# make install-daemon
# make install-daemon-config //在xinetd下安装nrpe daemon服务
# make install-xinetd
2)、编辑/etc/xinetd.d/nrpe 文件,在only_from处添加监视器的ip地址
only_from = 127.0.0.1 <nagios_ip_address>
3)、编辑/etc/services 文件,添加nrpe daemon
nrpe 5666/tcp #NRPE
4)、重启xinetd服务
#service xinetd restart
5)、测试 nrpe运行
[root@dns conf]# netstat -at |grep nrpe
tcp 0 0 *:nrpe *:* LISTEN
[root@dns conf]# /usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v2.12
[root@dns init.d]# /usr/local/nagios/libexec/check_nrpe -h 查看check_nrpe的用法;
用法:
check_nrpe -H 被监控的主机 -c 要执行的监控命令
注意:-c 后面接的监控命令必须是nrpe.cfg文件中定义的,也就是nrpe daemon 只运行nrpe.cfg中所定义的命令;
6)、如果有防火墙 或者selinux 时 ,可以选择关闭selinux ,因为如果是在强制模式时,当联入nagios的CGI时导致一个“内部服务错误”的消息,在不关闭selinux时可以如下做法:
#chcon -R -t http_sys_content_t /usr/local/nagios/sbin
#chcon -R -t http_sys_content_t /usr/local/nagios/share
防火墙:
#iptables -I RH-firewall-1-INPUT -p tcp -m tcp -dport 5666 -j accept
二、被监控端安装
一)、添加帐号
[root@server28 ~]# useradd nagios -s /sbin/nologin
二)、安装nagios插件
[root@server28 tar]#tar -zxvf nagios-plugins-1.4.14.tar.gz
# cd nagios-plugins-1.4.14/
[root@server28 nagios-plugins-1.4.14]# ./configure --prefix=/usr/local/nagios
[root@server28 nagios-plugins-1.4.14]# make
[root@server28 nagios-plugins-1.4.14]# make install
三)、安装nrpe(监控机也要安装)
[root@server28 tar]# tar -zxvf nrpe-2.12.tar.gz
[root@server28 nrpe-2.12]# ./configure --prefix=/usr/local/nagios/
[root@server28 nrpe-2.12]# make all
[root@server28 nrpe-2.12]# make install-plugin //安装check_nrpe这个插件
[root@server28 nrpe-2.12]# make install-daemon //安装daemon
[root@server28 nrpe-2.12]# make install-daemon-config //安装配置文件
[root@server28 nrpe-2.12]# make install-xinetd
四)、编辑nrpe.cfg 文件允许Nagios监控服务器(192.168.0.25)监控;
allowed_hosts=127.0.0.1,192.168.0.25
启动nrpe
[root@localhost etc]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
[root@server28 nrpe-2.12]# netstat -at |grep nrpe
tcp 0 0 *:nrpe *:* LISTEN
[root@server28 nrpe-2.12]# /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
NRPE v2.12
五)、同上在192.168.0.26上面安装;
六)、在192.168.0.25上面
[root@dns objects]# /usr/local/nagios/libexec/check_nrpe -H 192.168.0.28 -c check_users
USERS OK - 1 users currently logged in |users=1;5;10;0
[root@dns objects]# /usr/local/nagios/libexec/check_nrpe -H 192.168.0.26
NRPE v2.12
到此服务端和客户端安装完成