Zabbix 添加 MySQL 主机

文章
林里克斯

配置 Zabbix 监控 MySQL .

Zabbix 添加 MySQL 主机


实验平台:CentOS 7.6.1810

zabbix-Server 版本:5.0.2

zabbix-agent 版本:5.0.2

MySQL 版本:5.7



需要安装 mysqlmysqladmin 命令

1.创建监控用户

$ mysql -u root -p
> create user 'zabbix_monitor'@'%' identified by 'zabbix123';
> grant usage,replication client,process,show databases,show view on *.* to 'zabbix_monitor';

2.在 zabbix 配置文件路径下创建 MySQL 模板

$ cd /etc/zabbix/zabbix_agentd.d/
$ vim template_db_mysql.conf

#template_db_mysql.conf created by Zabbix for "Template DB MySQL" and Zabbix 4.2
#For OS Linux: You need create .my.cnf in zabbix-agent home directory (/var/lib/zabbix by default) 
#For OS Windows: You need add PATH to mysql and mysqladmin and create my.cnf in %WINDIR%\my.cnf,C:\my.cnf,BASEDIR\my.cnf https://dev.mysql.com/doc/refman/5.7/en/option-files.html
#The file must have three strings:
#[client]
#user='zbx_monitor'
#password='<password>'
#
UserParameter=mysql.ping[*], mysqladmin -h"$1" -P"$2" ping
UserParameter=mysql.get_status_variables[*], mysql -h"$1" -P"$2" -sNX -e "show global status"
UserParameter=mysql.version[*], mysqladmin -s -h"$1" -P"$2" version
UserParameter=mysql.db.discovery[*], mysql -h"$1" -P"$2" -sN -e "show databases"
UserParameter=mysql.dbsize[*], mysql -h"$1" -P"$2" -sN -e "SELECT COALESCE(SUM(DATA_LENGTH + INDEX_LENGTH),0) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='$3'"
UserParameter=mysql.replication.discovery[*], mysql -h"$1" -P"$2" -sNX -e "show slave status"
UserParameter=mysql.slave_status[*], mysql -h"$1" -P"$2" -sNX -e "show slave status"

3.配置 MySQL 信息

$ mkdir /var/lib/zabbix
$ vim /var/lib/zabbix/.my.cnf

[client]
user=zabbix_monitor
password=zabbix123

4.在 zabbix web 上链接上 MySQL 模板就可以查看监控了

Zabbix 添加 MySQL 主机

5.遇到报错

13633:20200815:135343.160 item "Jblog:mysql.connection_errors_internal.rate" became not supported: Preprocessing failed for: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock...
1. Failed: cannot extract XML value with xpath "/resultset/row[field/text()='Connection_errors_internal']/field[@name='Value']/text()": cannot parse xml value: Start tag expected, '<' not found
noname.xml:1: parser error : Start tag expected, '<' not found
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib

注重这点就可以了
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock...

是因为默认找的 mysql.sock 文件是在路径
没有在 my.cnf 里面定义的话,mysql.sock 默认是在 /tmp/mysql.sock 下面

  • 解决报错
$ vim /var/lib/zabbix/.my.cnf

[client]
user=zabbix_monitor
password=zabbix123
socket=/tmp/mysql.sock

Over~

版权协议须知!

本篇文章来源于 Uambiguous ,如本文章侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意

1195 0 2020-08-15


分享:
icon_mrgreen.gificon_neutral.gificon_twisted.gificon_arrow.gificon_eek.gificon_smile.gificon_confused.gificon_cool.gificon_evil.gificon_biggrin.gificon_idea.gificon_redface.gificon_razz.gificon_rolleyes.gificon_wink.gificon_cry.gificon_surprised.gificon_lol.gificon_mad.gificon_sad.gificon_exclaim.gificon_question.gif
博主卡片
林里克斯 博主大人
一个致力于Linux的运维平台
运维时间
搭建这个平台,只为分享及记载自己所遇之事和难题。

现在时间 2024-04-19

今日天气
站点统计
  • 文章总数:240篇
  • 分类总数:29个
  • 评论总数:10条
  • 本站总访问量 213868 次

@奥奥

@Wong arrhenius 牛比

@MakerFace 厉害了!