有效監(jiān)控 redis 數(shù)據(jù)庫對(duì)于保持最佳性能、識(shí)別潛在瓶頸和確保整體系統(tǒng)可靠性至關(guān)重要。 Redis Exporter Service 是一個(gè)強(qiáng)大的實(shí)用程序,旨在使用 Prometheus 監(jiān)控 Redis 數(shù)據(jù)庫。 本教程將指導(dǎo)您完成 Redis Exporter Service 的完整設(shè)置和配置,確保您無縫建立監(jiān)控解決方案。通過學(xué)習(xí)本教程,您將實(shí)現(xiàn)完全可操作的監(jiān)控設(shè)置
方法一:手動(dòng)配置
我們繼續(xù)本節(jié)的手動(dòng)配置方法。
創(chuàng)建Prometheus系統(tǒng)用戶和組
創(chuàng)建一個(gè)名為的系統(tǒng)用戶和組“prometheus”來管理導(dǎo)出器
sudo groupadd --system prometheus
sudo useradd -s /sbin/nologin --system -g prometheus prometheus
下載并安裝 Redis Exporter
下載從 gitHub 提取最新版本的 Redis Exporter 下載的文件,并將二進(jìn)制文件移動(dòng)到 /usr/local/bin/ 目錄。
tar xvf redis_exporter-*.linux-amd64.tar.gz
sudo mv redis_exporter-*.linux-amd64/redis_exporter /usr/local/bin/
驗(yàn)證 Redis 導(dǎo)出器安裝
redis_exporter --version
這是示例輸出:
為 Redis Exporter 配置 systemd 服務(wù)
創(chuàng)建 systemd 服務(wù)單元文件來管理 Redis Exporter
sudo vim /etc/systemd/system/redis_exporter.service
將以下內(nèi)容添加到file:
[Unit]Description=Prometheus Redis ExporterDocumentation=https://github.com/oliver006/redis_exporterWants=network-online.targetAfter=network-online.target[Service]Type=simpleUser=prometheusGroup=prometheusExecReload=/bin/kill -HUP $MaiNPIDExecStart=/usr/local/bin/redis_exporter --log-format=txt --namespace=redis --web.listen-address=:9121 --web.telemetry-path=/metricssyslogIdentifier=redis_exporterRestart=always[Install]WantedBy=multi-user.target
重新加載 systemd 并啟動(dòng) Redis Exporter服務(wù)
sudo systemctl daemon-reload
sudo systemctl enable redis_exporter
sudo systemctl start redis_exporter
配置 Prometheus Droplet(手動(dòng)方法)
讓我們手動(dòng)配置 Prometheous Droplet。
備份 prometheus.yml 文件
cp /etc/prometheus/prometheus.yml /etc/prometheus/prometheus.yml-$(date '%d%b%Y-%H:%M')
添加 Redis Exporter 端點(diǎn)scraped
登錄到您的 Prometheus 服務(wù)器并添加要抓取的 Redis Exporter 端點(diǎn)。
將 IP 地址和端口替換為您的 Redis Exporter 端點(diǎn)(9121 是 Redis Exporter 的默認(rèn)端口)服務(wù))。
vi /etc/prometheus/prometheus.yml
scrape_configs: - job_name: server1_db static_configs: - targets: ['10.10.1.10:9121'] labels: alias: db1 - job_name: server2_db static_configs: - targets: ['10.10.1.11:9121'] labels:
手動(dòng)配置到此結(jié)束。現(xiàn)在,讓我們繼續(xù)基于腳本的配置。
方法 2:使用腳本進(jìn)行配置
您還可以通過運(yùn)行兩個(gè)腳本來實(shí)現(xiàn)此目的 – 一個(gè)用于目標(biāo) Droplet,另一個(gè)用于 Prometheus Droplet。
讓我們從配置目標(biāo) Droplet 開始。
通過 ssh 連接到目標(biāo)Droplet。
使用以下命令下載目標(biāo)配置腳本:
wget https://solutions-files.ams3.digitaloceanspaces.com/Redis-Monitoring/DO_Redis_Target_Config.sh
下載腳本后,確保它具有可執(zhí)行權(quán)限運(yùn)行:
chmod x DO_Redis_Target_Config.sh
通過運(yùn)行以下命令執(zhí)行腳本:
./DO_Redis_Target_Config.sh
配置
注意:如果redis_exporter.service文件已經(jīng)存在,腳本將不會(huì)運(yùn)行。
配置 Prometheus Droplet(腳本方法)
SSH 到 Prometheus Droplet 并使用以下命令下載腳本:
wget https://solutions-files.ams3.digitaloceanspaces.com/Redis-Monitoring/DO_Redis_Prometheus_Config.sh
下載腳本后,請(qǐng)確保它具有可執(zhí)行權(quán)限運(yùn)行:
chmod x DO_Redis_Prometheus_Config.sh
執(zhí)行腳本running:
./DO_Redis_Prometheus_Config.sh
輸入要添加到監(jiān)控的 Droplet 數(shù)量。
輸入主機(jī)名和IP地址。
配置完成。
添加后,通過訪問 URL prometheushostname:9090/targets 檢查目標(biāo)是否更新。
注意:如果您輸入的 IP 地址已添加到 監(jiān)控時(shí),您將被要求再次輸入詳細(xì)信息。另外,如果 您沒有更多服務(wù)器可以添加,可以輸入 0 退出 script
配置 grafana
通過瀏覽器訪問 Grafana-IP:3000 登錄 Grafana 儀表板。
Go到配置 > 數(shù)據(jù)來源。
單擊“添加數(shù)據(jù)源”。
搜索并選擇 Prometheus。
輸入名稱 Prometheus 和 URL (Prometheus主機(jī)名:9090)并單擊“保存并測(cè)試”。如果看到“數(shù)據(jù)源正在運(yùn)行”,則說明您已成功添加數(shù)據(jù)源。完成后,轉(zhuǎn)到創(chuàng)建 > 導(dǎo)入。
您可以手動(dòng)配置儀表板或通過以下方式導(dǎo)入儀表板 上傳 JSON 文件。用于 Redis 監(jiān)控的 json 模板可以是 在以下鏈接中找到:
https://solutions-files.ams3.digitaloceanspaces.com/Redis-Monitoring/DO_Grafana-Redis_Monitoring.json
填寫字段并導(dǎo)入。
Grafana 儀表板是 準(zhǔn)備好。選擇主機(jī)并檢查是否 指標(biāo)是可見的。請(qǐng)隨意修改和編輯儀表板 根據(jù)需要。