设置一个 MySql/MariaDB 监控用户:
jack@onitroad:~# 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, 2014, 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
环境:
- 主机名 = db01.onitroad.com
- IP 地址 = 192.168.1.50
- 操作系统 = Ubuntu 16.04 LTS
配置 Zabbix 代理
要监控MySql/MariaDB,我们必须在/etc/zabbix/zabbix_agentd.conf.d中创建一个名为userparameter_mysql.conf的文件,它会用于收集数据:
jack@onitroad:~# vi /etc/zabbix/zabbix_agentd.conf.d/userparameter_mysql.conf
添加此行
# For all the following commands HOME should be set to the directory that has .my.cnf file with password information. ## Flexible parameter to grab global variables. On the frontend side, use keys like mysql.status[Com_insert]. # Key syntax is mysql.status[variable]. UserParameter=mysql.status[*],echo "show global status where Variable_name='';" | HOME=/etc/zabbix mysql -N | awk '{print $}' # My line ## Flexible parameter to determine database or table size. On the frontend side, use keys like mysql.size[zabbix,history,data]. # Key syntax is mysql.size[<database>,<table>,<type>]. # Database may be a database name or "all". Default is "all". # Table may be a table name or "all". Default is "all". # Type may be "data", "index", "free" or "both". Both is a sum of data and index. Default is "both". # Database is mandatory if a table is specified. Type may be specified always. # Returns value in bytes. # 'sum' on data_length or index_length alone needed when we are getting this information for whole database instead of a single table UserParameter=mysql.size[*],echo "select sum($(case "" in both|"") echo "data_length+index_length";; data|index) echo "_length";; free) echo "data_free";; esac)) from information_schema.tables$([[$ ##Default below UserParameter=mysql.ping,HOME=/etc/zabbix mysqladmin ping | grep -c alive ##My line UserParameter=mysql.uptime,HOME=/etc/zabbix mysqladmin status | cut -f2 -d ":" | cut -f1 -d "T" | tr -d " " UserParameter=mysql.threads,HOME=/etc/zabbix mysqladmin status | cut -f3 -d ":" | cut -f1 -d "Q" | tr -d " " UserParameter=mysql.questions,HOME=/etc/zabbix mysqladmin status | cut -f4 -d ":"|cut -f1 -d "S" | tr -d " " UserParameter=mysql.slowqueries,HOME=/etc/zabbix mysqladmin status | cut -f5 -d ":" | cut -f1 -d "O" | tr -d " " UserParameter=mysql.qps,HOME=/etc/zabbix mysqladmin status | cut -f9 -d ":" | tr -d " " UserParameter=mysql.version,mysql -V
接下来,我们需要向 Zabbix 提供新用户的登录信息。
在 /etc/zabbix 中创建一个名为 .my.cnf 的文件并用以下几行填充它:
jack@onitroad:~# vi /etc/zabbix/.my.cnf #[mysql] user=zabbix_admin password=Password [mysqladmin] user=zabbix_admin password=Password
使用以下命令重启 zabbix 代理服务:
jack@onitroad:~# systemctl restart zabbix-agent
最后,我们可以通过选择 MySQL 服务器模板在 Zabbix 服务器中设置主机,我们将开始获取数据流并触发有关数据库服务器状态的触发器。
在我们在 Ubuntu 16.04 LTS 上安装 Zabbix Server 之后。
本文将演示如何使用zabbix agent通过收集查询、慢查询、服务器状态、服务器正常运行时间等数据来监控MySql/Mariadb数据库服务器...
日期:2020-06-02 22:19:01 来源:oir作者:oir