这是 middleware/redis.md 的每次改动内容,按时间从新到旧。其他文章一起提交的部分不会出现在这里。
#1
2026-10-18
+66
−0
docs: 新增存储/中间件/自动化/云与K8s/证书/流程 6 个分类和 16 篇文章
e4d2cd0
new file mode 100644
@@ -0,0 +1,66 @@
+---
+tags: [Redis, 缓存, 中间件]
+order: 10
+---
+
+# Redis 安装与排查
+
+## 场景
+
+应用要用 Redis 做缓存或会话存储,装上之后还要防止被扫、被写满。
+
+## 前置条件
+
+- 知道应用连过来的网段
+- 规划内存上限(别让 Redis 吃满物理内存)
+- 确认是否允许丢数据(决定开不开 AOF)
+
+## 配置
+
+```bash
+dnf install -y redis
+
+cat >/etc/redis/redis.conf.d/ops.conf <<'EOF'
+bind 10.0.0.5 127.0.0.1
+protected-mode yes
+requirepass 强密码
+maxmemory 2gb
+maxmemory-policy allkeys-lru
+appendonly yes
+appendfsync everysec
+EOF
+
+systemctl enable --now redis
+systemctl restart redis
+```
+
+连接测试:
+
+```bash
+redis-cli -h 10.0.0.5 -a 强密码 ping
+```
+
+## 验证
+
+```bash
+redis-cli -a 强密码 INFO server | head
+redis-cli -a 强密码 INFO memory | grep used_memory_human
+redis-cli -a 强密码 CONFIG GET maxmemory
+redis-cli -a 强密码 DBSIZE
+```
+
+## 回滚
+
+```bash
+systemctl disable --now redis
+rm /etc/redis/redis.conf.d/ops.conf
+```
+
+## 坑
+
+- **默认 `bind 0.0.0.0` + 无密码 = 被挖矿**,这是最常见的失陷原因。
+- `maxmemory` 不设,内存涨到 OOM 被内核杀掉。
+- `maxmemory-policy noeviction` 时写满会直接报错,不是淘汰。
+- 开 AOF 后磁盘写入翻倍,机械盘上延迟明显。
+- 主从切换后应用还连着旧主,要客户端支持 sentinel 或 cluster。
+- `KEYS *` 在大库上会阻塞,用 `SCAN`。