在 CentOS 上监控 Redis 状态,常见方式从简单到专业如下,你可以按场景选择。
redis-cli pingredis-cli ping
✅ 正常返回:
PONG
说明 Redis 服务存活。
redis-cli info(最重要)redis-cli info
常用分类:
redis-cli info server # 版本、启动时间
redis-cli info clients # 客户端连接数
redis-cli info memory # 内存使用
redis-cli info stats # 命中率、命令统计
redis-cli info replication # 主从状态
redis-cli info persistence # RDB / AOF
✅ 重点关注指标:
used_memoryconnected_clientsinstantaneous_ops_per_seckeyspace_hits / missesrole:master / slaveps -ef | grep redis
或
systemctl status redis
ss -lntp | grep 6379
或
netstat -lntp | grep 6379
top
htop
free -h
tail -f /var/log/redis/redis.log
(路径可能不同,取决于配置)
gem install redis-stat
redis-stat
实时显示:
Redis → redis_exporter → Prometheus → Grafana
wget https://github.com/oliver006/redis_exporter/releases/download/v1.55.0/redis_exporter-v1.55.0.linux-amd64.tar.gz
tar -zxvf redis_exporter-*.tar.gz
./redis_exporter --redis.addr=localhost:6379
scrape_configs:
- job_name: redis
static_configs:
- targets: ["localhost:9121"]
✅ Grafana 可导入官方 Redis Dashboard
Zabbix 可通过:
redis-cli info监控:
| 指标 | 建议阈值 |
|---|---|
| 内存使用 | > 80% |
| 连接数 | > maxclients 80% |
| 命中率 | < 90% |
| 主从状态 | master_link_status=down |
| 延迟 | > 10ms |
#!/bin/bash
redis-cli ping | grep -q PONG && echo "Redis OK" || echo "Redis DOWN"
如果你愿意,我可以:
你现在用的是 单机 Redis 还是集群?