Nagios-Linux主机监控

2021年09月15日 阅读数:3
这篇文章主要向大家介绍Nagios-Linux主机监控,主要内容包括基础应用、实用技巧、原理机制等方面,希望对大家有所帮助。

本文转自:http://www.yylog.org/?p=4282linux

Nagios客户端配置
安装nagios-plugins
[root@nginx_server ~]# groupadd nagios
[root@nginx_server ~]# useradd -g nagios nagios -s /sbin/nologin
[root@nginx_server ~]# tar -zxvf nagios-plugins-1.4.14.tar.gz
[root@nginx_server ~]# cd nagios-plugins-1.4.14
[root@nginx_server nagios-plugins-1.4.14]# ./configure –prefix=/usr/local/nagios
[root@nginx_server nagios-plugins-1.4.14]# make && make installios

安装nrpe
[root@nginx_server ~]# tar -zxvf nrpe-2.12.tar.gz
[root@nginx_server ~]# cd nrpe-2.12
[root@nginx_server nrpe-2.12]# ./configure
[root@nginx_server nrpe-2.12]# make all
[root@nginx_server nrpe-2.12]# make install-plugin
[root@nginx_server nrpe-2.12]# make install-daemon
[root@nginx_server nrpe-2.12]# make install-daemon-config
[root@nginx_server nrpe-2.12]# make install-xinetd
[root@nginx_server nrpe-2.12]# chown -R nagios.nagios /usr/local/nagios
配置NRPE
修改/etc/xinetd.d/nrpe 将only_from = 127.0.0.1指定为only_from = 192.168.1.66(Nagios服务器地址)
[root@nginx_server nrpe-2.12]# vi /etc/xinetd.d/nrpe
# default: on
# description: NRPE (Nagios Remote Plugin Executor)
service nrpe
{
flags = REUSE
socket_type = stream
port = 5666
wait = no
user = nagios
group = nagios
server = /usr/local/nagios/bin/nrpe
server_args = -c /usr/local/nagios/etc/nrpe.cfg –inetd
log_on_failure += USERID
disable = no
only_from = 192.168.1.66
}
添加NRPE服务端口
[root@nginx_server nrpe-2.12]# vi /etc/services
nrpe 5666/tcp # nrpe
启动NRPE守护进程
[root@nginx_server nrpe-2.12]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
[root@nginx_server nrpe-2.12]# netstat -natp|grep 5666
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 21235/nrpe
检查NRPE状态,返回版本信息则NRPE正常。
[root@nginx_server nrpe-2.12]# /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
NRPE v2.12nginx

Nagios服务端配置
[root@localhost /]# cd /usr/local/nagios/etc/objects/
建立被监控主机配置文件
[root@localhost objects]# cp localhost.cfg 192.168.1.60.cfg
修改192.168.1.60.cfg配置文件
将192.168.1.60.cfg中localhost替换成192.168.1.60(被监控端主机IP),将hostgroup_name注释或将名称改成其余,不要和localhost.cfg重名。
将address 127.0.0.1,修改成address 192.168.1.60。
[root@localhost objects]# vi 192.168.1.60.cfg
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.1.60
alias 192.168.1.60
address 192.168.1.60
}服务器

define hostgroup{
# hostgroup_name linux-servers ; The name of the hostgroup
alias Linux Servers ; Long name of the group
members 192.168.1.60 ; Comma separated list of hosts that belong to this group
}
检查配置nagios配置文件
[root@localhost etc]# /usr/local/nagios/bin/nagios -v nagios.cfg
最后重启nagios服务
root@localhost etc]# service nagios restart
Running configuration check…done.
Stopping nagios: done.
Starting nagios:This account is currently not available.
done.
访问nagios监控页面,此时nagios已经成功获取到被监控端的主机状态,如图:
Nagios-Linux主机监控_nagiossocket

Nagios-Linux主机监控_nagios_02