怎么用Nagios监测Windows服务器

怎么用Nagios监测Windows服务器,第1张

监控主机配置:redhat linux as4,nagios3

监控主机:Windows Server 2008 R2 Enterprise,nsclient++0.4.4.172

Nagios是一款开源的免费网络监视工具,其功能强大,灵活性强。能有效监控Windows、Linux和Unix的主机状态,交换机路由器等网络设置,打印机等。nagios监控windows系统有三种实现方式:SNMP、NSClient++、NRPE。

下面介绍使用NSClient++方式来监控Windows:

首先在windows下安装nsclient++,运行NSCP-0.4.0.172-x64.msi安装文件,一步一步往下走,其中需要设置nagios监控主机IP和NSClient密码(值当使用check_nt时使用),如图1所示:

Allowed hosts:填写nagios监控主机IP

NSClient Password:当使用命令check_nt时需要设置密码,根据自己情况设置

Module to load:根据自己的需要选择相应的模块

安装完毕以后,打开windows服务管理器,查看nsclient服务是否启动,如图2所示:

然后在nagios监控主机上面进行相关的配置,主要涉及两个配置文件nagios.cfg和windows.cfg

(1)因为nagios是模块化调用,先到配置文件打开windows相关模块,编辑nagios.cfg文件

[root@localhost etc]# ls

cgi.cfg htpasswd nagios.cfg nrpe.cfg objects objects.bak objects.tar resource.cfg

[root@localhost etc]# pwd

/usr/local/nagios/etc

[root@localhost etc]# vi nagios.cfg

将#cfg_file=/usr/local/nagios/etc/objects/windows.cfg该行前面的#注释去掉即可.

(1)修改windows.cfg配置文件,需要修改define host和define service两部分

# 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 video4-beijing The name we're giving to this host 被监控主机的主机名

alias video4-beijing A longer name associated with the host

contact_groupssa

address 10.12.4.169 IP address of the host 被监控主机的IP

}

# Create a service for monitoring CPU load

# Change the host_name to match the name of the host you defined above

define service{

use generic-service

host_name video4-beijing

service_description CPU Load

check_command check_nt!CPULOAD!-l 5,80,90

contact_groups sa

}

# Create a service for monitoring

# Change the host_name to match the name of the host you defined above

define service{

use generic-service

host_name video4-beijing

service_description Memory Usage

check_command check_nt!MEMUSE!-w 80 -c 90

contact_groups sa

}

# Create a service for monitoring C:\ disk usage

# Change the host_name to match the name of the host you defined above

define service{

use generic-service

host_name video4-beijing

service_description C:\ Drive Space

check_command check_nt!USEDDISKSPACE!-l c -w 80 -c 90

contact_groups sa

}

修改完相关的配置文件以后,执行如下命令检查配置文件是否正确:

[root@localhost objects]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

遇到的问题,在检查配置文件时错误信息如下:

Checking services...

Error: Contact group 'admins' specified in service 'C:\ Drive Space' for host 'video4-beijing' is not defined anywhere!

Error: Contact group 'admins' specified in service 'Explorer' for host 'video4-beijing' is not defined anywhere!

Error: Contact group 'admins' specified in service 'Memory Usage' for host 'video4-beijing' is not defined anywhere!

Checked 14 services.

Checking hosts...

Error: Contact group 'admins' specified in host 'video4-beijing' is not defined anywhere!

Checked 7 hosts.

Checking host groups...

Checked 2 host groups.

Checking service groups...

Checked 0 service groups.

Checking contacts...

Checked 1 contacts.

Checking contact groups...

Checked 1 contact groups.

Checking service escalations...

Checked 0 service escalations.

Checking service dependencies...

Checked 0 service dependencies.

Checking host escalations...

Checked 0 host escalations.

Checking host dependencies...

Checked 0 host dependencies.

Checking commands...

Checked 25 commands.

Checking time periods...

Checked 5 time periods.

Checking for circular paths between hosts...

Checking for circular host and service dependencies...

Checking global event handlers...

Checking obsessive compulsive processor commands...

Checking misc settings...

Total Warnings: 0

Total Errors: 4

***>One or more problems was encountered while running the pre-flight check...

Check your configuration file(s) to ensure that they contain valid

directives and data defintions. If you are upgrading from a previous

version of Nagios, you should be aware that some variables/definitions

may have been removed or modified in this version. Make sure to read

the HTML documentation regarding the config files, as well as the

'Whats New' section to find out what has changed.

以上问题的原因是因为一开始在windows.cfg文件中定义host和service时没有增加contact_groups sa这个字段,host和service默认所在的contact_group为admins,而我的nagios监控主机contacts.cfg文件中配置的contactgroup为sa。

方法/步骤

nagios监控windows服务器的时候,服务器需要安装nsclient++,我这里安装的版本是NSCP-0.4.1.73-x64,双击安装,下一步,并选择同意安装协议,下一步。

选择典型安装,继续下一步,允许主机这里填写nagios服务器的地址,并勾选相应的模块进行加载,下一步,直至安装成功。

验证nsclient是否安装成功,我们查看是否启用了5666和12489端口,如果有,表明NSClient服务启动正常。防火墙也要打开tcp的12489端口,否则nagios 检查此服务的时候会报错。

在运行里面输入services.msc打开服务,找出nsclient++服务是否已经开启,发现状态是已开启,启动类型是自动。

进入nsclient安装目录,查看nsclient.ini文件,这里允许主机一定要是nagios服务器的地址。

进入目录 /usr/local/nagios/libexec/

在nagios监控端验证是否可以监控到windows主机,用命令./check_nt -H 192.168.1.215 -p 12489 -v UPTIME可以检测到Windows服务器已经在线了5小时30分钟,也表示可以从Windows服务器拿到数据了。

定义主机、服务、命令

定义命令,进入到目录下

/usr/local/nagios/etc/objects/编辑目录下面的windows.cfg,修改为想要监控的Windows主机,

需要进入到目录下/usr/local/nagios/etc/,在nagios.cfg里面调用刚刚修改的windows.cfg模板,增加一行cfg_file=/usr/local/nagios/etc/objects/windows.cfg,用命令/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg,验证下配置是否正确,并重启nagios服务。

登录到nagios,发现winserver已经监控到了,目前在线的主机数为2,相应的windows服务也被监控到了,从而实现了nagios对Windows服务器的监控。

说明:

● 主机名 host_name,必须是主机配置文件hosts.cfg中定义的主机。

● 检查用的命令check_command,在命令配置文件中定义或在nrpe配置文件中有定义。

● 最大重试次数max_check_attempts 一般设置为3-4次比较好,这样不会因为网络闪断片刻而发生误报。

● 检查间隔和重试检查间隔的单位是分钟。

● 通知间隔指探测到故障以后,每隔多少时间发送一次报警信息。 它的单位是分钟。

● 通知选项跟服务定义配置文件相同。

● 联系组contact_groups由配置文件contactgroup.cfg定义。

● 检查主机资源需要安装和配置nrpe,这个过程在后面完成。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11600939.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-17
下一篇2023-05-17

发表评论

登录后才能评论

评论列表(0条)

    保存