# 安装数据库
[root@node1 ~]# yum install -y mariadb-server
# 启动服务
[root@node1 ~]# systemctl enable mariadb --now
# 进入数据库
[root@node1 ~]# mysql
# 创建用户jerry,密码是123
MariaDB [(none)]> grant all on *.* to jerry@'localhost' identified by '123';
# 退出
MariaDB [(none)]> exit
# 解压mysqld_exporter软件包
[root@node1 ~]# tar xf mysqld_exporter-0.12.1.linux-amd64.tar.gz
# 复制到local目录下
[root@node1 ~]# mv mysqld_exporter-0.12.1.linux-amd64 /usr/local
/mysqld_exporter
# 创建.my.cnf
[root@node1 ~]# vim /usr/local/mysqld_exporter/.my.cnf
[client]
host=127.0.0.1
port=3306
user=jerry
password=123
# 创建service文件
[root@node1 ~]# vim /usr/lib/systemd/system/mysqld_exporter.service
[Unit]
Description=mysqld_exporter
After=network.target
[Service]
ExecStart=/usr/local/mysqld_exporter/mysqld_exporter \
--config.my-cnf=/usr/local/mysqld_exporter/.my.cnf
[Install]
WantedBy=multi-user.target
# 重新加载配置
[root@node1 ~]# systemctl daemon-reload
# 启动服务
[root@node1 ~]# systemctl enable mysqld_exporter.service --now
[root@node1 ~]# ss -tlnp | grep :9104
LISTEN 0 128 :::9104
# 修改配置文件,追加以下内容:
[root@prometheus ~]# vim /usr/local/prometheus/prometheus.yml
- job_name: 'mysql'
static_configs:
- targets: ['192.168.88.11:9104']
[root@prometheus ~]# systemctl restart prometheus.service
查看状态
导入监控模板
查看监控数据
模板切换查看其模板