社群開發者您好! ?
在這篇文章中,我將引導您完成在 Galera Cluster 節點上設定 MariaDB/MySQL Exporter 以使用 Prometheus 進行監控所採取的步驟。就我而言,我在具有三個節點的雲端伺服器供應商上運行 MariaDB Galera Cluster,並使用 Prometheus Grafana 來監控我的設定。 Galera Cluster 設定和監控工具非常有用,但從 MariaDB 取得正確的指標並不簡單,因此我決定記錄我的解決方案。
要監控 MariaDB 和 Galera Cluster 指標,例如每秒查詢數、連線數、複製狀態等,您需要結合 MySQL Exporter 和 Prometheus。該導出器將公開特定於資料庫的指標,包括 Galera 和 MariaDB 統計資料。
在 Galera 叢集節點上設定 MariaDB/MySQL Exporter 的步驟:
注意:您已經可以在雲端伺服器供應商的市場上使用 Prometheus Grafana 的機器。赫茲納,數位海洋
在每個 Galera 節點上,我們需要安裝 MySQL Exporter,它收集指標並將其公開給 Prometheus。具體方法如下:
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.15.1/mysqld_exporter-0.15.1.linux-amd64.tar.gz
tar xvfz mysqld_exporter-0.15.1.linux-amd64.tar.gz
sudo cp mysqld_exporter-0.15.1.linux-amd64/mysqld_exporter /usr/local/bin/
sudo useradd -rs /bin/false mysqld_exporter
導出器需要存取 MariaDB 指標。在匯出器的主目錄中建立 .my.cnf 檔案來儲存連接憑證:
sudo mkdir /etc/.mysqld_exporter
sudo nano /etc/.mysqld_exporter/.my.cnf
將以下內容新增至文件:
[client] user=exporter password=yourpassword
確保使用者俱有存取必要指標的適當權限:
存取使用 mysql -u root 或 mariadb -u root
建立由「yourpassword」所識別的使用者「exporter」@「localhost」;
授予進程,複製客戶端,選擇 *.* TO 'exporter'@'localhost';
同花順特權;
為了確保 MySQL Exporter 在啟動時啟動,讓我們將其配置為 systemd 服務:
sudo nano /etc/systemd/system/mysqld_exporter.service
將以下內容新增至文件:
[Unit] Description=Prometheus MySQL Exporter Wants=network-online.target After=network-online.target [Service] User=mysqld_exporter Group=mysqld_exporter ExecStart=/usr/local/bin/mysqld_exporter \ --config.my-cnf=/etc/.mysqld_exporter/.my.cnf [Install] WantedBy=multi-user.target
儲存檔案並重新載入systemd:
sudo systemctl daemon-reload
sudo systemctl 啟動 mysqld_exporter
sudo systemctl 啟用 mysqld_exporter
接下來,更新您的 Prometheus 配置以從節點中取得指標。將以下內容新增至您的 prometheus.yml 檔案:
在此之前,您可以透過存取以下命令來檢查 MySQL Exporter 是否正在運行:
curl http://
要存取此文件,例如 prometheus.yml,請使用:
sudo nano /opt/containers/prometheus-grafana/prometheus/prometheus.yml
加入 scrape_configs::
- job_name: 'mariadb-galera' static_configs: - targets: ['node1-ip:9104', 'node2-ip:9104', 'node3-ip:9104']
請回覆您資料庫節點的IP
然後,重新載入 Prometheus:
sudo systemctl 重新載入普羅米修斯
如果您使用 Grafana,您可以匯入預先建置的儀表板以進行 MySQL/MariaDB 監控。 MySQL/MariaDB 指標的一種流行儀表板 ID 是 7362.
導入:
您現在應該在 Grafana 儀表板中看到來自 MariaDB Galera Cluster 節點的詳細指標!
透過在每個 Galera Cluster 節點上設定 MariaDB Exporter,Prometheus 現在可以抓取和監控關鍵資料庫指標。此設定可以更了解叢集的運作狀況和效能,從而更輕鬆地根據需要進行故障排除和最佳化。
如果您正在設定類似的內容或有任何建議,請隨時在下面留下任何問題或評論。感謝您的閱讀!
免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。
Copyright© 2022 湘ICP备2022001581号-3