在 CentOS 上配置 Redis 日志,通常有两种方式:修改 redis.conf 配置文件(推荐)和通过命令行临时设置(重启失效)。
下面以常见场景为例说明。
通常位置:
/etc/redis.conf
# 或
/etc/redis/redis.conf
查看 Redis 使用的配置文件:
ps -ef | grep redis
编辑配置文件:
vi /etc/redis.conf
logfile /var/log/redis/redis.log
如果写
logfile "",日志会输出到标准输出(适合 systemd / 容器)
loglevel notice
可选级别:
debug(最详细)verbosenotice(默认,推荐)warning(最少)mkdir -p /var/log/redis
chown redis:redis /var/log/redis
用户根据 redis 启动用户调整(常见为
redis)
systemctl restart redis
或
redis-cli shutdown
redis-server /etc/redis.conf
tail -f /var/log/redis/redis.log
如果你用的是 CentOS 7+ 的 systemd:
logfile ""
然后查看日志:
journalctl -u redis -f
redis-cli config set logfile /var/log/redis/redis.log
redis-cli config set loglevel verbose
logfile 路径和权限journalctl -xesetsebool -P redis_enable_notify 1
如果你愿意,可以告诉我:
我可以给你更精确的配置示例。