Promethus(普罗米修斯)监控Mysql数据库mysql
这个是基于上面环境搭建的,须要的能够访问方面链接查看。linux
教程使用的软件:连接: https://pan.baidu.com/s/1QV4KYZksyIp65UsScioq4Q 提取码: vcejweb
监控远程MySQLsql
服务器 | IP地址 |
Prometneus服务器 | 192.168.116.129 |
被监控服务器(mysql) | 192.168.116.130 |
grafana服务器 | 192.168.116.131 |
① 在被管理机agent1上安装mysqld_exporter组件
下载地址: https://prometheus.io/download/数据库
上传mysqld_exporter组件vim
安装mysqld_exporter组件bash
tar xf mysqld_exporter-0.11.0.linux-amd64.tar.gz -C /usr/local/ mv /usr/local/mysqld_exporter-0.11.0.linux-amd64/ /usr/local/mysqld_exporter ls /usr/local/mysqld_exporter
安装mariadb数据库,并受权服务器
yum install mariadb\* -y systemctl restart mariadb systemctl enable mariadb mysql
MariaDB [(none)]> grant select,replication client,process ON *.* to 'mysql_monitor'@'localhost' identified by '123';
(注意:受权ip为localhost,由于不是prometheus服务器来直接找mariadb 获取数据,而是prometheus服务器找mysql_exporter,mysql_exporter 再找mariadb。因此这个localhost是指的mysql_exporter的IP)ide
MariaDB [(none)]> flush privileges; MariaDB [(none)]> quit
建立一个mariadb配置文件,写上链接的用户名与密码(和上面的受权的用户名 和密码要对应)ui
vim /usr/local/mysqld_exporter/.my.cnf
[client] user=mysql_monitor password=123
启动mysqld_exporter
nohup /usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/.my.cnf &
确认端口(9104)
② 回到prometheus服务器的配置文件里添加被监控的mariadb的配置段
在主配置文件最后再加上下面三行
vim /usr/local/prometheus/prometheus.yml
- job_name: 'mariadb' static_configs: - targets: ['192.168.116.130:9104']
- job_name: 'agent1_mariadb' # 取一个job 名称来表明被监控的mariadb static_configs: - targets: ['10.1.1.14:9104'] # 这里改为 被监控机器的IP,后面端口接9104
改完配置文件后,重启服务
pkill prometheus
/usr/local/prometheus/prometheus --config.file="/usr/local/prometheus/prometheus.yml" &
③ 回到web管理界面 --》点Status --》点Targets --》能够看到监控 mariadb了