Zabbix 添加 MySQL 主机
配置 Zabbix
监控 MySQL
.
实验平台:CentOS 7.6.1810
zabbix-Server 版本:5.0.2
zabbix-agent 版本:5.0.2
MySQL 版本:5.7
需要安装 mysql
和 mysqladmin
命令
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
模板就可以查看监控了
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 ,如本文章侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意
1843 0 2020-08-15
博主卡片
运维时间
搭建这个平台,只为分享及记载自己所遇之事和难题。
现在时间 2025-01-18
今日天气
随机推荐
站点统计
- 文章总数:241篇
- 分类总数:29个
- 评论总数:14条
- 本站总访问量 365418 次
@svmuvwpuqi 真棒!
@smdxydrauu 博主太厉害了!
@xiaozi 最后的分享的镜像下载地址打不开 服务器没有开机吗?
@yuanyuan 为什么我的4b安装centos7.9 插上tf卡 显示不兼...
@Wong arrhenius 牛比
@MakerFace 厉害了!
@TongSir 老哥 更新下我的友链链接 https://blog.ton...