当前位置:   article > 正文

Prometheus监控MySQL容器

prometheus mysql容器

操作系统:centos7

1、准备mysql镜像及mysqld_exporter安装包

2、构建镜像

      1)编写Dockerfile
  1. ~]# mkdir -p /data/file
  2. ~]# cd /data/file/
  3. file]# vim Dockerfile
  4. FROM mysql:5.7.21
  5. ADD mysqld_exporter-0.13.0-rc.0.linux-amd64.tar.gz /prometheus-monitor/exporter
  6. ADD my.cnf /prometheus-monitor/exporter/mysqld_exporter-0.13.0-rc.0.linux-amd64/
  7. ADD start.sh /prometheus-monitor/exporter/mysqld_exporter-0.13.0-rc.0.linux-amd64/
  8. RUN chmod +x /prometheus-monitor/exporter/mysqld_exporter-0.13.0-rc.0.linux-amd64/mysqld_exporter
  9. RUN chmod +x /prometheus-monitor/exporter/mysqld_exporter-0.13.0-rc.0.linux-amd64/start.sh
  10. WORKDIR /prometheus-monitor/exporter/mysqld_exporter-0.13.0-rc.0.linux-amd64/
  11. CMD ["/prometheus-monitor/exporter/mysqld_exporter-0.13.0-rc.0.linux-amd64/start.sh"]
  12. expose 9080
      2)准备start.sh脚本
  1. service mysql start
  2. ./mysqld_exporter --config.my-cnf=my.cnf --web.listen-address=:9080
      3)准备my.cnf文件
  1. [client]
  2. host=localhost
  3. user=exporter
  4. password=123123
      4)执行命令构建镜像

# docker build -t mysql_exporter .

3、启动容器并创建exporter用户授权权限

  1. # docker run -itd --name=mysql -p 9080:9080 -e mysql_root_password=123123 mysql_exporter
  2. # docker exec -it mysql bash
  3. root@85f367fbc12f:/prometheus-monitor/exporter/mysqld_exporter-0.13.0-rc.0.linux-amd64# mysql -uroot -p123123
  4. mysql> use mysql;
  5. Reading table information for completion of table and column names
  6. You can turn off this feature to get a quicker startup with -A
  7. Database changed
  8. mysql> create user 'exporter' identified by '123123';
  9. Query OK, 0 rows affected (0.00 sec)
  10. mysql> grant process,replication client,select on *.* to 'exporter'@'%';
  11. Query OK, 0 rows affected (0.00 sec)
  12. mysql> FLUSH PRIVILEGES;
  13. Query OK, 0 rows affected (0.00 sec)
  14. mysql> exit

重启容器

# docker restart mysql

访问:http://192.168.53.7:9080/metrics

通过访问该地址可以看到mysql监控的相关指标

将此监控纳入外部prometheus服务上,并使用grafana进行展示即完成

重启Prometheus服务

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/517359
推荐阅读
相关标签
  

闽ICP备14008679号