Featured image of post Redis 主从复制权限问题解决

Redis 主从复制权限问题解决

Opening the temp file needed for MASTER <-> REPLICA synchronization: Permission denied

现象

今天在搭建 redis主从复制环境时遇到了问题,两个从库都无法同步主库的数据

观察日志发现Opening the temp file needed for MASTER <-> REPLICA synchronization: Permission denied

replication-with-redis-error1

replication-with-redis-error2

原因

通过日志看出来是同步文件权限的问题

这是因为在需要完整数据传输时,redis 需要创建临时转储文件。如果关闭 rdb 设置,则在需要完整同步时,由于无法创建快照,将发生错误。

解决

在 redis 的配置文件里加上 rdb 文件的配置路径,重启 redis 服务即可

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
[root@localhost ~]# cat /etc/redis/redis.conf | grep -v "#"
daemonize yes
bind 0.0.0.0
port 6379
slaveof 10.0.0.101 6379
slave-read-only yes
masterauth 123456
requirepass 123456

dir /var/lib/redis
dbfilename dump.rdb

replication-with-redis-error3

master_link_status up 数据可以正常同步了

Licensed under CC BY-NC-SA 4.0
使用 Hugo 构建
主题 StackJimmy 设计