Nagios监控mysql
工作原理
利用特定的用户定期访问指定的mysql数据库。当不能访问或连不通时则报警。
配置过程如下
1、 在生产库上安装nagios插件,
以nagios-plugins-1.4.15为例来讲述整个配置过程
进入nagios-plugins-1.4.15 目录
./configure 编译
然后是 编译完显示一定要有mysql支持,不然没有check_mysql这个插件
config.status: creating po/Makefile
--with-apt-get-command:
--with-ping6-command: /bin/ping6-n -U -w %d -c %d %s
--with-ping-command: /bin/ping-n -U -w %d -c %d %s
--with-ipv6: yes
--with-mysql:/usr/bin/mysql_config
--with-openssl: yes
--with-gnutls: no
--enable-extra-opts: no
--with-perl:/usr/bin/perl
--enable-perl-modules: no
--with-cgiurl:/nagios/cgi-bin
--with-trusted-path:/bin:/sbin:/usr/bin:/usr/sbin
--enable-libtap: no
Make all&&make install
插件安装完毕
再安装nrpe 安装过程略同时是编译安装三步曲:./configure make make install
2、 配置mysql
mysql>create database nagios; //建立nagios专用数据
QueryOK, 1 row affected (0.00 sec)
mysql>grant select on nagios.* to nagios@'%' identified by '######'; //建立nagios专用用户权限只给select就OK,给多了不安全。###是密码
QueryOK, 0 rows affected (0.00 sec)
mysql>flush privileges; //刷新权限让数据库接受新的配置
QueryOK, 0 rows affected (0.00 sec)
mysql>select User,Password,Host from user;//查询一下
+--------+-----------------------------------------------------------------------+------------------------------------+
|User | Password | Host |
+--------+-----------------------------------------------------------------------+------------------------------------+
|root |*FD571203974BA9AFE270FE62151AE967ECA5E0AA | localhost |
|root | | localhost.localdomain |
|root | |127.0.0.1 |
| | |localhost |
| | |localhost.localdomain |
|nagios | *34194D8AE12BBBCB89E1755EF0337452C18FF325 | % |
+-----------+-----------------------------------------------------------------------+--------------------------------+
6rows in set (0.00 sec)
用以下命令来验证一下,
[root@localhost/]# /usr/local/nagios/libexec/check_mysql -H 192.168.12.88 -u nagios -d nagios-p 3j5Power
Uptime:3552 Threads: 1 Questions: 56 Slow queries: 0 Opens: 30 Flush tables: 1 Open tables: 23 Queries per second avg: 0.15
[root@localhost /]#
3、 配置nrpe.cfg
[root@localhost/]# vim /usr/local/nagios/etc/nrpe.cfg,加入下面一行
command[check_mysql]=/usr/local/nagios/libexec/check_mysql-H 192.168.12.88 -u nagios -d nagios -p ###### //后面的###代表你设的密码
4、 配置nagios服务端
[root@station1/]# vim /usr/local/nagios/etc/objects/192.168.12.88.cfg //加入如下内容
defineservice{
use generic-service
host_name LDS
service_description check_mysql
check_command check_nrpe!check_mysql
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$'class='tips'rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=$SERVICEDESC$
}
//标蓝的部分是加了图形显示的设置,要是你没配置pnp4nagios这行可注掉
重起nrpe 和服务端的nagios就可以了