Bootstrap

(三)Prometheus监控MySQL服务

目录

         一,部署环境准备

1,mysqld_exporter 组件下载

2,mysql以及mysqld_exporter 组件安装

3,在mysql_exporter中设置mysql配置信息

4,启动mysql_exporter

5,查看端口9104是否起来

二,配置prometheus拉取mysql节点信息

1,在prometheus的server服务端进行修改

2,重启prometheus服务

3,通过web端查看 http://192.168.100.12:9090/

​4,查看mysql数据页   http://192.168.100.13:9104/


上一篇文章(二)Prometheus监控Nginx服务

本篇继续搭建基于——Prometheus监控MySQL服务

一,部署环境准备

Prometheus服务器192.168.100.12
Nginx+MySQL服务器192.168.100.13
grafana 服务器192.168.100.12

1,mysqld_exporter 组件下载

下载地址

https://github.com/prometheus/mysqld_exporter/releases/download/v0.13.0/mysqld_exporter-0.13.0.linux-amd64.tar.gz

2,mysql以及mysqld_exporter 组件安装

#解压安装包
tar zxf mysqld_exporter-0.13.0.linux-amd64.tar.gz

mv mysqld_exporter-0.13.0.linux-amd64 /usr/local/mysql_exporter

#安装mariadb
yum install mariadb\* -y

#启动数据库
systemctl start mariadb
systemctl enable  mariadb

#查看端口
ss -natlp |grep 3306

#进入mysql (mariadb数据库不需要密码)
#在数据库里创建mysql账号用户收集数据
mysql -uroot

MariaDB [(none)]>  grant select,replication client,process ON *.* to 'mysql_monitor'@'localhost' identified by '12345678';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.000 sec)


3,在mysql_exporter中设置mysql配置信息

[root@localhost mysql_exporter]# pwd
/usr/local/mysql_exporter
[root@localhost mysql_exporter]# ls
LICENSE  mysqld_exporter   NOTICE

创建 .my.cnf 文件
[root@localhost mysql_exporter]# cat .my.cnf 
[client]
user=mysql_monitor
password=12345678

4,启动mysql_exporter

[root@localhost mysql_exporter]# nohup ./mysqld_exporter --config.my-cnf=/usr/local/mysql_exporter/.my.cnf &
[1] 1649
[root@localhost mysql_exporter]# nohup: 忽略输入并把输出追加到"nohup.out"

5,查看端口9104是否起来

[root@localhost ~]# netstat -lnptu | grep 9104
tcp6       0      0 :::9104                 :::*                    LISTEN      1649/./mysqld_expor 

二,配置prometheus拉取mysql节点信息

1,在prometheus的server服务端进行修改

vim /usr/local/prometheus/prometheus.yml

  - job_name: 'mysql'
    static_configs:
     - targets: ['192.168.100.13:9104']

2,重启prometheus服务

systemctl daemon-reload 
systemctl restart prometheus.service 
systemctl status prometheus.service 

3,通过web端查看 http://192.168.100.12:9090/

4,查看mysql数据页   http://192.168.100.13:9104/

 Prometheus监控MySQL服务完成

;