当前位置:首页 > CN2资讯 > 正文内容

用nagios监控linux和windows服务器(五)linux服务器监控

2天前CN2资讯

 八、使用Nagios监控Windows服务器

1.windows机器的配置

1).监控方法的选择

其实Nagios对服务器的监控方法有很多,但大体上可以分为三种:

a. 通过snmp协议编写脚本使用snmpwalk或snmpget等client程序对远程主机进行数据的抓取

b. 走c/s方式,通过特定的客户端用他们自己的协议对服务器进行数据抓取,这一类需要在目标服务器上安装服务器端(即Listener),服务器端通过自己的程序对服务器上的数据进行收集(wmi,vbscript),最后再由nagios服务器上的客户端来取数据。这类的代表应用有NSClient++,pNSClient,nrpe_nt等等

c. 还是走c/s方式,只不过这次nagios本机变成了服务器端,目标监控服务器上通过安装客户端向nagios服务器推送本机的相关数据。这类的代表应用有NSCA等

 

鉴于我需要用到performance data来使用pnp进行绘图,而本人编程能力非常有限,再加上我是个非常懒的SA。所以,我选择了上面的第二类方式对我的所有Windows服务器进行监控,选择的应用是NSClient++。

NSCLient++是针对Windows操作系统的一款简单但是功能强大又安全的监控服务器端,同时兼容了NSClient/NRPE/NSCA三种方式。它能监控cpu,内存,硬盘,进程,服务状态,性能计数器等等。NSClient++提供的CheckCommands.

2).下载NSClient++-Win32-0.3.5.msi并安装。

运行nsclient++,打开cmd窗口,输入:

NSClient++ /install

NSClient++ SysTray install

NSClient++ /start

如果有防火墙,请开放相应端口。

3). 修改配置文件

a. 到安装目录打开NSC.ini文件进行修改:

在[modules]模块,将除RemoteConfiguration.dll外的所有dll文件明前的注释(;)去掉。

在[Settings]模块可以设置一个连接密码password=PWD,为了简单,在此不设密码。设置 allowed_hosts=127.0.0.1/32,192.168.0.19,可以连接的监控服务器的地址,如果写成192.168.0.0/24 则表示该子网内的所有机器都可以访问;如果这个地方是空白则表示所有的主机都可以连接上来(注意在[NSClient]有allowed_hosts的同样设置,不要设置错了),最后不要忘记去掉前面的注释符(;)。

b. 其他模块的配置:(把以下模块相关行的注释去掉就行了)

[log]

file=nsclient.log

date_mask=%Y-%m-%d %H:%M:%S

root_folder=exe

 

[NSClient]

#允许访问的主机IP,多个主机用,分隔

allowed_hosts=127.0.0.1/32

#监听端口

port=12489

socket_timeout=30

 

[NRPE]

#监听端口

port=5666

command_timeout=60

#不使用ssl,否则容易出错

use_ssl=0

#允许访问的主机IP,多个主机用,分隔

allowed_hosts=127.0.0.1/32

socket_timeout=30

#启用performance_data(关键,就看着他画图呢)

performance_data=1

 

[NRPE Handlers]

#定义NRPE的命令

#监测内存

check_mem=inject checkMem MaxWarn=80% MaxCrit=90% ShowAll=long type=physical

 

编辑完成以后保存关闭,在windows防火墙里开放tcp12489和5666端口,然后在Windows的服务里面找到新装的NSClientpp服务,启动它。

2.Linux监控服务器上nagios的配置

1).创建监控配置文件print-w-30.cfg,使用check_nt命令监控windows系统信息(此命令默认已定义)。

Windows监控示例配置文件:

[root@tech etc]# vi /usr/local/nagios/etc/servers/print-w-80.cfg

###################################################################

# WINDOWS.CFG – SAMPLE CONFIG FILE FOR MONITORING A WINDOWS MACHINE

#

# Last Modified: 06-13-2007

#

# NOTES: This config file assumes that you are using the sample configuration

# files that get installed with the Nagios quickstart guide.

#

####################################################################

 

####################################################################

####################################################################

#

# HOST DEFINITIONS

#

####################################################################

####################################################################

 

# Define a host for the Windows machine we’ll be monitoring

# Change the host_name, alias, and address to fit your situation

 

# 定义windows主机名和IP的地方

define host{

use windows-server ; Inherit default values from a template

host_name print80 ; The name we’re giving to this host

alias Print80 ; A longer name associated with the host

address 192.168.0.80 ; IP address of the host

}

# address后面跟的是被监控端windows机器的IP地址,多个IP用,分隔

 

####################################################################

####################################################################

#

# HOST GROUP DEFINITIONS

# 主机组在/usr/local/nagios/etc/servers/hostgroup.cfg中单独配置

####################################################################

####################################################################

# Define a hostgroup for Windows machines

# All hosts that use the windows-server template will automatically be a member of this group

 

#define hostgroup{

# hostgroup_name windows-servers ; The name of the hostgroup

# alias Windows Servers ; Long name of the group

# }

#####################################################################

#####################################################################

#

# SERVICE DEFINITIONS

#

#####################################################################

#####################################################################

# Create a service for monitoring the version of NSCLient++ that is installed

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

 

# 利用check_nt命令监控NSClient++,check_nt命令默认已定义

define service{

use generic-service

host_name print80

service_description NSClient++ Version

check_command check_nt!CLIENTVERSION

}

 

# Create a service for monitoring the uptime of the server

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

 

# 监控系统运行的时间

define service{

use generic-service

host_name print80

service_description Uptime

check_command check_nt!UPTIME

}

 

# Create a service for monitoring CPU load

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

 

# 监控CPU使用率,80%警告,90%严重

define service{

use generic-service

host_name print80

service_description CPU Load

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

}

 

# Create a service for monitoring

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

 

# 监控内存使用率,记住此为虚拟内存和物理内存的总量,80%警告,90%严重

define service{

use generic-service

host_name print80

service_description Memory Usage

check_command check_nt!MEMUSE!-w 80 -c 90

}

 

# Create a service for monitoring C:\ disk usage

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

 

# 监控C盘空间的使用率,80%警告,90%严重

define service{

use generic-service

host_name print80

service_description C_Drive_Space

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

}

 

# Create a service for monitoring the W3SVC service

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

 

# 监控w3svc服务的状态,w3svc是用来监视web服务的健康状况的

define service{

use generic-service

host_name print80

service_description W3SVC

check_command check_nt!SERVICESTATE!-d SHOWALL -l W3SVC

}

 

# Create a service for monitoring the Explorer.exe process

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

 

# 监控explorer进程

define service{

use generic-service

host_name print80

service_description Explorer

check_command check_nt!PROCSTATE!-d SHOWALL -l Explorer.exe

}

2).主机组配置文件

root@tech etc]# vi /usr/local/nagios/etc/servers/hostgroup.cfg

# 配置linux主机组的地方,可将要监控的linux主机加进来

define hostgroup{

hostgroup_name linux-servers ; The name of the hostgroup

alias Linux Servers ; Long name of the group

members localhost,wiki ; Comma separated list of hosts that belong to this group

}

 

# 配置windows主机组的地方,可将要监控的windows主机加进来

define hostgroup{

hostgroup_name windows-servers ; The name of the hostgroup

alias Windows Servers ; Long name of the group

members print80 ; Comma separated list of hosts that belong to this group

}

# 去掉上面windows主机配置部分的注释

3). 使用NSClient和NRPE监控

修改commands.cfg,增加使用NSClient和NRPE收集数据的命令,因为NSClient监测到的内存大小都大于实际的物理内存(估计可能是总计),所以使用NRPE监测内存

 

# 'check_remote_nt_disk' command definition,监测硬盘使用量

define command{

        command_name    check_remote_nt_disk

        command_line$USER1$/check_nt -H $ARG1$ -p $ARG2$ -v $ARG3$ -l $ARG4$ -w $ARG5$ -c $ARG6$

        }

 

# 'check_remote_nt_cpu' command definition,监测cpu负载

define command{

        command_name    check_remote_nt_cpu

        command_line    $USER1$/check_nt -H $ARG1$ -p $ARG2$ -v $ARG3$ -l $ARG4$

        }

 

# 'check_nt_mem_nrpe' command definition,监测内存使用量

define command{

        command_name    check_nt_mem_nrpe

        command_line    $USER1$/check_nrpe -H $ARG1$ -n -p $ARG2$ -c $ARG3$

        }

 

# 'check_avg_disk_queue' command definition,监测硬盘读写队列

define command{

        command_name    check_avg_disk_queue

        command_line    $USER1$/check_nt -H $ARG1$ -p $ARG2$ -v $ARG3$ -l $ARG4$ -d $ARG5$ -w $ARG6$ -c $ARG7$

        }

 

修改print-w-80.cfg中service定义里面的check_command

 

define service{

        use                             web-service,service-pnp

        host_name                       web1

        service_description             disk-d

        check_command                   check_remote_nt_disk!10.10.10.11!5666!USEDDISKSPACE!d!85!90

        }

 

define service{

        use                             web-service,service-pnp

        host_name                       web1

        service_description             mem

        check_command                   check_nt_mem_nrpe!10.10.10.11!5667!check_mem

        }

 

define service{

        use                             web-service,service-pnp

        host_name                       web4

        service_description             avg-disk-queue

        check_command                   check_avg_disk_queue!10.10.10.24!5666!COUNTER!"\\PhysicalDisk(_Total)\\Avg. Disk Queue Length","%.2f"!SHOWALL!14!28

        }

 

修改完以后重新配置nagios使配置生效

#/etc/init.d/nagios reload

 

    你可能想看:

    扫描二维码推送至手机访问。

    版权声明:本文由皇冠云发布,如需转载请注明出处。

    本文链接:https://www.idchg.com/info/31347.html

    分享给朋友:

    “用nagios监控linux和windows服务器(五)linux服务器监控” 的相关文章

    不限制流量套餐:选择适合你的最佳电信方案

    在我们这个信息高速发展的时代,手机成为了我们日常生活中不可或缺的一部分。而随着视频、游戏和社交媒体等应用的流行,很多用户的流量需求逐渐增加。这也促使电信运营商们纷纷推出了“不限流量套餐”,以满足用户对流量的广泛需求。 简单来说,不限流量套餐意指用户可以在一个月内不限流量使用手机数据,虽然很多套餐背后...

    如何开启BBR查询并提升TCP网络性能

    BBR(Bottleneck Bandwidth and Round-trip propagation time)是一种由Google开发的TCP拥塞控制算法,我对它的了解让我感到非常兴奋。BBR旨在通过精确的网络条件监测,以提高传输速度和稳定性。传统的拥塞控制算法往往依赖于丢包率的变化来调整传输速...

    Rackdog:高性价比的独立服务器租赁和托管解决方案

    Rackdog是一家充满活力的基础设施即服务(IaaS)提供商,成立于2020年。作为互联网时代的重要角色,Rackdog专注于独立服务器出租和托管业务,拥有一系列丰富的服务。通过自己的设备和网络架构,Rackdog正在为客户提供优质的托管解决方案。 Rackdog的AS号是AS398465,拥有多...

    BGPTO独立服务器:高性能云主机解决方案

    BGPTO是一家由国人创办的云服务器主机商,致力于为用户提供高性能的独立服务器。随着全球互联网的发展,对云计算和服务器主机的需求不断增加,BGPTO顺应这一趋势,选择在日本、新加坡、香港和美国等地设立机房。公司希望通过独立服务器的销售,满足用户在不同地区的需求,尤其是针对国内用户和企业的海外业务拓展...

    美国VPS市场分析:选择高性价比服务的指南

    在全球众多VPS市场中,美国VPS市场以其庞大的规模和快速的增长而著称。我总能在网上看到一些关于美国VPS的讨论,许多创业者和开发者都对它们赞不绝口。这一市场的吸引力,首先得益于云计算的迅猛发展。越来越多的企业和个人用户意识到,借助VPS可以更灵活地管理自己的网络资源,满足不断增长的需求。 美国VP...

    easyvm:轻松创建和管理虚拟机的虚拟化解决方案

    什么是 easyvm easyvm 是一种轻量级的虚拟化解决方案,旨在帮助用户快速、简单地创建和管理虚拟机。面对日益增长的技术需求和IT成本压力,easyvm 提供了一个灵活且易于使用的平台,适合不同技术水平的用户。它不仅支持多种操作系统的虚拟化,还能够满足不同开发、测试以及生产环境的需求。每个人都...