码迷,mamicode.com
首页 > 移动开发 > 详细

Nagios4.3.1监控Centos6.7

时间:2017-06-23 10:45:44      阅读:259      评论:0      收藏:0      [点我收藏+]

标签:linux   windows   服务器   

上一篇Nagios监控windows中已经写到Nagios的安装过程,这里不再重复。



基于NPRE检测linux

在linux主机上安装NRPE,并通过5666端口让服务端check_nrpe跟NRPE进行通讯

NRPE(Nagios Remote Plugin Executor)是用于在远端服务器上运行检测命令的守护进程,他用于让Nagios监控端基于安装的方式触发远端主机上的检测命令,并将检测结果输出至监控端,而其执行的开销远低于基于SSH的检测方式,而且检测过程并补需要远程主机上的系统账号等信息,其按期性也高于SSH的检测方式

安装前准备
调整系统时间
下载nagios-plugins-2.2.1.tar.gz
https://www.nagios.org/downloads/nagios-plugins/
下载nrpe-3.1.0.tar.gz

=============================================================
配置被监控端Nagios Client

1. 安装nrpe和nagios插件
[root@client ~]# yum install openssl openssl-devel xinetd gcc make

[root@client ~]# useradd nagios
[root@client ~]# tar xvf nagios-plugins-2.2.1.tar.gz
[root@client ~]# cd nagios-plugins-2.2.1
[root@client nagios-plugins-2.2.1]# ./configure && make && make install

[root@client ~]# tar xvf nrpe-2.13.tar.gz
[root@client ~]# cd nrpe-2.13
[root@client nrpe-2.13]# ./configure && make && make install
[root@client nrpe-2.13]# make install-daemon-config
[root@client nrpe-2.13]# make install-xinetd
[root@client nrpe-2.13]# vim /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 = 127.0.0.1 10.200.1.23    //10.200.1.23 为nagios监控中心地址    #而且中间必须是空格
}
技术分享[root@client nrpe-2.12]# vim /etc/services
nrpe 5666/tcp # NRPE //添加该行
[root@client nrpe-2.13]# service xinetd restart
[root@client nrpe-2.13]# chkconfig xinetd on          #添加开机自启动
[root@client nrpe-2.13]# chkconfig --list xinetd     #查看2345是否on

[root@client nrpe-2.13]# netstat -tunpl | grep 5666
tcp        0      0 :::5666                     :::*                        LISTEN      2818/xinetd   
技术分享
2. 配置监控本地私有资源
[root@client nrpe-2.12]# vim /usr/local/nagios/etc/nrpe.cfg
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_root]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/mapper/vg01-lv_root
command[check_home]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/mapper/vg01-lv_home
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 50% -c 40%
[root@client ~]# service xinetd restart

开放5666端口并重启防火墙
[root@localhost /]# vim /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 5666 -j ACCEPT
技术分享

[root@localhost /]# service iptables restart

[root@localhost ~]# netstat -tnlp     查看监听端口5666端口上已经开启了xinetd服务

技术分享


========================================================
配置监控中心Nagios Server
1. 安装nrpe插件并测试
[root@master ~# tar xvf nrpe-2.13.tar.gz //仅需要check_nrpe插件
[root@master nrpe-2.13]# ./configure && make all && make install
[root@master ~]# /usr/local/nagios/libexec/check_nrpe -H 10.200.1.24
NRPE v2.13


定义主机和定义服务
[root@linyangjun local]# cd /etc/nagios/
编辑nagiios.cfg
增加cfg_file=/etc/nagios/objects/centos6.cfg  保存后退出
技术分享切换到[root@linyangjun nagios]# cd objects/
[root@linyangjun objects]# vim cnetos6.cfg          #新增centos6.cfg 文件
填入内容:
# Define a host for the local machine

define host{
use linux-server
host_name Centos6                                   #监控端显示名称            
alias web-10.200.1.24
address 10.200.1.24                                 #被监控端IP  
}

# Define a service to check the disk space of the root partition
# on the local machine. Warning if < 20% free, critical if
# < 10% free space on partition.
define service{
use local-service
host_name Centos6
service_description Root Partition
check_command check_nrpe!check_root
}

# Define a service to check the swap usage the local machine.
# Critical if less than 10% of swap is free, warning if less than 20% is free
define service{
use local-service
host_name Centos6
service_description Swap Usage
check_command check_nrpe!check_swap
}

# Define a service to check the number of currently running procs
# on the local machine. Warning if > 250 processes, critical if
# > 400 users.
define service{
use local-service
host_name Centos6
service_description Total Processes
check_command check_nrpe!check_total_procs
}

#保存后退出

/usr/local/nagios/bin/nagios -v /etc/nagios/nagios.cfg   #可验证语法是否错误


测试通过之后重启nagios服务

#service nagios restart

技术分享


在/usr/local/nagios/libexec 下,使用cher_nrpe -H 10.200.1.24 测试链接,显示版本号表示链接正常

技术分享



重启完毕打开监控web界面,登录之后可以看到centos6已经在监控列表中

技术分享




本文出自 “centos6使用xtrabackup” 博客,请务必保留此出处http://9052426.blog.51cto.com/9042426/1941052

Nagios4.3.1监控Centos6.7

标签:linux   windows   服务器   

原文地址:http://9052426.blog.51cto.com/9042426/1941052

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!