温馨提示×

centos如何监控redis

小樊
49
2026-08-18 15:42:51
栏目: 云计算

CentOS 上监控 Redis,可以从 命令行、内置监控、第三方工具 三个层面来做。下面按由易到难、由基础到生产级给你梳理一套常用方案。


一、Redis 自带监控(最基础)

1️⃣ 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 cpu
redis-cli info persistence
redis-cli info replication

✅ 重点指标:

  • memory
    • used_memory
    • used_memory_rss
    • mem_fragmentation_ratio
  • stats
    • total_commands_processed
    • instantaneous_ops_per_sec
  • clients
    • connected_clients

2️⃣ redis-cli --stat(实时)

redis-cli --stat

示例输出:

------- data ------ --------------------- load -------------------- - child -
keys       mem      clients blocked requests            connections
12         1.12M    10      0       123456(+12)          78

✅ 适合快速查看 QPS、连接数、内存


3️⃣ redis-cli monitor(调试用,慎用)

redis-cli monitor

⚠️ 生产环境慎用

  • 会输出所有命令
  • 对性能影响大

二、系统级监控(CentOS)

1️⃣ 查看 Redis 进程

ps -ef | grep redis
top -p $(pgrep redis-server)

2️⃣ 查看端口

ss -lntp | grep 6379

3️⃣ 查看内存 & CPU

free -h
vmstat 1
iostat -x 1

三、日志监控

Redis 日志位置

grep logfile /etc/redis.conf

常见路径:

/var/log/redis/redis.log

查看:

tail -f /var/log/redis/redis.log

✅ 常见关注点:

  • OOM
  • latency
  • fork
  • BGSAVE

四、生产级监控方案(强烈推荐)

✅ 方案一:Redis Exporter + Prometheus + Grafana(最主流)

1️⃣ 安装 Redis Exporter

wget https://github.com/prometheus/redis_exporter/releases/download/v1.55.0/redis_exporter-v1.55.0.linux-amd64.tar.gz
tar -zxvf redis_exporter*
cd redis_exporter

启动:

./redis_exporter --redis.addr=redis://127.0.0.1:6379

(如有密码)

./redis_exporter --redis.addr=redis://127.0.0.1:6379 --redis.password=yourpassword

2️⃣ Prometheus 配置

scrape_configs:
  - job_name: redis
    static_configs:
      - targets: ["localhost:9121"]

3️⃣ Grafana

  • 导入官方 Redis Dashboard
  • 可监控:
    • QPS
    • 内存
    • 命中率
    • 延迟
    • 主从状态

企业最常用方案


✅ 方案二:Zabbix 监控 Redis

适合已有 Zabbix 环境

  • 使用 redis-cli info
  • 自定义 key
  • 模板:
    • Zabbix 官方 / 社区 Redis 模板

五、Redis 延迟 & 健康检查

1️⃣ 延迟监控

redis-cli --latency
redis-cli --latency-history

2️⃣ 检查是否存活

redis-cli ping
# 返回 PONG

六、常见告警指标建议

指标 告警建议
内存使用率 > 80%
连接数 > maxclients * 80%
命中率 < 90%
fork 失败 出现即告警
主从断连 立即告警

七、快速总结(推荐搭配)

开发/测试

redis-cli info
redis-cli --stat

生产环境

Redis Exporter + Prometheus + Grafana

如果你愿意,我可以:

  • ✅ 给你 CentOS 7/8 一键部署脚本
  • ✅ 帮你 解读 redis-cli info 输出
  • ✅ 设计 Redis 告警规则

你现在用的是 单机 Redis 还是集群?有没有密码?

0