Nagios使用check_mysql監控mysql
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]#
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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 使用Nagios打造專業的業務狀態監控iOS
- Nagios+Centreon監控系統簡介iOS
- Cacti+Nagios監控平臺完美整合iOS
- 監控系統:深度對比Zabbix、Nagios、Pandora FMSiOS
- 使用Zabbix + Python對Mysql監控PythonMySql
- MySQL監控工具MySql
- zabbix、cacti、nagios,伺服器監控還有更好的選擇嗎?iOS伺服器
- Java後端分散式系統的服務監控:Zabbix與NagiosJava後端分散式iOS
- 【DB寶41】監控利器PMM的使用--監控MySQL、PG、MongoDB、ProxySQL等MySqlMongoDB
- TenSunS監控Mysql:如何優雅的使用一個mysqld_exporter監控所有的MySQL例項MySqlExport
- mytop 使用介紹 mysql實時監控工具MySql
- MySQL sys效能監控MySql
- MySQL監控-Datadog資料庫監控調研MySql資料庫
- 使用夜鶯和 Categraf 快速建設 MySQL 監控MySql
- MySQL調優使用者監控之show processlistMySql
- 手把手教你使用 Prometheus 監控 MySQL 與 MariaPrometheusMySql
- Mysql事件監控日誌MySql事件
- mysql效能監控相關MySql
- 搭建Lepus 天兔 監控MySQLMySql
- Prometheus MySQL監控+grafana展示PrometheusMySqlGrafana
- 使用Admin監控
- 【Zabbix】使用zabbix 3.4自帶Mysql模板,監控Redhat 7.0上的MysqlMySqlRedhat
- Mysql效能監控視覺化MySql視覺化
- SpringBoot使用prometheus監控Spring BootPrometheus
- 使用Prometheus監控FlinkPrometheus
- 04、MySQL Case-MySQL常用監控指標MySql指標
- 手把手教你使用 Prometheus 監控 MySQL 與 MariaDB.mdPrometheusMySql
- Grafana+Prometheus 監控 MySql服務GrafanaPrometheusMySql
- MYSQL和SQLServer效能監控指標MySqlServer指標
- MySQL MHA 執行狀態監控MySql
- MYSQL最樸素的監控方式MySql
- shell監控mysql 8.0資料庫MySql資料庫
- shell監控mysql 5.7資料庫MySql資料庫
- Java 監控基礎 - 使用 JMX 監控和管理 Java 程式Java
- upptime:使用GitHub Actions監控你的網站健康監控Github網站
- 【Zabbix】使用dbforbbix 2.2-beta監控Redhat 7.0上的Oracle、MysqlORBRedhatOracleMySql
- 【DB寶39】使用Docker分分鐘搭建Zabbix 5.0配置MySQL監控DockerMySql
- 使用Splunk監控SAP Dump
- 監控索引的使用(轉)索引