一 导入第三方软件

二 安装解压

三 写service脚本。执行二进制文件

四 查看获取的监控指标
登录9121端口查看
五 让prometheus获取信息

加了标签,可以给三个机器的端口加到一个实例标签里面

六 登录prometheus服务器查看

七 查PSQL

八 配grafana出图

执行时间

下面给出一个从 0 到可视化的 Prometheus + Redis Exporter 部署方案,涵盖下载、systemd 管理、Prometheus 抓取配置以及 Grafana 使用示例,直接可以在生产或测试环境落地。
1️⃣ 安装 redis_exporter
1. 下载并解压
# 选择最新版本,也可以替换为特定版本
wget https://github.com/oliver006/redis_exporter/releases/latest/download/redis_exporter-v1.66.0.linux-amd64.tar.gz
tar zxvf redis_exporter-v1.66.0.linux-amd64.tar.gz
sudo mv redis_exporter-v1.66.0.linux-amd64/redis_exporter /usr/local/bin/
可选:容器方式
docker run -d --name redis_exporter \
-p 9121:9121 \
oliver006/redis_exporter
2️⃣ 启动并配置 systemd
编辑 /etc/systemd/system/redis_exporter.service:
[Unit]
Description=Redis Exporter
After=network.target
[Service]
User=redis
Group=redis
ExecStart=/usr/local/bin/redis_exporter \
--redis.addr=redis://127.0.0.1:6379 \
--redis.password=your_password
Restart=on-failure
[Install]
WantedBy=multi-user.target
加载并启动:
sudo systemctl daemon-reload
sudo systemctl enable --now redis_exporter
默认监听端口:9121
验证:
curl http://localhost:9121/metrics | head
3️⃣ 配置 Prometheus 抓取
在 prometheus.yml 增加 job:
scrape_configs:
- job_name: 'redis'
static_configs:
- targets:
- 192.168.10.21:9121 # redis_exporter 所在主机
labels:
env: production
app: redis
检查配置:
promtool check config /etc/prometheus/prometheus.yml
sudo systemctl restart prometheus
Prometheus UI (http://<prometheus_host>:9090) → Status → Targets 应看到 redis job 状态为 UP。
4️⃣ Grafana 可视化
-
Grafana → Connections → Add data source → Prometheus
URL:http://<prometheus_host>:9090 -
导入社区 Redis Dashboard(推荐 ID 11835 或 763)
- Dashboard → Import → 输入 ID → 选择数据源。
这些模板包含内存使用、命中率、连接数、CPU、慢查询等常见面板,可直接使用。
5️⃣ 告警示例 (可选)
/etc/prometheus/rules/redis_rules.yml
groups:
- name: redis_alerts
rules:
- alert: RedisMemoryHigh
expr: redis_memory_used_bytes / redis_memory_max_bytes > 0.8
for: 5m
labels:
severity: warning
annotations:
summary: "Redis memory >80% on {{ $labels.instance }}"
在 prometheus.yml 中添加:
rule_files:
- "/etc/prometheus/rules/redis_rules.yml"
6️⃣ 生产环境建议
| 方向 | 建议 |
|---|---|
| 安全 | 如需公网访问,在 exporter 前加 Nginx + basic_auth 或防火墙 |
| 高可用 | 多节点 Redis 建议每台都部署 exporter,并用 service_discovery |
| 监控指标 | 常用:redis_connected_clients、redis_keyspace_hits_total、redis_mem_fragmentation_ratio、redis_memory_used_bytes |
| 升级 | exporter 与 Redis 升级可独立进行,推荐版本 >= v1.5+ |
✅ 总结流程
Redis → 部署 redis_exporter(端口9121) → Prometheus 抓取并打标签 → Grafana 导入 Dashboard →(可选)Prometheus Rule 告警。
按以上步骤即可快速搭建 Prometheus 监控 Redis 的完整体系。
2579

被折叠的 条评论
为什么被折叠?



