【问题标题】:How to monitor databases from a distant server?如何从远程服务器监控数据库?
【发布时间】:2018-05-03 13:43:03
【问题描述】:

我在服务器(Ubuntu 16.04)上安装了 Zabbix,以监控其他服务器的性能。我可以看到它的 CPU 使用率、内存使用率等。

但是,该服务器(Ubuntu 16.04)还包含一个数据库,我也想监控它的性能(每分钟的查询数、执行时间等)。我还没有找到如何使用 Zabbix 来做到这一点。

有人可以指导我如何做到这一点吗?如果 Zabbix 做不到,还有其他工具可以监控远程数据库吗?

非常感谢。

【问题讨论】:

标签: mysql monitoring zabbix


【解决方案1】:

Zabbix 由两个组件组成

  1. 存储所有收集的数据、处理和触发触发器的 Zabbix 服务器
  2. Zabbix Agent 可以安装在大多数操作系统上,允许从系统中收集深度数据。然后,Agent 将收集到的数据发送回 Zabbix 服务器

因此,在您的情况下,最好在数据库服务器上安装 zabbix 代理,然后使用 zabbix 中包含的 mysql 监控工具。 这样您就不必允许网络访问您的 mysql 服务器。

最常见的问题是,您需要一个名为 zabbix(或您在配置文件中定义的用户)的数据库用户,该用户对 mysql 的统计信息具有读取权限。

这里创建mysql用户并分配权限

root@web01:~# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.17-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2016, 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> create user 'zabbix_admin'@'localhost' IDENTIFIED BY 'Password';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT USAGE ON *.* TO 'zabbix_admin'@'localhost' IDENTIFIED BY 'Password';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

然后在 zabbix config 文件夹中指定登录信息

root@web01:~# vi /etc/zabbix/.my.cnf
#
[mysql]
user=zabbix_admin
password=Password
[mysqladmin]
user=zabbix_admin
password=Password

然后在/etc/zabbix/zabbix_agentd.conf.d/userparameter_mysql.conf 文件中指定要监控的内容(取自模板) 这里还有一些额外的指针:

【讨论】: