监控Linux或Unix主机
一、概述
有两种不同的方法监控linux/Unix主机的服务器和属性:
第一种是使用共享SSH键和check_by_ssh插件来执行远程服务器上的插件.这种方法会导致被监控的服务器负载过高不推荐使用.
第二种是使用NRPE插件,NRPE允许你执行远程服务器上的插件,推荐使用此种方式.
二、NRPE的使用
1.概述
a)设计NRPE插件的原因是为了远程Linux/Unix主机执行插件,用来监控“本地”类似于CPU负载、内存使用量等等.如果想实现这些功能那么必须在linux/Unix主机中安装NRPE插件.
b)设计概述
NRPE插件由两部分组成:
①check_nrpe插件,它使用在本地主机上.
②NRPE守护进程,它在远程监控机上运行.
当Nagios需要从远端监控机上获取监控项状态时
①Nagios将执行check_nrpe插件以及告诉它需要检查什么服务.
②本地check_nrpe插件通过SSL加密连接远端NRPE守护进程.
③NRPE守护检查运行相关插件来检查服务或资源的状态.
④检查结果是通过NRPE守护进程返回给check_nrpe插件,然后返回结果返回到Nagios进程.
2.使用示例
a)直接检查
在远程linux/Unix主机上使用NRPE插件来监控本地资源,如:cpu使用率、内存使用率、swap使用率、当前用户、硬盘使用率、进程状态等等.
b)间接检查
你可以使用NRPE插件间接的检查服务器资源,可能从监控机不能直接到达Nagios主机.
3.安装
为了使用NRPE插件,你需要在监控主机上安装NRPE.
a)先决条件
为了成功安装你需要:
- 在远程主机上有root权限
- 远程主机上有nagios用户
b)假设
你想运行NRPE守护进程没有inetd或者xinetd那么请阅读
- README
- SECURITY
c)远程主机设置
①创建账户
创建账户需要使用root账户
/usr/sbin/useradd nagios
passwd nagios
②安装Nagios插件
创建下载目录
mkdir ~/downloads
cd ~/downloads
通过http://www.nagios.org/download/下载最新版本的Nagios 插件压缩包
wget http://osdn.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.6.tar.gz
解压Nagios tarball
tar -zxvf nagios-plugins-1.4.6.tar.gz
cd nagios-plugins-1.4.6
编译安装插件
./configure
make
make install
插件目录权限设置
chown nagios.nagios /usr/local/nagios
插件权限设置
chown -R nagios.nagios /usr/local/nagios/libexec
③安装xinetd
检查系统是否安装xinetd
若如没有安装可通过“yum install xinetd"命令安装
④安装NRPE守护进程
通过http://www.nagios.org/download/下载最新的NRPE源码包
cd ~/downloads
wget http://osdn.dl.sourceforge.net/sourceforge/nagios/nrpe-2.8.tar.gz
解压NRPE
tar -zxvf nrpe-2.8.tar.gz
cd nrpe-2.8
编译NRPE插件
./configure
make all
安装NRPE插件、守护进程和配置文件
make install-plugin
make install-daemon
make install-daemon-config
使用xinetd服务启动NRPE守护进程
make install-xinetd
编辑/etc/xinetd.d/nrpe文件
在only_from添加本机IP地址和Nagios服务器IP地址
格式如下
only_from = 127.0.0.1 <nagios_ip_address>
编辑/etc/services文件
添加NRPE守护进程
格式如下
nrpe 5666/tcp #NRPE
重启xinetd服务
service xinetd restart
⑤测试NRPE守护进程
确保nrpe守护进程在xinetd下运行
netstat -at | grep nrpe
输出如下
tcp 0 0 *:nrpe *:* LISTEN
如果没有上述输出请检查第④步
检查nrpe运行是否正常
/usr/local/nagios/libexec/check_nrpe -H localhost
返回NRPE的版本为运行正常
⑥打开防火墙限制
iptables -I RH-Firewall-1-INPUT -p tcp -m tcp –dport 5666 -j ACCEPT
保存规则
service iptables save
⑦自定义NRPE命令
你可以通过编辑/usr/local/nagios/etc/nrpe.cg来增加你想要的check命令
d)监控主机设置
在监控主机需要设置如下几步:
- 安装check_nrpe插件
- 创建check_nrpe插件使用Ngios命令定义
- 创建Nagios主机和服务器定义用来监控远程主机
①安装check_nrpe插件
安装需要使用root权限
创建下载目录
mkdir ~/downloads
cd ~/downloads
通过http://www.nagios.org/download/下载最新版的nrpe
wget http://osdn.dl.sourceforge.net/sourceforge/nagios/nrpe-2.8.tar.gz
解压nrpe tarball
tar -zxvf nrpe-2.8.tar.gz
cd nrpe-2.8
编译NRPE插件
./configure
make all
安装NRPE插件
make install-plugin
②NRPE通讯测试
使用命令
/usr/local/nagios/libexec/check_nrpe -H 192.168.0.1
返回NRPE版本为正常
③创建命令定义
为了使Nagios配置文件使用它,你需要创建一个命令定义.
vi /usr/local/nagios/etc/commands.cfg
增加定义项
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
④创建主机和服务定义
创建一些对象的定义用来监控远程Linux/Unix主机.
接下来定义一个新的主机
建议增加linux监控主机时以主机为名称新建配置文件
cp /usr/local/nagios/etc/objects/localhost.cfg /usr/local/nagios/etc/objects/<linuxIP>.cfg
在将nagios.cfg配置中新增一行
vim /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/<linuxIP>.cfg
define host{
use linux-box ; Inherit default values from a template
host_name remotehost ; The name we're giving to this server
alias Fedora Core 6 ; A longer name for the server
address 192.168.0.1 ; IP address of the server
}
接下来定义一些服务
下列定义将监控远程主机上的CPU负载
define service{
use generic-service
host_name remotehost
service_description CPU Load
check_command check_nrpe!check_load
}
下列定义将监控远程主机上当前登录的用户
define service{
use generic-service
host_name remotehost
service_description Current Users
check_command check_nrpe!check_users
}
下列定义将监控远程主机上/dev/hda1的空间用量
define service{
use generic-service
host_name remotehost
service_description /dev/hda1 Free Space
check_command check_nrpe!check_hda1
}
下列服务将监控主机上进程总和
define service{
use generic-service
host_name remotehost
service_description Total Processes
check_command check_nrpe!check_total_procs
}
下列服务将监控主机上僵尸进程数
define service{
use generic-service
host_name remotehost
service_description Zombie Processes
check_command check_nrpe!check_zombie_procs
}
⑤重启Nagios
首先使用命令
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
确认配置文件正确
使用
service nagios restart
重启Nagios服务
4.自定义配置
每当想要自定义一个新的服务时需要做两件事情
1.在远程主机上nrpe.cfg中添加一个新的命令定义
2.Nagios定义一个新的服务定义
下列是自定义监控swap使用率的例子
a)远程主机配置
可以使用check_swap插件来监控swap的使用量.
check_swap在/usr/local/nagios/libexec目录下
使用nagios用户登录至远程主机
手动运行check_swap命令来调整警告阀值
下面例子表示如果swap空间小于20%告警“警告”,如果swap空间小于10%告警“严重警告”
/usr/local/nagios/libexec/check_swap -w 20% -c 10%
编辑nrpe配置文件
vi /usr/local/nagios/etc/nrpe.cfg
添加一行新的check_swap命令定义
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%
重启NRPE进程即可.
具体信息请移步至
相关推荐
提供linux系统CPU、内存、磁盘IO等项的具体监控方法
UNIX® and Linux® System Administration Handbook, Fifth Edition, is today’s definitive guide to installing, configuring, and maintaining any UNIX or Linux system, including systems that supply core ...
UNIX® and Linux® System Administration Handbook, Fifth Edition, is today’s definitive guide to installing, configuring, and maintaining any UNIX or Linux system, including systems that supply core ...
Linux System and Performance Monitoring
介绍linux监控工具的文档,很好的展示了从网络,io,cpu等各方面对系统状态进行监控的相关工具。
<filter-name>monitoring</filter-name> <filter-class>net.bull.javamelody.MonitoringFilter</filter-class> </filter> <filter-name>monitoring</filter-name> <url-pattern>/*</url-pattern> </...
Linux Performance Monitoring
The purpose of this document is to describe how to monitor Linux operating systems for performance. This paper examines how to interpret common Linux performance tool output. After collecting this ...
一个简短的44页的英文教程,简单实用,针对性强
Linux-Performance-Monitoring.pdf(1 file)
A Linux and UNIX® System Programming Handbook Chapter 1: History and Standards Chapter 2: Fundamental Concepts Chapter 3: System Programming Concepts Chapter 4: File I/O: The Universal I/O Model ...
The most powerful and popular Linux monitoring open source project.
tracking of the monitor cross reference ID for the current monitoring session // for each device known by the CTsapiWnd // 2. tracking of all of the calls and connections for each device known by ...
<filter-name>monitoring</filter-name> <filter-class>net.bull.javamelody.MonitoringFilter</filter-class> <param-name>log</param-name> <param-value>true</param-value> </init-param> </...
Go实现的简易Linux监控系统的后端,适用于x86_64系统 Go实现的简易Linux监控系统的后端,适用于x86_64系统 Go implementation of a simple Linux monitoring system back-end, suitable …所有源码均经过严格测试,...
cpu监控脚本以及文档说明,负载监控脚本以及文档说明
介绍linux io 监控和优化,文字简单到位。 Disk IO subsystems are the slowest part of any Linux system. This is due mainly to their distance from the CPU and the fact that disks require the physics to ...
Device Monitoring Studio is a software solution for monitoring, logging and analyzing data coming through PC ports and connections. Combining together the power of Serial, USB and Network monitoring ...
Statistical profile monitoring is an area of statistical quality control that is growing in significance for researchers and practitioners, specifically because of its range of applicability across ...