Nagios 监控mysql服务器详细实现过程

1、NRPE介绍

NRPE是Nagios的一个功能扩展,它可在远程Linux/Unix主机上执行插件程序。通过在远程服务器上安装NRPE插件及Nagios插件程序来向Nagios监控平台提供该服务器的本地情况,如CPU负载,内存使用,磁盘使用等。这里将Nagios监控端称为Nagios服务器端,而将远程被监控的主机称为Nagios客户端。

Nagios监控远程主机的方法有多种,其方式包括SNMP,NRPE,SSH,NCSA等。这里介绍其通过NRPE监控远程Linux主机的方式。

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

2、NRPE的工作原理

NRPE有两部分组成

check_nrpe插件:位于监控主机上

nrpe daemon:运行在远程主机上,通常是被监控端agent

注意:nrpe daemon需要Nagios-plugins插件的支持,否则daemon不能做任何监控

当Nagios需要监控某个远程Linux主机的服务或者资源情况时:

首先:Nagios会运行check_nrpe这个插件,告诉它要检查什么;

其次:check_nrpe插件会连接到远程的NRPE daemon,所用的方式是SSL;

然后:NRPE daemon 会运行相应的Nagios插件来执行检查;

最后:NRPE daemon 将检查的结果返回给check_nrpe 插件,插件将其递交给nagios做处理。

<版权所有,文章允许转载,但必须以链接方式注明源地址,否则追究法律责任!> 
原博客地址:    http://blog.csdn.net/mchdba/article/details/46666229
原作者:黄杉 (mchdba)

3、被监控端安装Nagios-plugins插件和NRPE

去mysql客户端安装nrpe客户端服务

3.1、添加nagios用户

[[email protected] ~]# useradd -s/sbin/nologin nagios

3.2,安装nagios插件

[[email protected] ~]# yum -yinstall gcc gcc-c++ make openssl openssl-devel

3.3,安装nrpe

tar -xvf nrpe-2.15.tar.gz

cd nrpe-2.15

./configure--with-nrpe-user=nagios --with-nrpe-group=nagios --with-nagios-user=nagios--with-nagios-group=nagios --enable-command-args --enable-ssl

make all

make install-plugin

make install-daemon

make install-daemon-config

3.4,去检查nrpe配置

grep -v ‘^#‘ /usr/local/nagios/etc/nrpe.cfg |sed ‘/^$/d‘

[[email protected] ~]# grep -v ‘^#‘ /usr/local/nagios/etc/nrpe.cfg|sed ‘/^$/d‘

log_facility=daemon

pid_file=/var/run/nrpe.pid

server_port=5666

nrpe_user=nagios

nrpe_group=nagios

allowed_hosts=127.0.0.1,192.168.121.211

dont_blame_nrpe=0

allow_bash_command_substitution=0

debug=0

command_timeout=60

connection_timeout=300

command[check_users]=/usr/local/nagios/libexec/check_users-w 8 -c 12

command[check_load]=/usr/local/nagios/libexec/check_load -w15,10,5 -c 30,25,20

command[check_sda1]=/usr/local/nagios/libexec/check_disk -w20% -c 10% -p /dev/sda3

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 750 -c 800

command[check-host-alive]=/usr/local/nagios/libexec/check_ping-H 10.254.3.72 -w 3000.0,80% -c 5000.0,100% -p 5

command[check_mysql_status]=/usr/local/nagios/libexec/check_mysql-unagios -P3306 -s /usr/local/mysql/mysql.sock -Hlocalhost--password=‘[email protected]‘ -d test -w 60 -c 100

[[email protected] ~]#

3.5,启动nrpe

/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe

4,制作启动脚本:

[[email protected] bin]# cat /etc/init.d/nrped

#chkconfig: 2345 80 90

#description:auto_run

NRPE=/usr/local/nagios/bin/nrpe

NRPECONF=/usr/local/nagios/etc/nrpe.cfg

case "$1" in

start)

echo -n "Starting NRPE daemon..."

$NRPE -c $NRPECONF -d

echo " done."

;;

stop)

echo -n "Stopping NRPE daemon..."

pkill -u nagios nrpe

echo " done."

;;

restart)

$0 stop

sleep 2

$0 start

;;

*)

echo "Usage: $0 start|stop|restart"

;;

esac

exit 0

[[email protected] bin]#

5,设置启动

chmod +x /etc/init.d/nrped

chkconfig --add nrped

chkconfig nrped on

[[email protected] bin]# ps -eaf|grep nrpe

nagios  30440     1  0 23:48 ?        00:00:00 /usr/local/nagios/bin/nrpe -c/usr/local/nagios/etc/nrpe.cfg -d

root    30442  3292  0 23:48 pts/0    00:00:00 grep nrpe

[[email protected] bin]#

[[email protected] bin]# netstat -tnlp |grepnrpe

tcp       0      0 0.0.0.0:5666                0.0.0.0:*                   LISTEN      30440/nrpe

tcp       0      0 :::5666                     :::*                        LISTEN      30440/nrpe

[[email protected] bin]#

6,监控端安装nrpe

tar xf nrpe-2.15.tar.gz

cd nrpe-2.15

./configure --with-nrpe-user=nagios --with-nrpe-group=nagios --with-nagios-user=nagios --with-nagios-group=nagios  --enable-command-args --enable-ssl

make all

make install-plugin

#安装完成后,会在Nagios安装目录的libexec下生成check_nrpe的插件,如下所示:

[[email protected]_db2 nagios]#  ll /usr/local/nagios/libexec/check_nrpe

-rwxrwxr-x 1 nagios nagios 76777 Jun 2523:53 /usr/local/nagios/libexec/check_nrpe

[[email protected]_db2 nagios]#

检测报错:

[[email protected]_db2 libexec]# ./check_nrpe -H192.168.121.210

CHECK_NRPE: Error - Could not complete SSLhandshake.

[[email protected]_db2 libexec]#

去客户端在allowed_hosts中添加监控端IP地址

[[email protected] ~]# vim/usr/local/nagios/etc/nrpe.cfg

allowed_hosts=127.0.0.1,192.168.121.211

在mysql服务器上,报错:

[[email protected] ~]#/usr/local/nagios/libexec/check_mysql -unagios -P3306 -S -s/usr/local/mysql/mysql.sock -Hlocalhost --password=‘[email protected]‘ -d test -w 60-c 100

/usr/local/nagios/libexec/check_mysql:error while loading shared libraries: libmysqlclient.so.18: cannot open sharedobject file: No such file or directory

[[email protected] ~]#

[[email protected] ~]# find / -namelibmysqlclient.so.18

/usr/local/mysql/lib/libmysqlclient.so.18

/root/mysql/mysql-5.6.12/libmysql/libmysqlclient.so.18

/root/mysql-5.6.12/libmysql/libmysqlclient.so.18

[[email protected] ~]# ln -s/usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18

[[email protected] ~]#

添加mysql账号:

mysql> GRANT PROCESS, SUPER, REPLICATIONCLIENT ON *.* TO ‘nagios‘@‘localhost‘ IDENTIFIED BY ‘[email protected]‘;

Query OK, 0 rows affected (0.05 sec)

mysql>

客户端自己检测:

[[email protected] ~]#/usr/local/nagios/libexec/check_mysql -unagios -P3306  -s /usr/local/mysql/mysql.sock -Hlocalhost--password=‘[email protected]‘ -d test -w 60 -c 100

Uptime: 1823238  Threads: 6 Questions: 684495  Slow queries:0  Opens: 124  Flush tables: 1  Open tables: 116  Queries per second avg:0.375|Connections=3116c;;; Open_files=19;;; Open_tables=116;;; Qcache_free_memory=61538880;;;Qcache_hits=176271c;;; Qcache_inserts=41370c;;; Qcache_lowmem_prunes=0c;;;Qcache_not_cached=331835c;;; Qcache_queries_in_cache=3373;;; Queries=684496c;;;Questions=681384c;;; Table_locks_waited=0c;;; Threads_connected=5;;;Threads_running=2;;; Uptime=1823238c;;;

[[email protected] ~]#

7,完善配置文件

7.1在command.cfg里面添加监控command命令

将servers.cfg添加进nagios.cfg里面,将command.cfg里面的check_host_alive以及check_mysql_status补充好,然后重启nagios

# add by timman on 20150512

define command{

command_name    check_mysql_status

command_line    $USER1$/check_mysql_status-w $ARG1$ -c $ARG2$

}

# ‘check_nrpe‘ command definition,add bytimman on 20140508

define command{

command_name    check_nrpe

command_line    $USER1$/check_nrpe-H $HOSTADDRESS$ -c $ARG1$

}

define command{

command_name    check_host_alive

command_line    $USER1$/check_ping-H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5

}

7.2在servers.cfg里面添加check_mysql_status、 check_host_alive等服务监控项。

[[email protected]_db2 etc]# more servers.cfg

#  servicedefinition

define service{

host_name               cactitest

service_description     check_load

check_command          check_nrpe!check_load

max_check_attempts      5

normal_check_interval   3

retry_check_interval    2

check_period            24x7

notification_interval   10

notification_period     24x7

notification_options    w,u,c,r

contact_groups          dba

}

define service{

host_name               cactitest

service_description    check_host_alive

check_command          check_host_alive

max_check_attempts      5

normal_check_interval   3

retry_check_interval    2

check_period            24x7

notification_interval   10

notification_period     24x7

notification_options    w,u,c,r

contact_groups          dba

}

define service{

host_name               cactitest

service_description     Check Disksda1

check_command          check_nrpe!check_sda1

max_check_attempts      5

normal_check_interval   3

retry_check_interval    2

check_period            24x7

notification_interval   10

notification_period     24x7

notification_options    w,u,c,r

contact_groups          dba

}

define service{

host_name               cactitest

service_description     TotalProcesses

check_command           check_nrpe!check_total_procs

max_check_attempts      5

normal_check_interval   3

retry_check_interval    2

check_period            24x7

notification_interval   10

notification_period     24x7

notification_options    w,u,c,r

contact_groups          dba

}

define service{

host_name               cactitest

service_description     CurrentUsers

check_command          check_nrpe!check_users

max_check_attempts      5

normal_check_interval   3

retry_check_interval    2

check_period            24x7

notification_interval   10

notification_period     24x7

notification_options    w,u,c,r

contact_groups          dba

}

define service{

host_name               cactitest

service_description     CheckZombie Procs

check_command          check_nrpe!check_zombie_procs

max_check_attempts      5

normal_check_interval   3

retry_check_interval    2

check_period            24x7

notification_interval   10

notification_period     24x7

notification_options    w,u,c,r

contact_groups          dba

}

define service{

host_name               cactitest

service_description     CheckMysql Status

check_command          check_nrpe!check_mysql_status

max_check_attempts      5

normal_check_interval   3

retry_check_interval    2

check_period            24x7

notification_interval   10

notification_period     24x7

notification_options    w,u,c,r

contact_groups          dba

}

7.3 在nagios.cfg加载servers.cfg等配置文件

在nagios.cfg里面配置

cfg_file=/usr/local/nagios/etc/servers.cfg

同时添加新的主机或者服务配置cfg文件,都需要在nagios.cfg里面配置一下,然后重启nagios才能生效,如下所示:

[[email protected]_db2 nagios]# grep -v ‘^#‘/usr/local/nagios/etc/nagios.cfg |sed ‘/^$/d‘ |grep cfg_file

cfg_file=/usr/local/nagios/etc/objects/commands.cfg

cfg_file=/usr/local/nagios/etc/objects/contacts.cfg

cfg_file=/usr/local/nagios/etc/contactgroups.cfg

cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg

cfg_file=/usr/local/nagios/etc/objects/templates.cfg

cfg_file=/usr/local/nagios/etc/hosts.cfg

cfg_file=/usr/local/nagios/etc/servers.cfg

cfg_file=/usr/local/nagios/etc/hostgroups.cfg

cfg_file=/usr/local/nagios/etc/objects/localhost.cfg

[[email protected]_db2 nagios]#

8,之后在页面就可以看到监控效果了

参考文章:http://os.51cto.com/art/201409/452605.htm

时间: 2024-10-11 16:46:52

Nagios 监控mysql服务器详细实现过程的相关文章

Nagios监控MySQL报错:NRPE: Unable to read output的详细解决过程

前言:nagios界面上,看到监控mysql服务报错如下: Warning:NRPE: Unable to read output 1,去nagios监控服务器上check下 1.1,执行check_nrpe命令远程调用 在监控端nagios服务器上执行check_nrpe检查mysql状态报错如下: [[email protected] ~]# /usr/lib/nagios/plugins/check_nrpe  -H192.xx.180.xx -c check_mysql_status N

Nagios监控nginx服务详细过程

1在nginx 服务器上安装nrpe客户端: Nginx的服务需要监控起来,不然万一down了而不及时修复,会影响web应用,如下web应用上面启动的nginx后台进程[[email protected] ~]# ps aux|grep nginxnobody   15294  0.0  0.0  22432  3464 ?        S    Jul03   0:05 nginx: worker process      nobody   15295  0.0  0.0  22432  3

zabbix之监控MySQL服务器(可用于主从架构)

穿件监控MySQL的自定义参数 在zabbix的agent端添加配置文件 # vim /etc/zabbix/mysql/.my.cnf  用于连接MySQL的配置文件,无需显示输入用户和密码 [client]host     = localhostuser     = rootpassword = 123456socket   = /usr/local/mysql/mysql.sock[mysql]host     = localhostuser     = rootpassword =123

详解 Spotlight on MySQL监控MySQL服务器

详解 Spotlight on MySQL监控MySQL服务器 前一章详解了Spotlight on Unix 监控Linux服务器 ,今天再来看看Spotlight on MySQL怎么监控MySQL服务器. 注:http://www.cnblogs.com/Javame/p/3685512.html 第一步: 下载并安装mysql-connector-3.5x Spotlight on MySQL 连接mysql必须使用mysql-connector-3.5x,5.3.2版本我试了下不行,有

使用nagios监控HP服务器RAID

背景:单位在IDC机房选用了DELL和HP两种类型的服务器.对监控服务器硬件特别是RAID方面的信息,dell可以使用自带的OMSA程序进程监控.可是HP没有此方面的监控,服务器中的磁盘是最容易出现问题的,个人研究了多日发现可以使用下面的方式进行对HP服务器监控RAID. 使用nagios监控HP服务器的RAID: 前提本地服务器已经安装好nagios-plugin和nrpe模块,如果没有安装可以搜索一下,相关教程有很多,属于nagios的使用.这里只说一下如何监控raid. 当前使用的操作系统

nagios监控mysql

在nagios上部署check_mysql_health 监控mysql 博客分类: 架构 本监控为基于nagios服务器主动监控方法,利用check_mysql_health实现多种监控模式:       connection-time          (Time to connect to the server)       uptime                   (Time the server is running)       threads-connected      

zabbix-3.2.4监控mysql服务器性能

环境:centos7已安装 zabbix-agent-3.2.4-2.el7.x86_64 zabbix-server-mysql-3.2.4-2.el7.x86_64 zabbix-web-3.2.4-2.el7.noarch zabbix-web-mysql-3.2.4-2.el7.noarch zabbix-release-3.2-1.el7.noarch zabbix-get-3.2.4-2.el7.x86_64 查看zabbix_agentd.conf配置文件: PidFile=/va

Spotlight on MySQL监控MySQL服务器

第一步: 下载并安装mysql-connector-3.5x Spotlight on MySQL 连接mysql必须使用mysql-connector-3.5x,5.3.2版本我试了下不行,有兴趣可以试试 1.下载 官网下载地址 http://dev.mysql.com/downloads/connector/odbc/ mysql-connector-3.5x下载地址 http://yunpan.cn/QiV5FC6QE7cxT  访问密码 78a6 2.安装 一路默认安装. 第二步:下载并

zabbix监控mysql-如何使用zabbix自带的模板监控-nagios监控mysql主从

用zabbix监控mysql(源码安装)安装位置在/usr/local/zabbix/ 监控端(server): 在被监控端主机上关联该模板Template App MySQL 中文:组态->主机->名称一栏点击进去->模板,点击链接新模板->添加->Template App MySQL->存档 英文:Configuration->Hosts->Name->Templates,Link new templates->Add->Templat