前言



由于近期某个同事部署这prometheus的监控mysql的组件的时候,出现了一个没见过的报错,刚好有时间就写一下。



mysqld_exporter的部署



数据库授权



需要一个账号对数据库进行查询,所以必须去监控的数据库中授权
用户和密码随意

CREATE USER 'exporter'@'localhost' IDENTIFIED BY 'expoter12Ssdc3' WITH MAX_USER_CONNECTIONS 3;
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost';orGRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost' IDENTIFIED BY 'expoter12Ssdc3' WITH MAX_USER_CONNECTIONS 3;


mysqld_exporter安装



<1>下载mysqld_exporter
#https://github.com/prometheus/mysqld_exporter/releases

cd /data
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz
tar xf mysqld_exporter-0.12.1.linux-amd64.tar.gz
mv mysqld_exporter-0.12.1.linux-amd64 mysqld_exporter


<2>配置用于监控的配置文件
mysqld_exporter会读取该配置文件中的账号密码用于监控

cd /data/mysqld_exporter
cat .my.cnf[client]
host = 127.0.0.1
user = exporter
password = expoter12Ssdc3
socket = /tmp/mysql_3306.sock
[mysqladmin]
host = 127.0.0.1
user = exporter
password = expoter12Ssdc3
socket = /tmp/mysql_3306.sock


配置完,测试一下使用该配置文件中的账号密码socket是否可登陆

mysql -uexporter -p'expoter12Ssdc3' -S /tmp/mysql_3306.sock


<3>配置启动方式

根据系统版本配置启动方式,暂时不需要启动

Centos7# cat /usr/lib/systemd/system/mysqld-exporter.service
[Unit]
Description=mysqld_exporter[Service]
ExecStart=/data/mysqld_exporter/mysqld_exporter --config.my-cnf /data/mysqld_exporter/.my.cnf --web.listen-address=0.0.0.0:9104 \
--collect.slave_status \
--collect.binlog_size \
--collect.info_schema.processlist \
--collect.info_schema.innodb_metrics \
--collect.engine_innodb_status \
--collect.perf_schema.file_events \
--collect.perf_schema.replication_group_member_stats
Restart=on-failure[Install]
WantedBy=multi-user.target管理方式:
systemctl daemon-reload
systemctl enable mysqld-exporter
systemctl restart mysqld-exporter
systemctl status mysqld-exporter
systemctl stop mysqld-exporter
Centos6cat /etc/init.d/mysqld_exporter
#!/bin/bash# chkconfig: 2345 80 80
# description: Start and Stop mysqld_exporter
# Source function library.. /etc/init.d/functionsprog_name="mysqld_exporter"
prog_path="/data/mysqld_exporter/mysqld_exporter"
pidfile="/var/run/mysqld_exporter.pid"
prog_logs="/data/mysqld_exporter/mysqld_exporter.log"
options="--config.my-cnf=/data/mysqld_exporter/.my.cnf --web.listen-address=0.0.0.0:9104 --collect.slave_status --collect.binlog_size --collect.info_schema.processlist --collect.info_schema.innodb_metrics --collect.engine_innodb_status --collect.perf_schema.file_events --collect.perf_schema.replication_group_member_stats"
DESC="mysqld_exporter"[ -x "${prog_path}" ] || exit 1RETVAL=0start(){action $"Starting $DESC..." su -s /bin/sh -c "nohup $prog_path $options >> $prog_logs 2>&1 &" 2> /dev/null
RETVAL=$?
PID=$(pidof ${prog_path})
[ ! -z "${PID}" ] && echo ${PID} > ${pidfile}
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog_name
return $RETVAL
}stop(){echo -n $"Shutting down $prog_name: "
killproc -p ${pidfile}
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog_name
return $RETVAL
}restart() {stop
start
}case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status $prog_path
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
RETVAL=1
esac------------------------------------------------------------
cat  /etc/sysconfig/mysqld_exporter
ARGS=""------------------------------------------------------------
管理方式:
chmod +x /etc/init.d/mysqld_exporter
chkconfig mysqld_exporter on
/etc/init.d/mysqld_exporter restart


<4>mysqld_exporter监控多个数据库

可以根据配置文件分开监控,日志也分开

例如:一台服务器有多个数据库3306 3307

拷贝2个mysqld_exporter安装包
cp -r mysqld_exporter-0.12.1.linux-amd64 mysqld_exporter_3306
cp -r mysqld_exporter-0.12.1.linux-amd64 mysqld_exporter_3307修改监控文件为对应的库的配置
cd  /data/mysqld_exporter_3307
cat .my.cnf
[client]
host = 127.0.0.1
user = exporter
password = expoter12Ssdc3
socket = /tmp/mysql_3307.sock
[mysqladmin]
host = 127.0.0.1
user = exporter
password = expoter12Ssdc3
socket = /tmp/mysql_3307.sock修改启动文件也根据情况修改



mysqld_exporter常见报错



报错类型



权限

<1> level=error msg=“Error pinging mysqld: Error 1045: Access denied for user ‘root’@‘localhost’ (using password: YES)” source=“exporter.go:146”

如上报错,是授权问题,数据库中记得授权,并且查看mysqld_exporter下的my.cnf中的配置



socket

<2>level=error msg=“Error pinging mysqld: dial unix /tmp/mysql_3306.sock: connect: no such file or directory” source=“exporter.go:146”

如上报错,和明显是socket问题,修改my.cnf中的socket为正确的



DSN

<3>level=error msg=“Error pinging mysqld: this user requires old password authentication. If you still want to use it, please add ‘allowOldPasswords=1’ to your DSN. See also https://github.com/go-sql-driver/mysql/wiki/old_passwords” source=“exporter.go:146”

见于老数据库,是由于old_paswords参数导致,这个文档实际主要是这个问题。当前服务不支持密码的简单散列。

old_passwords,这个参数是mysql为了兼容4.1之前的客户端而保留的。开启这个old_passwords参数后,添加用户时生成的密码是以16位加密的方式存储的,而4.1之后的客户端都是采用64位加密方式存储的,所以通常情况下这个参数默认关闭的 old_passwords=0 ,即 old_passwords OFF,意思是不用16位加密,而是加密成64位
“https://github.com/go-sql-driver/mysql#allowoldpasswords”

1、按照官方提示你需要去你的mysql数据库设置old_passwords=0,不采用16位的加密,不管你是临时设置还是修改配置文件并重启,当执行后,所有用户的密码都会变成64位加密,即41个字节。

show variables like '%password%';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| old_passwords   | OFF   |
| report_password |       |
+-----------------+-------+
2 rows in set (0.00 sec)SET SESSION old_passwords=0;show variables like '%password%';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| old_passwords   | ON    |
| report_password |       |
+-----------------+-------+
2 rows in set (0.00 sec)重新设置密码
SET PASSWORD FOR 'user'@'localhost' = PASSWORD('fiuurw65d7u');SET GLOBAL old_passwords=0;


2、但是上面存在一个问题。当这个服务很老,你不清楚为什么使用这个,是前人不小心还是业务有需求设置的这个参数?修改或重启数据库时候是否会导致业务异常?所以我们需要一个不对数据库进行修改的方法。

在启动时候设置DSN的环境变量来启动,可以直接在外面使用也可以写到启动文件中

格式:

DATA_SOURCE_NAME=用户名:密码@unix\(Sock)/?参数=值&参数=值
or
DATA_SOURCE_NAME=用户名:密码@(ip地址:端口)/?参数=值&参数=值DATA_SOURCE_NAME=exporter:expoter12Ssdc3@unix\(/tmp/mysql_3306.sock\)/?allowOldPasswords=true
Centos7
# cat /usr/lib/systemd/system/mysqld-exporter.service
[Unit]
Description=mysqld_exporter[Service]
Environment="DATA_SOURCE_NAME=exporter:expoter12Ssdc3@unix\(/tmp/mysql_3306.sock\)/?allowOldPasswords=true"
ExecStart=/data/mysqld_exporter/mysqld_exporter --config.my-cnf /data/mysqld_exporter/.my.cnf --web.listen-address=0.0.0.0:9104 \
--collect.slave_status \
--collect.binlog_size \
--collect.info_schema.processlist \
--collect.info_schema.innodb_metrics \
--collect.engine_innodb_status \
--collect.perf_schema.file_events \
--collect.perf_schema.replication_group_member_stats
Restart=on-failure
等等
Centos6cat /etc/init.d/mysqld_exporter#!/bin/bash# chkconfig: 2345 80 80
# description: Start and Stop mysqld_exporter
# Source function library.. /etc/init.d/functionsexport DATA_SOURCE_NAME=exporter:'expoter12Ssdc3'@unix\(/tmp/mysql_3306.sock\)/?allowOldPasswords=true
prog_name="mysqld_exporter"
等等


补充:

go连接数据库是通过DSN数据源,.my.cnf只是一个用于从其中读取部分参数的文件,但是有部分选项是不能通过文件中获取的,所以allowoldpasswords等参数配置到mysqld_exporter的my.cnf中是不识别的,需要以DSN环境变量来启用某些功能或配置

这个设置常见于很老的服务,如果老版本打开了old_passwords选项,迁移或复制后的mysql也要打开old_password 或者 对密码rehash,生成新的hash密码长度(40个16进制字符,然后在前面再加一个*,41字节)



不兼容参数

<4>level=error msg=“Error scraping for collect.perf_schema.replication_group_member_stats: Error 1146: Table ‘performance_schema.replication_group_member_stats’ doesn’t exist” source=“exporter.go:171”

该数据库版本不兼容该参数,此报警忽略或删除启动文件中这个参数

#收集器参数
#参数名 MySQL版本  作用
#collect.auto_increment.columns                 5.1 自增列最大值
#collect.binlog_size                            5.1 binlog文件大小
#collect.engine_innodb_status                   5.1 从SHOW ENGINE INNODB STATUS 命令收集
#collect.engine_tokudb_status                   5.6 从SHOW ENGINE TOKUDB STATUS 命令收集 .
#collect.global_status                          5.1 从SHOW GLOBAL STATUS命令收集 (默认可用)
#collect.global_variables                       5.1 从SHOW GLOBAL VARIABLES命令收集 (默认可用)
#collect.info_schema.clientstats                5.5 如果使用userstat=1运行,则设置为true以收集客户端统计信息。
#collect.info_schema.innodb_metrics             5.6 收集information_schema.innodb_metrics 指标.
#collect.info_schema.innodb_tablespaces         5.7 收集information_schema.innodb_sys_tablespaces 指标.
#collect.info_schema.innodb_cmp                 5.5 收集information_schema.innodb_cmp中的innoDB压缩表指标
#collect.info_schema.innodb_cmpmem              5.5 收集information_schema.innodb_cmpmem中InnoDB 缓冲池指标 .
#collect.info_schema.processlist                5.1 收集 information_schema.processlist中的线程状态
#collect.info_schema.processlist.min_time       5.1 线程在每个状态的最小时间. (默认: 0)
#collect.info_schema.query_response_time        5.5 如果query_response_time_stats 设置的 ON,则收集查询响应时间.
#collect.info_schema.tables                     5.1 收集information_schema.tables中的指标 (默认开启)
#collect.info_schema.tables.databases           5.1 为所有数据库收集表统计信息.
#collect.info_schema.tablestats                 5.1 如果tablestats=1, 收集数据表统计数据.
#collect.info_schema.userstats                  5.1 如果userstat=1, 收集用户统计数据.
#collect.perf_schema.eventsstatements           5.6 收集performance_schema.events_statements_summary_by_digest中的指标.
#collect.perf_schema.eventsstatements.digest_text_limit 5.6 标准语句的最大长度. (默认: 120)
#collect.perf_schema.eventsstatements.limit     5.6 根据响应时间限制语句的事件数量. (默认: 250)
#collect.perf_schema.eventsstatements.timelimit 5.6 限制最后出现的事件事件. 单位:秒(默认: 86400)
#collect.perf_schema.eventswaits                5.5 收集performance_schema.events_waits_summary_global_by_event_name中的指标.
#collect.perf_schema.file_events                5.6 收集performance_schema.file_summary_by_event_name中的指标.
#collect.perf_schema.file_instances             5.5 收集performance_schema.file_summary_by_instance中的指标.
#collect.perf_schema.indexiowaits               5.6 收集performance_schema.table_io_waits_summary_by_index_usage中的指标.
#collect.perf_schema.tableiowaits               5.6 收集performance_schema.table_io_waits_summary_by_table中的指标.
#collect.perf_schema.tablelocks                 5.6 收集performance_schema.table_lock_waits_summary_by_table中的指标.
#collect.perf_schema.replication_group_member_stats 5.7 收集performance_schema.replication_group_member_stats中的指标.
#collect.slave_status                           5.1 收集SHOW SLAVE STATUS (默认可用)
#collect.slave_hosts                            5.1 收集SHOW SLAVE HOSTS信息
#collect.heartbeat                              5.1 收集数据库实例心跳
#collect.heartbeat.database                     5.1 收集某数据库心跳. (默认 heartbeat)
#collect.heartbeat.table                        5.1 收集某表的心跳. (默认 heartbeat)



Grafana不出图



版本不兼容



关于这个问题不只出现在这个组件中。实际上在部署各种服务中,常见因版本问题导致的异常。
例如:你在grafana中导入一个几年前的监控模板,而你的组件使用的是最新的或者近期的版本,通常每一版本的软件都会对一些配置或参数进行优化调整,时间越久与老版本的差别越大,这就导致了新软件获取的数据在老模板上不一定适用。这时需要降低组件版本,最好是与老模板同年的组件版本。
所以不要什么软件都直接使用最新的,如果是根据某篇文档进行配置,最好版本和文档中不要差太多。



启动问题

启动后,不仅要看端口是否up,还需要看一下启动日志是否报错,通过接口是否可获得数据。



Mysqld_exporter部署及常见的几种错误相关推荐

  1. mysql 3种报错_MySQL读取Binlog日志常见的3种错误-阿里云开发者社区

    MySQL读取Binlog日志常见的3种错误 mysqlbinlog: [ERROR] unknown variable 'default-character-set=utf8mb4' 当我们在my. ...

  2. python中常见的几种错误

    python中常见的几种错误: 1.end前面一定加逗号 2.命令输入错误 3.冒号中英文切换 4.命令缩进错误 5.等于号要双等于,否则一个等于号是赋值 6.命令之间正确搭配

  3. 大数据可视化常见的三种错误

    可视化是获取并分享观点的绝佳途径,但很多大数据团队却没能选对正确的方式.可视化怎么会出现问题?原因很简单,因为存在多种可能破坏数据可视化效果的实施方式.下面我们就一同来探讨最为常见的三种错误实践. 错 ...

  4. c语言数组常见错误,C语言数组在使用中常见的几种错误.pdf

    S C i 卜NOL & TE Q 月N创,)<白Y INI: 口书明A T I仁别 T 技 术 C 语言数组在使用 中常见 的几种错误 刘莉娜 (包头农牧学校 0 14030) 摘 要 ...

  5. 95码号、106码号申请时常见的几种错误

    每天,我们都能收到不少短信,来自银行的通知.物流的提醒.商家店铺的促销.发送的号码,一开始是常见的手机号码,慢慢的越来越多地变成106开头或95开头的号码.这类码号具有较高的含金量和良好的识别率,也是 ...

  6. golang-文章翻译-go常见的10种错误

    文章目录 一.枚举默认值和json反序列化 二.BenchMarking和内联 三.每次传参都应该用指针吗? 四.break和条件控制语句 五.错误管理 六.数组初始化 6.1 len 和 cap 6 ...

  7. Elasticsearch 常见的 8 种错误及最佳实践

    题记 Elasticsearch 社区有大量关于 Elasticsearch 错误和异常的问题. 深挖这些错误背后的原因,把常见的错误积累为自己的实战经验甚至是工具,不仅可以节省我们的开发和运维时间, ...

  8. 【转】WebAPI ASP.Net 发布部署中常见的两个错误未能找到 CodeDom未能加载System.Web.WebPages.Razor

    未能加载文件或程序集"System.Web.WebPages.Razor, Version=3.0.0.0, Culture=ne 未能找到 CodeDom 提供程序类型"Micr ...

  9. 404常见的几种错误原因

    1.       访问项目,但是项目没有部署到tomcat服务器.报404,重新部署项目 2.       在浏览器地址栏路径输入错误(比如中文空格), 只要将路径修改正确就行了 3.       拷 ...

最新文章

  1. 深入理解 wpa_supplicant(二)
  2. SpringBoot跨域
  3. 使用rel=noopener
  4. HDU 2055 An easy problem
  5. 使用requests请求网页时,返回的页面信息有时是乱码,如下代码
  6. ab压力测试工具linux,【Linux】ApacheBench(ab)压力测试工具
  7. 第五十七期:小型企业将如何从5G中受益
  8. java中怎么获取配置文件的值_java如何获取配置文件的值
  9. LeetCode刷题(26)
  10. python发音语言-python 利用pyttsx3文字转语音过程详解
  11. yum文件,来自网络
  12. Qt开发之路——SogouInput\Components\ Error - RtlWerpReportException failed with status code :-107374182
  13. 计算机教学能力大赛实施报告模板,“现代信息技术在课堂教学中的运用”实施情况总结...
  14. 散列表的概念及其拉链法和常见的散列函数(C语言)
  15. Java视频教程,最新全套Java教程!
  16. 用Unity做游戏,你需要深入了解一下IL2CPP
  17. redis之十五(游标迭代器(过滤器)——Scan)
  18. JS学习之BOM | 常见网页特效 | 轮播图 | 返回顶部 | 筋斗云案例
  19. rabbitmq高级特性(消息手动确认)
  20. Linux mysql服务(重启,启动,停止)

热门文章

  1. Eclipse怎么汉化?(附汉化包下载链接版)
  2. react 单元测试 (jest+enzyme)
  3. 粒子群算法及其matlab实现
  4. 微服务的理解 —— 江湖往事
  5. 2006年中国自动识别技术协会工作总结
  6. css background-size:contain与cover的区别
  7. java中简单的快速排序_【新手自白书】简单快速排序的实现(JAVA)
  8. linux 非root用户mount,linux – 选项“user”适用于mount,而不适用于umount
  9. 2D游戏神器-RuleTile
  10. ie—5WHY分析法