自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Prometheus 快速監(jiān)控 MySQL 數(shù)據(jù)庫(kù),超簡(jiǎn)單!

數(shù)據(jù)庫(kù) MySQL
本文在默認(rèn)數(shù)據(jù)庫(kù)和 prometheus 都已部署好的前提下,分享 Prometheus 如何監(jiān)控 MySQL 數(shù)據(jù)庫(kù)。

今天分享一下Prometheus如何監(jiān)控MySQL數(shù)據(jù)庫(kù)。

實(shí)驗(yàn)環(huán)境:

  • 數(shù)據(jù)庫(kù)服務(wù)器:10.0.0.41
  • prometheus服務(wù)器:10.0.0.104

默認(rèn)數(shù)據(jù)庫(kù)和prometheus都已部署好!下面演示安裝mysql_exporter過(guò)程。

一、安裝mysqld_exporter

在MySQL數(shù)據(jù)庫(kù)服務(wù)器上安裝mysql_exporter。

1. 創(chuàng)建 MySQL 只讀監(jiān)控用戶

在 MySQL 中運(yùn)行以下命令(換成你自己的密碼):

CREATE USER 'exporter'@'%' IDENTIFIED BY '123456';
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'%';
FLUSH PRIVILEGES;

驗(yàn)證登錄:

mysql -uexporter -p123456

2. 安裝 mysqld_exporter

下載并安裝:

cd /opt
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.17.2/mysqld_exporter-0.17.2.linux-amd64.tar.gz
tar -xvf mysqld_exporter-0.17.2.linux-amd64.tar.gz
cp mysqld_exporter-0.17.2.linux-amd64/mysqld_exporter /usr/local/bin/
chmod +x /usr/local/bin/mysqld_exporter

3.創(chuàng)建配置文件

在 /etc 下創(chuàng)建 .mysqld_exporter.cnf 登錄配置:

vi  /etc/.mysqld_exporter.cnf

內(nèi)容如下:

[client]
user=exporter
password=123456

4. 配置 systemd 服務(wù)

創(chuàng)建服務(wù)文件:

vi  /etc/systemd/system/mysqld_exporter.service

內(nèi)容如下:

[Unit]
Descriptinotallow=Prometheus MySQL Exporter
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/mysqld_exporter--config.my-cnf=/etc/.mysqld_exporter.cnf
Restart=on-failure

[Install]
WantedBy=multi-user.target

然后啟動(dòng)服務(wù):

# 重載系統(tǒng)服務(wù)
systemctl daemon-reload

# 啟動(dòng)并設(shè)置開(kāi)機(jī)自啟動(dòng)
systemctl enable --now mysqld_exporter

查看狀態(tài):

systemctl status mysqld_exporter

5. 防火墻放行(可選)

確保 Prometheus 節(jié)點(diǎn)(10.0.0.104)能訪問(wèn)此節(jié)點(diǎn)的 9104 端口:

# 關(guān)閉防火墻
systemctl disable --now firewalld

# 或者開(kāi)通9104端口
firewall-cmd --permanent --add-port=9104/tcp
firewall-cmd --reload

二、Prometheus 配置

編輯你的 prometheus.yml:

vi /data/prometheus/prometheus.yml
global:
  scrape_interval: 15s

scrape_configs:
  - job_name: 'mysql-exporter'
    static_configs:
      - targets: ['10.0.0.41:9104']
        labels:
          mysql: 10.0.0.41數(shù)據(jù)庫(kù)

保存并重啟 Prometheus:

systemctl restart prometheus

訪問(wèn) Prometheus 界面:

http://10.0.0.104:9090

進(jìn)入 Status > Targets,確認(rèn) 10.0.0.41:9104 狀態(tài)為 UP。

三、測(cè)試指標(biāo)是否可用

在瀏覽器或命令行訪問(wèn):

http://10.0.0.41:9104/metrics

你應(yīng)該能看到:

說(shuō)明 exporter 成功運(yùn)行并能讀取數(shù)據(jù)庫(kù)狀態(tài)!

四、使用Grafana可視化展示

導(dǎo)入 MySQL 監(jiān)控 Dashboard(推薦模板 ID:7362 或 14057):

責(zé)任編輯:趙寧寧 來(lái)源: 運(yùn)維李哥不背鍋
相關(guān)推薦

2023-02-28 22:52:47

2019-04-02 10:36:17

數(shù)據(jù)庫(kù)MySQL優(yōu)化方法

2011-03-04 14:13:02

MySQL數(shù)據(jù)庫(kù)

2014-04-09 11:43:54

Zabbix監(jiān)控Mysql數(shù)據(jù)庫(kù)

2022-07-11 09:36:38

SpringJava開(kāi)發(fā)

2020-11-20 08:15:40

Grafana + P

2011-03-21 17:00:23

MySQL數(shù)據(jù)庫(kù)

2023-02-28 00:01:53

MySQL數(shù)據(jù)庫(kù)工具

2010-06-04 09:58:03

MySQL數(shù)據(jù)庫(kù)備份

2009-06-02 14:36:28

HibernateMySQLEclipse

2010-06-09 11:32:51

MySQL數(shù)據(jù)庫(kù)備份

2023-12-26 07:40:34

2010-05-12 17:45:03

MySQL數(shù)據(jù)庫(kù)引擎

2011-04-06 09:09:17

MySQL數(shù)據(jù)庫(kù)備份

2010-05-14 11:04:17

連接MySQL

2019-01-02 09:30:59

MySQL數(shù)據(jù)庫(kù)日志審計(jì)

2021-03-08 10:18:55

數(shù)據(jù)庫(kù)數(shù)據(jù)Prometheus

2021-03-15 10:10:29

數(shù)據(jù)庫(kù)數(shù)據(jù)查詢

2018-09-13 15:20:24

數(shù)據(jù)庫(kù)MySQLSQL

2018-01-04 10:43:43

OracleMysqlJava
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)