Nagios使用check_mysql监控mysql
Nagios监控服务器:192.168.9.172
mysql服务器:192.168.9.145
1. 建立测试用的数据库nagios,并给权限
[root@mysqltest1 ~]# mysql -uroot -p123456
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 288
Server version: 5.1.73-community-log MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
mysql> create database nagios;
Query OK, 1 row affected (0.02 sec)
mysql> grant select on nagios.* to nagios
-> @'%' identified by '123456';
Query OK, 0 rows affected (0.29 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.22 sec)
mysql>
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select user, password, host from user;
+-------------+-------------------------------------------+---------------+
| user | password | host |
+-------------+-------------------------------------------+---------------+
| root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | localhost |
| root | | mysqltest1 |
| root | *4A82FDF1D80BA7470BA2E17FEEFD5A53D5D3B762 | 127.0.0.1 |
| | | localhost |
| | | mysqltest1 |
| replication | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | 192.168.9.146 |
| nagios | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | % |
+-------------+-------------------------------------------+---------------+
7 rows in set (0.01 sec)
mysql>
mysql>
mysql>
2. nagios监控服务器命令测试:
[root@nagios libexec]# mysql -uroot -p123456
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
[root@nagios libexec]# cd /var/lib/mysql/
[root@nagios mysql]# ll
总用量 28784
drwx------. 2 mysql mysql 12288 9月 9 23:21 cacti
drwx------. 2 mysql mysql 20480 9月 9 23:22 centreon
drwx------. 2 mysql mysql 12288 9月 9 23:22 centreon_status
drwx------. 2 mysql mysql 4096 9月 18 15:28 centreon_storage
-rw-rw----. 1 mysql mysql 18874368 11月 10 15:08 ibdata1
-rw-rw----. 1 mysql mysql 5242880 11月 10 15:08 ib_logfile0
-rw-rw----. 1 mysql mysql 5242880 11月 10 15:08 ib_logfile1
drwx------. 2 mysql mysql 4096 9月 9 23:21 mysql
srwxrwxrwx 1 mysql mysql 0 9月 24 14:56 mysql.sock
drwx------. 2 mysql mysql 4096 11月 10 00:00 syslog
drwx------. 2 mysql mysql 4096 9月 9 23:21 test
-rwxrwxrwx 1 root root 49848 9月 22 16:52 tuning-primmer.sh
[root@nagios mysql]# pwd
/var/lib/mysql
[root@nagios tmp]# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
[root@nagios tmp]# ll
总用量 4
lrwxrwxrwx 1 root root 25 11月 10 15:09 mysql.sock -> /var/lib/mysql/mysql.sock
-rw-r--r-- 1 root root 81 11月 10 08:03 ntp.log
[root@nagios tmp]# ll
总用量 4
lrwxrwxrwx 1 root root 25 11月 10 15:09 mysql.sock -> /var/lib/mysql/mysql.sock
-rw-r--r-- 1 root root 81 11月 10 08:03 ntp.log
[root@nagios tmp]# mysql -uroot -p123456
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9907711
Server version: 5.1.66 Source distribution
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> exit
Bye
#测试可连接到测试数据库192.168.9.145
[root@nagios tmp]# mysql -h 192.168.9.145 -unagios -p123456
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 289
Server version: 5.1.73-community-log MySQL Community Server (GPL)
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| nagios |
| test |
+--------------------+
3 rows in set (0.03 sec)
mysql>
mysql>
mysql> exit
Bye
You have new mail in /var/spool/mail/root
3.使用测试,及返回结果:
[root@nagios tmp]# /usr/local/nagios/libexec/check_mysql -H 192.168.9.145 -u nagios -d nagios -p 123456
Uptime: 953443 Threads: 3 Questions: 1480 Slow queries: 0 Opens: 52 Flush tables: 1 Open tables: 28 Queries per second avg: 0.1
[root@nagios tmp]#
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29500582/viewspace-1327449/,如需转载,请注明出处,否则将追究法律责任。