如何在 Linux 上使用 Nagios 监控远程 Windows 机器

网友投稿 561 2022-05-28

在之前的文章中,我们讨论了Nagios 3.0 Jumpstart 指南和如何使用 Nagios 3.0 监控远程 linux 主机。在本文中,我将解释如何使用nagios 监控服务器来监控远程windows 机器和windows 服务器上运行的各种服务。本文涵盖以下三个部分。

一、概述

二.在远程 Windows 主机上安装 nagios 的 4 个步骤

在远程 windows 服务器上安装 NSClient++

修改 NSClient++ 服务

修改 NSC.ini

启动 NSClient++ 服务

三、nagios监控服务器的6个配置步骤

验证 check_nt 命令和 windows-server 模板

取消注释 /usr/local/nagios/etc/nagios.cfg 中的 windows.cfg

修改/usr/local/nagios/etc/objects/windows.cfg

定义应监控的 Windows 服务。

启用密码保护

验证配置并重新启动 Nagios。

一、概述

.

当 Nagios(安装在 nagios-server 上)监视远程 Windows 主机上的服务(例如磁盘空间使用情况)时,将在非常高的级别上执行以下三个步骤。

Nagios 将在 nagios-server 上执行 check_nt 命令并请求它监视远程 Windows 主机上的磁盘使用情况。

nagios-server 上的 check_nt 会联系远程 windows 主机上的 NSClient++ 服务,并请求它在远程主机上执行 USEDDISKSPACE。

USED DISKSPACE 命令的结果将由 NSClient++ 守护进程返回到 nagios-server 上的 check_nt。

以下流程总结了上面的解释:

Nagios Server (check_nt) —-> 远程主机(NSClient++) —-> USEDDISKSPACE

Nagios Server (check_nt) <-- 远程主机(NSClient++) <-- USEDDISKSPACE (返回磁盘空间使用情况)

二、在远程 Windows 主机上设置 nagios 的 4 个步骤

.

1.在远程windows服务器上安装NSClient++

从NSClient++ 项目下载 NSCP 0.3.1 (NSClient++-Win32-0.3.1.msi) 。NSClient++ 是一个开源 Windows 服务,它允许 Nagios 为 Windows 服务收集性能指标。完成以下五个 NSClient++ 安装步骤以完成安装。

(1) NSClient++ 欢迎屏幕

(2) 许可协议屏幕

(3) 选择安装选项和位置。使用默认选项并单击下一步。(4) 准备安装屏幕。单击“安装”以开始安装。(5) 安装完成画面。

2.修改NSClient++服务

转到控制面板 -> 管理工具 -> 服务。双击“NSClientpp (Nagios) 0.3.1.14 2008-03-12 w32”服务并选中“允许服务与桌面交互”复选框,如下所示。

3.修改NSC.ini

(1) 修改NSC.ini并取消*.dll的注释:编辑C:\Program Files\NSClient++\NSC.ini文件,取消[modules]下除RemoteConfiguration.dll和CheckWMI.dll以外的所有内容

[modules] ;# NSCLIENT++ MODULES ;# A list with DLLs to load at startup. ; You will need to enable some of these for NSClient++ to work. ; ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ; * * ; * N O T I C E ! ! ! - Y O U H A V E T O E D I T T H I S * ; * * ; ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! FileLogger.dll CheckSystem.dll CheckDisk.dll NSClientListener.dll NRPEListener.dll SysTray.dll CheckEventLog.dll CheckHelpers.dll ;CheckWMI.dll ; ; RemoteConfiguration IS AN EXTREM EARLY IDEA SO DONT USE FOR PRODUCTION ENVIROMNEMTS! ;RemoteConfiguration.dll ; NSCA Agent is a new beta module use with care! NSCAAgent.dll ; LUA script module used to write your own "check deamon" (sort of) early beta. LUAScript.dll ; Script to check external scripts and/or internal aliases, early beta. CheckExternalScripts.dll ; Check other hosts through NRPE extreme beta and probably a bit dangerous! :) NRPEClient.dll

(2) 修改NSC.ini,取消allowed_hosts的注释。编辑 C:\Program Files\NSClient++\NSC.ini 文件并在设置下取消对 allowed_host 的注释并添加 nagios-server 的 ip-address。

;# ALLOWED HOST ADDRESSES ; This is a comma-delimited list of IP address of hosts that are allowed to talk to the all daemons. ; If leave this blank anyone can access the deamon remotly (NSClient still requires a valid password). ; The syntax is host or ip/mask so 192.168.0.0/24 will allow anyone on that subnet access allowed_hosts=192.168.1.2/255.255.255.0

注意: allowed_host 位于 [Settings]、[NSClient] 和 [NRPE] 部分下。为此,请确保更改 [设置] 下的 allowed_host。

(3) 修改 NSC.ini 并取消注释端口。编辑 C:\Program Files\NSClient++\NSC.ini 文件并取消注释 [NSClient] 部分下的 port#

;# NSCLIENT PORT NUMBER ; This is the port the NSClientListener.dll will listen to. port=12489

(4) 修改NSC.ini 并指定密码。您还可以指定 nagios 服务器远程访问 NSClient++ 代理所需的密码。

[Settings] ;# OBFUSCATED PASSWORD ; This is the same as the password option but here you can store the password in an obfuscated manner. ; *NOTICE* obfuscation is *NOT* the same as encryption, someone with access to this file can still figure out the ; password. Its just a bit harder to do it at first glance. ;obfuscated_password=Jw0KAUUdXlAAUwASDAAB ; ;# PASSWORD ; This is the password (-s) that is required to access NSClient remotely. If you leave this blank everyone will be able to access the daemon remotly. password=My2Secure$Password

4.启动NSClient++服务

从控制面板启动 NSClient++ 服务 -> 管理工具 -> 服务 -> 选择“NSClientpp (Nagios) 0.3.1.14 2008-03-12 w32”并点击开始(或)点击“开始 -> 所有程序 - > NSClient++ -> 启动 NSClient++ (Win32) 。请注意,这会将 NSClient++ 作为 Windows 服务启动。

稍后如果您修改 NSC.ini 文件中的任何内容,您应该从 Windows 服务重新启动“NSClientpp (Nagios) 0.3.1.14 2008-03-12 w32”。

三、nagios监控服务器的6个配置步骤

.

1.验证check_nt命令和windows-server模板

验证在 /usr/local/nagios/etc/objects/commands.cfg 下是否启用了 check_nt

# 'check_nt' command definition define command{ command_name check_nt command_line $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -v $ARG1$ $ARG2$ }

验证是否在 /usr/local/nagios/etc/objects/templates.cfg 下启用了 windows-server 模板

# Windows host definition template - This is NOT a real host, just a template! define host{ name windows-server ; The name of this host template use generic-host ; Inherit default values from the generic-host template check_period 24x7 ; By default, Windows servers are monitored round the clock check_interval 5 ; Actively check the server every 5 minutes retry_interval 1 ; Schedule host check retries at 1 minute intervals max_check_attempts 10 ; Check each server 10 times (max) check_command check-host-alive ; Default command to check if servers are "alive" notification_period 24x7 ; Send notification out at any time - day or night notification_interval 30 ; Resend notifications every 30 minutes notification_options d,r ; Only send notifications for specific host states contact_groups admins ; Notifications get sent to the admins by default hostgroups windows-servers ; Host groups that Windows servers should be a member of register 0 ; DONT REGISTER THIS - ITS JUST A TEMPLATE }

2.取消/usr/local/nagios/etc/nagios.cfg中windows.cfg的注释

# Definitions for monitoring a Windows machine cfg_file=/usr/local/nagios/etc/objects/windows.cfg

3.修改/usr/local/nagios/etc/objects/windows.cfg

默认情况下,windows.cfg 下给出了 windows 服务器的示例主机定义,修改它以反映需要通过 nagios 监视的适当 windows 服务器。

# Define a host for the Windows machine we'll be monitoring # Change the host_name, alias, and address to fit your situation define host{ use windows-server ; Inherit default values from a template host_name remote-windows-host ; The name we're giving to this host alias Remote Windows Host ; A longer name associated with the host address 192.168.1.4 ; IP address of the remote windows host }

4.定义需要监控的windows服务。

以下是示例 windows.cfg 中已启用的默认 Windows 服务。确保更新这些服务上的 host_name 以反映在上述步骤中定义的 host_name。

define service{ use generic-service host_name remote-windows-host service_description NSClient++ Version check_command check_nt!CLIENTVERSION } define service{ use generic-service host_name remote-windows-host service_description Uptime check_command check_nt!UPTIME } define service{ use generic-service host_name remote-windows-host service_description CPU Load check_command check_nt!CPULOAD!-l 5,80,90 } define service{ use generic-service host_name remote-windows-host service_description Memory Usage check_command check_nt!MEMUSE!-w 80 -c 90 } define service{ use generic-service host_name remote-windows-host service_description C:\ Drive Space check_command check_nt!USEDDISKSPACE!-l c -w 80 -c 90 } define service{ use generic-service host_name remote-windows-host service_description W3SVC check_command check_nt!SERVICESTATE!-d SHOWALL -l W3SVC } define service{ use generic-service host_name remote-windows-host service_description Explorer check_command check_nt!PROCSTATE!-d SHOWALL -l Explorer.exe }

5. 启用密码保护

如果您在 Windows 机器上 NSClient++ 配置文件的 NSC.ini 文件中指定了密码,则需要修改 check_nt 命令定义以包含密码。修改/usr/local/nagios/etc/commands.cfg文件,添加密码如下图。

define command{ command_name check_nt command_line $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -s My2Secure$Password -v $ARG1$ $ARG2$ }

6. 验证配置并重启 Nagios。

验证 nagios 配置文件,如下所示。

如何在 Linux 上使用 Nagios 监控远程 Windows 机器

[nagios-server]# /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,如下图。

[nagios-server]# /etc/rc.d/init.d/nagios stop Stopping nagios: .done. [nagios-server]# /etc/rc.d/init.d/nagios start Starting nagios: done.

从 Nagios Web UI (http://nagios-server/nagios) 验证远程 Windows 主机上运行的各种服务的状态,如下所示。

Linux Windows

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:MySQL 系列教程之(十)索引原理:B+ 树与索引丨【绽放吧!数据库】
下一篇:光变声
相关文章