4、添加一个gagcmd组
#groupadd gagcmd
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd apache
5、编译安装nagios软件
mkdir /home/huang/tools -p
cd /home/huang/tools/
wget https://sourceforge.net/projects/nagios/files/nagios-4.x/nagios-4.1.1/nagios-4.1.1.tar.gz
tar xzf nagios-4.1.1.tar.gz
cd nagios-4.1.1
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf
--》由于nagios的web界面需要授权认证:
-》htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin ---->设置密码为redhat
service httpd restart
6、编译安装插件nagios-plugins
cd /home/huang/tools/
wget http://www.nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz
tar xfz nagios-plugins-2.1.1.tar.gz
cd nagios-plugins-2.1.1
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg 检测一下是否有错误
service nagios start
chkconfig --add nagios
chkconfig nagios on
7、安装插件nrpe:
wget https://github.com/NagiosEnterprises/nrpe/archive/3.0.tar.gz
tar xf 3.0.tar.gz
cd nrpe-3.0/
./configure
make all
make install
make install-plugin
make install-daemon
make install-config
以下是一些编译参数选择:
###
[root@RS1 nrpe-3.0]# make
Please enter make [option] where [option] is one of:
all builds nrpe and check_nrpe
nrpe builds nrpe only
check_nrpe builds check_nrpe only
install-groups-users add the users and groups if they do not exist
install install nrpe and check_nrpe
install-plugin install the check_nrpe plugin
install-daemon install the nrpe daemon
install-config install the nrpe configuration file
install-inetd install the startup files for inetd, launchd, etc.
install-init install the startup files for init, systemd, etc.
开启nagios服务端:
service nagios start
浏览器访问:
http://192.168.1.155/nagios
#安装插件nagios-plugins
cd /home/huang/tools/
wget http://www.nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz
tar xfz nagios-plugins-2.1.1.tar.gz
cd nagios-plugins-2.1.1
./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local/nagios
make
make install
chown -R nagios.nagios /usr/local/nagios/
#安装NRPE
wget https://github.com/NagiosEnterprises/nrpe/archive/3.0.tar.gz
tar xf 3.0.tar.gz
cd nrpe-3.0/
./configure
make all
make install
make install-plugin
make install-daemon
make install-config
#配置hosts.cfg文件
将localhost.cfg重名了为hosts.cfg,将它修改为以下
[root@RS1 etc]# cat objects/hosts.cfg
###############################################################################
# LOCALHOST.CFG - SAMPLE OBJECT CONFIG FILE FOR MONITORING THIS MACHINE
#
#
# 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 a host for nagios server
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 nagios_server ----》这里的名称可以随便取
alias nagios_server
address 192.168.1.155 ----》这里我以nagios本机服务器端作为监控
}
# HOST GROUP DEFINITION
# Define an optional hostgroup for Linux machines
define hostgroup{
hostgroup_name linux-servers ; The name of the hostgroup
alias Linux Servers ; Long name of the group
members nagios_server ; Comma separated list of hosts that belong to this group -----》将要监控的hosts添加到hostgroup组中,放进members
}
#配置services.cfg文件
cd /usr/local/nagios/etc/objects
touch services.cfg
chown -R nagios.nagios services.cfg
编辑该文件添加需要监控的服务
define service{
use generic-service
host_name nagios_server -----》这里我以nagios服务端做监控样例,由于我nrpe插件没有启动所有不出监控的服务信息
service_description CPU Load
check_command check_nrpe!check_load
}
手动先使用命令收集下数据:
[root@RS1 etc]# /usr/local/nagios/libexec/check_nrpe -H 192.168.1.155 -c check_load
connect to address 192.168.1.155 port 5666: Connection refused
connect to host 192.168.1.155 port 5666: Connection refused
发现收集数据失败,发现并没有启动nrpe服务,于是
#nrpe 启动 监听的端口5666
修改配置文件:nrpe.cfg
allowed_hosts=127.0.0.1,192.168.1.155