useradd nagios
usermod –G nagios apache //把apache 用户加入nagios 组
mkdir /usr/local/nagios
chown -R nagios:nagios /usr/local/nagios
下载nagios安装包解压
./configure --prefix=/usr/local/nagios
make all
make install //安装nagios 主程序、CGI 和HTML 文件
make install-init //安装nagios 的启动脚本
make install-commandmode //安装外部命令使用的目录,并配置目录权限
make install-config //安装样板配置文件,位于/usr/local/nagios/etc 目录下
make install-webconf(如果apache 是yum安装的话可以直接安装,如果是手动编译安装apache的话在nagios的解压文件夹ssample-config文件夹下找到httpd.conf中将里面的内容直接复制到apache的配置文件里面) //安装apache 配置文件,以便能够通过web 页面访问nagios
touch /usr/local/nagios/etc/htpasswd.users
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin//建立登陆账号
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg //验证Nagios的配置文件
安装nagios-plugin插件
下载安装包解压
./configure --prefix=/usr/local/nagios
make && make install
查看/usr/local/nagios/libexec目录会显示安装的所有的插件
监控机、被监控机(Linux/Unix机)上安装nrpe(如果只需要监控服务可以不装这个)
下载安装软件包nrpe
./configure --prefix=/usr/local/nagios
make all
make install-plugin (在被监控机安装时先useradd nagios否则会出错)
make install-daemon
make install-daemon-config
make install-xinetd (把nrpe服务集成到xinetd服务里面)
vim /etc/xinetd.d/nrpe
only_from = 127.0.0.1 192.168.9.14(监控机的ip地址)
vi /etc/services 增加如下一行
nrpe 5666/tcp # NRPE
service xinetd restart
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg (或者是service nagios start)启动nagios后台进程这样才能显示
至此nagios监控机的配置已经完全结束
开启apache之后访问nagios之后就能看到本机的一些信息跟服务
监控其他机器的一些信息跟服务
监控机的配置:
在监控机器的command 命令里面定义nrpe命令
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
被监控机器上的配置:
下载安装软件包nrpe
./configure --prefix=/usr/local/nagios
make all
make install-plugin (在被监控机安装时先useradd nagios否则会出错)
make install-daemon
make install-daemon-config
make install-xinetd (把nrpe服务集成到xinetd服务里面)
vim /etc/xinetd.d/nrpe
only_from = 127.0.0.1 192.168.9.14(监控机的ip地址)
vi /etc/services 增加如下一行
nrpe 5666/tcp # NRPE
vi /usr/local/nagios/etc/nrpe.cfg
allowed_hosts 增加主控IP
service xinetd restart
在被监控机上确认服务是否启动
netstat -at|grep nrpe
tcp 0 0 *:nrpe *:* LISTEN
在监控机上测试被监控机的NRPE 工作是否正常
/usr/local/nagios/libexec/check_nrpe -H 被监控机IP
NRPE v2.12 //显示NRPE 版本信息,说明NRPE 工作正常
在监控机上拷贝localhost.cfg 文件修改为被监控主机配置文件后缀.cfg文件之后修改监控服务在监控命令前面加上check_nrpe!(以下为被监控机器的配置文件)这样才能监控远程机器
###############################################################################
# LOCALHOST.CFG - SAMPLE OBJECT CONFIG FILE FOR MONITORING THIS MACHINE
#
# Last Modified: 05-31-2007
#
# NOTE: This config file is intended to serve as an *extremely* simple
# example of how you can create configuration entries to monitor
# the local (Linux) machine.
#
###############################################################################
###############################################################################
###############################################################################
#
# HOST DEFINITION
#
###############################################################################
###############################################################################
# Define a host for the local machine
define host{
use linux-server ; Name of host template to use
; This host definition will inherit all variables that are defined
; in (or inherited by) the linux-server host template definition.
host_name 192.168.9.16
alias 192.168.9.16
address 192.168.9.16
}
###############################################################################
###############################################################################
#
# HOST GROUP DEFINITION
#
###############################################################################
###############################################################################
# Define an optional hostgroup for Linux machines
define hostgroup{
hostgroup_name linux ; The name of the hostgroup
alias Linux ; Long name of the group
members 192.168.9.16 ; Comma separated list of hosts that belong to this group
}
###############################################################################
###############################################################################
#
# SERVICE DEFINITIONS
#
###############################################################################
###############################################################################
# Define a service to "ping" the local machine
define service{
use local-service ; Name of service template to use
host_name 192.168.9.16
service_description PING
check_command check_nrpe!check_ping!100.0,20%!500.0,60%
}
# Define a service to check the disk space of the root partition
# on the local machine. Warning if < 20% free, critical if
# < 10% free space on partition.
define service{
use local-service ; Name of service template to use
host_name 192.168.9.16
service_description Root Partition
check_command check_nrpe!check_disk!20%!10%!/
}
# Define a service to check the number of currently logged in
# users on the local machine. Warning if > 20 users, critical
# if > 50 users.
define service{
use local-service ; Name of service template to use
host_name 192.168.9.16
service_description Current Users
check_command check_nrpe!check_users!20!50
}
# Define a service to check the number of currently running procs
# on the local machine. Warning if > 250 processes, critical if
# > 400 users.
define service{
use local-service ; Name of service template to use
host_name 192.168.9.16
service_description Total Processes
check_command check_nrpe!check_procs!250!400!RSZDT
}
# Define a service to check the load on the local machine.
define service{
use local-service ; Name of service template to use
host_name 192.168.9.16
service_description Current Load
check_command check_nrpe!check_load!5.0,4.0,3.0!10.0,6.0,4.0
}
# Define a service to check the swap usage the local machine.
# Critical if less than 10% of swap is free, warning if less than 20% is free
define service{
use local-service ; Name of service template to use
host_name 192.168.9.16
service_description Swap Usage
check_command check_nrpe!check_swap!20!10
}
# Define a service to check SSH on the local machine.
# Disable notifications for this service by default, as not all users may have SSH enabled.
define service{
use local-service ; Name of service template to use
host_name 192.168.9.16
service_description SSH
check_command check_ssh
notifications_enabled 0
}
# Define a service to check HTTP on the local machine.
# Disable notifications for this service by default, as not all users may have HTTP enabled.
define service{
use local-service ; Name of service template to use
host_name 192.168.9.16
service_description HTTP
check_command check_http
notifications_enabled 0
}
被监控机器上安装完成之后修改监控机nrpe.cfg在里面添加命令(此命令为监控机器上执行的命令调用libexec库里面的插件)
添加或者修改以下命令
command[check_ping]=/usr/local/nagios/libexec/check_ping -H 127.0.0.1 -w 100.0,20% -c 500.0,60%
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%
command[check_disk]=/usr/local/nagios//libexec/check_disk -w 20% -c 10% -p /dev/sda2
command[check_procs]=/usr/local/nagios//libexec/check_procs -w 150 -c 200
至此nagios监控主机以及被监控主机的配置就已经完成了!