温馨提示×

怎样监控CentOS Redis状态

小樊
42
2026-08-03 14:27:34
栏目: 云计算

CentOS 上监控 Redis 状态,常见方式从简单到专业如下,你可以按场景选择。


一、使用 Redis 自带命令(最常用)

1️⃣ redis-cli ping

redis-cli ping

✅ 正常返回:

PONG

说明 Redis 服务存活。


2️⃣ 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_memory
  • connected_clients
  • instantaneous_ops_per_sec
  • keyspace_hits / misses
  • role:master / slave

3️⃣ 查看 Redis 进程状态

ps -ef | grep redis

systemctl status redis

二、系统级监控(CentOS)

1️⃣ 端口监听

ss -lntp | grep 6379

netstat -lntp | grep 6379

2️⃣ 查看 CPU / 内存

top
htop
free -h

3️⃣ 查看日志

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

(路径可能不同,取决于配置)


三、使用 redis-stat(轻量工具)

gem install redis-stat
redis-stat

实时显示:

  • 内存
  • QPS
  • 连接数

四、Prometheus + Grafana(生产推荐 ✅)

架构

Redis → redis_exporter → Prometheus → Grafana

安装 redis_exporter

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

Prometheus 配置

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

✅ Grafana 可导入官方 Redis Dashboard


五、Zabbix 监控 Redis(企业常用)

Zabbix 可通过:

  • 自定义脚本调用 redis-cli info
  • 或 redis_exporter

监控:

  • 内存
  • 连接数
  • 主从状态
  • 延迟

六、常见告警指标建议

指标 建议阈值
内存使用 > 80%
连接数 > maxclients 80%
命中率 < 90%
主从状态 master_link_status=down
延迟 > 10ms

七、快速检查脚本(推荐)

#!/bin/bash
redis-cli ping | grep -q PONG && echo "Redis OK" || echo "Redis DOWN"

如果你愿意,我可以:

  • ✅ 给你 生产环境 Redis 监控方案
  • ✅ 帮你 配置 Prometheus + Grafana
  • ✅ 针对 单机 / 集群 / 哨兵 分别说明

你现在用的是 单机 Redis 还是集群?

0