您好,欢迎访问一九零五行业门户网

Nagios监控mysql服务器详细实现过程_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用户[root@localhost ~]# useradd -s/sbin/nologin nagios
3.2,安装nagios插件[root@localhost ~]# yum -yinstall gcc gcc-c++ make openssl openssl-devel
3.3,安装nrpetar -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'
[root@localhost ~]# 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='nagiosq@0625' -d test -w 60 -c 100
[root@localhost ~]#
3.5,启动nrpe/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe
4,制作启动脚本:[root@localhost 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
[root@localhost bin]#
5,设置启动chmod +x /etc/init.d/nrped
chkconfig --add nrped
chkconfig nrped on
[root@localhost 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
[root@localhost bin]#
[root@localhost 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
[root@localhost bin]#
6,监控端安装nrpetar 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的插件,如下所示:
[root@test_db2 nagios]# ll /usr/local/nagios/libexec/check_nrpe
-rwxrwxr-x 1 nagios nagios 76777 jun 2523:53 /usr/local/nagios/libexec/check_nrpe
[root@test_db2 nagios]#
检测报错:
[root@test_db2 libexec]# ./check_nrpe -h192.168.121.210
check_nrpe: error - could not complete sslhandshake.
[root@test_db2 libexec]#
去客户端在allowed_hosts中添加监控端ip地址
[root@localhost ~]# vim/usr/local/nagios/etc/nrpe.cfg
allowed_hosts=127.0.0.1,192.168.121.211
在mysql服务器上,报错:
[root@localhost ~]#/usr/local/nagios/libexec/check_mysql -unagios -p3306 -s -s/usr/local/mysql/mysql.sock -hlocalhost --password='nagiosq@0512' -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
[root@localhost ~]#
[root@localhost ~]# 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
[root@localhost ~]# ln -s/usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18
[root@localhost ~]#
添加mysql账号:
mysql> grant process, super, replicationclient on *.* to 'nagios'@'localhost' identified by 'nagiosq@0625';
query ok, 0 rows affected (0.05 sec)
mysql>
客户端自己检测:
[root@localhost ~]#/usr/local/nagios/libexec/check_mysql -unagios -p3306 -s /usr/local/mysql/mysql.sock -hlocalhost--password='nagiosq@0625' -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;;;
[root@localhost ~]#
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等服务监控项。[root@test_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才能生效,如下所示:
[root@test_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
[root@test_db2 nagios]#
8,之后在页面就可以看到监控效果了
其它类似信息

推荐信息