监控mysql应用

mysql exporter负责采集mysql指标数据,通过http暴露给prometheus

可采用二进制方式部署或者容器化部署

原理一样,都是通过访问登录mysql来得到相关信息

下载mysql的源

wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

rpm -ivh mysql80-community-release-el7-3.noarch.rpm

安装好后可以再/etc/yum.repos.d/ 目录下看到安装的yum源

添加key

rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

yum install mysql-community-server

如果还不行则可以添加--nogpgcheck 跳过检查key参数

yum install mysql-community-server --nogpgcheck

启动mysql

systemctl start mysqld

查看mysql状态

systemctl status mysqld

默认密码:123456

新建exporter用户并授权

下载安装mysql_exporter

https://github.com/prometheus/mysqld_exporter/releases

选择linux amd64版本的

 

编辑mysqld_exporter配置文件

[client]

user = exporter

password = 123456

 

整合到prometheus target上

vim mysql_exporter.service

[Unit]

Description=mysqld_exporter service

After=network-online.target

 

[Service]

Type=simple

ExecStart=/usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/mysqld_exporter.cnf

Restart=on-failue

ExecStop=/bin/kill -9 $MAINPID

 

[Install]

WantedBy=multi-user.target

 

mv mysqld_exporter.service /usr/lib/systemd/system

启动mysql_exporter

systemctl start mysqld_exporter.service

查看mysql_exporter状态

systemctl status mysqld_exporter.service

 

vim /usr/local/prometheus/prometheus.yml

  - job_name: "mysql_exporter"

    static_configs:

      - targets: ["192.168.242.134:9104"]

posted @ 2024-03-05 15:40  ~技术小白  阅读(0)  评论(0编辑  收藏  举报