Redis 日志分为 4 个级别,通过 loglevel 配置项控制输出阈值:
| 级别 | 标识 | 说明 |
|---|---|---|
| LL_DEBUG | # |
调试信息,默认不输出 |
| LL_VERBOSE | * |
详细信息 |
| LL_NOTICE | * |
通知信息(默认级别) |
| LL_WARNING | ! |
警告信息 |
日志格式:<pid>:<角色> <日期> <时间>.<毫秒> <级别标识> <消息>
一、启动与关闭
启动
oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
Redis version=6.2.x, bits=64, commit=xxx, modified=0, pid=1234, just started
Configuration loaded
Server initialized
Ready to accept connections
关闭
Removing the unix socket file.
Calling fsync() on the AOF file.
Saving the final RDB snapshot before exiting.
Removing the pid file.
二、数据加载
从 RDB 加载
RDB 'dump.rdb': CRC64 checksum is OK
Loading RDB produced by version 6.2.x
RDB age 3600 seconds
RDB memory usage when created 128.00 Mb
DB loaded from disk: 0.123 seconds
从 AOF 加载
Reading RDB preamble from AOF file...
Reading the remaining AOF tail...
DB loaded from append only file: 0.456 seconds
三、RDB 持久化
触发保存
1 changes in 3600 seconds. Saving... # save 3600 1 触发
100 changes in 300 seconds. Saving... # save 300 100 触发
后台保存过程
Background saving started by pid 237692 # fork 子进程
DB saved on disk # 子进程写入完成
RDB: 2 MB of memory used by copy-on-write # COW 额外内存
Background saving terminated with success # 主进程确认完成
保存失败
Can't save in background: fork: Cannot allocate memory
Background saving error
Write error saving DB on disk: No space left on device
四、AOF 持久化
AOF 写入异常
Error writing to the AOF file: No space left on device
Short write while writing to the AOF file
Can't recover from AOF write error when the AOF fsync policy is 'always'. Exiting...
Asynchronous AOF fsync is taking too long (disk is busy?). Writing the AOF buffer without waiting for fsync to complete, this may slow down Redis.
AOF 重写过程
Background append only file rewriting started by pid 2714036
AOF rewrite child asks to stop sending diffs. # 子进程通知停止增量
Parent agreed to stop sending diffs. Finalizing AOF... # 子进程收到 ACK
Concatenating 0.00 MB of AOF diff received from parent. # 追加增量差异
SYNC append only file rewrite performed # fsync 落盘
AOF rewrite: 1 MB of memory used by copy-on-write # COW 内存
Background AOF rewrite terminated with success # 主进程确认
Residual parent diff successfully flushed to the rewritten AOF (0.00 MB) # 追加剩余差异
Background AOF rewrite finished successfully # 最终完成
AOF 重写失败
Can't rewrite append only file in background: fork: Cannot allocate memory
Error opening /setting AOF rewrite IPC pipes: Too many open files
Error moving temp append only file on the final destination: No space left on device
Write error writing append only file on disk: Input/output error
AOF 加载异常
!!! Warning: short read while loading the AOF file !!!
!!! Truncating the AOF at offset 12345 !!!
Unexpected end of file reading the append only file. You can: 1) Make a backup of your AOF file, then use ./redis-check-aof --fix <filename>. 2) Alternatively you can set the 'aof-load-truncated' configuration option to yes and restart the server.
Bad file format reading the append only file: make a backup of your AOF file, then use ./redis-check-aof --fix <filename>
AOF 自动重写触发
Starting automatic rewriting of AOF on 100% growth
五、主从复制
从节点连接主节点
Trying a partial resynchronization (request <replid>:<offset>). # 尝试部分同步
Partial resynchronization not possible (no cached master) # 无法部分同步
Full resync from master: <replid>:<offset> # 全量同步
主节点处理从节点
Replica <ip>:<port> asks for synchronization
Partial resynchronization not accepted: Requested id is different
Full resync requested by replica <ip>:<port>
Starting BGSAVE for SYNC with target: <ip>:<port>
Synchronization with replica <ip>:<port> succeeded
同步数据加载
MASTER <-> REPLICA sync: Flushing old data
MASTER <-> REPLICA sync: Loading DB in memory
MASTER <-> REPLICA sync: Finished with success
复制积压缓冲区
Replication backlog created, my new replication IDs are: <id1> <id2>
复制连接断开
Connection with master lost.
Reconnecting to master <ip>:<port>
Master is currently unable to PSYNC but should be in the future
六、集群
集群初始化
No cluster configuration found, I'm <nodeid>
Node configuration loaded, I'm <nodeid>
集群状态变更
Cluster state changed: ok
Cluster state changed: fail
节点通信
Connecting with Node <nodeid> at <ip>:<port>
Connection with Node <nodeid> at <ip>:<port> failed: Connection refused
Accepting cluster node connection from <ip>:<port>
故障转移
Manual failover requested by replica <nodeid>
Start of election delayed for <ms> milliseconds
Failover election won, I'm the new master.
槽位变更
Slot <slot> migrated from <nodeid> to <nodeid>
七、客户端连接
连接建立与断开
Accepted <ip>:<port> # 新连接
Accepted connection to /tmp/redis.sock # Unix socket
Client closed connection # 客户端断开
Reading from client: Connection reset by peer # 读取错误
Closing idle client # 空闲超时断开
客户端输入缓冲区异常
Client id=<id> addr=<ip>:<port> fd=<n> name=<name> age=<sec> idle=<sec> flags=<flags> qbuf=<len> argv=<len> cmd=<cmd> input buffer length <len> is bigger than <limit> dropping the connection.
八、模块
Module '<name>' loaded from <path>
Module <name> unloaded
Module fork started pid: <pid>
九、内存与系统
内存警告
WARNING overcommit_memory is set to 0! Background save may fail under low memory condition.
WARNING you have Transparent Huge Pages (THP) support enabled in your kernel
WARNING Your kernel has a bug that could lead to data corruption during background save. Please upgrade to the latest stable kernel.
文件描述符
Increased maximum number of open files to <n>
系统监控
supervised by upstart, will stop to signal readiness.
Systemd supervision detected.
Upstart supervision detected.
十、碎片整理
Active defrag started
Active defrag done
Active defrag stopped
日志级别配置建议
| 场景 | 推荐 loglevel |
|---|---|
| 生产环境 | notice(默认) |
| 排查问题 | verbose |
| 开发调试 | debug |
| 只看警告 | warning |