非root用户启动Redis主从复制失败

搭建redis主从复制环境,非root用户启动redis,结果总是同步失败,日志报错如下:

42580:M 25 Apr 2021 20:50:16.183 # Background saving error
42580:M 25 Apr 2021 20:50:16.183 # Connection with replica 127.0.0.1:6380 lost.
42580:M 25 Apr 2021 20:50:16.183 # SYNC failed. BGSAVE child returned an error
42580:M 25 Apr 2021 20:50:16.183 # Connection with replica 127.0.0.1:6381 lost.
42580:M 25 Apr 2021 20:50:16.183 # SYNC failed. BGSAVE child returned an error
42580:M 25 Apr 2021 20:50:16.186 * Replica 127.0.0.1:6380 asks for synchronization
42580:M 25 Apr 2021 20:50:16.186 * Full resync requested by replica 127.0.0.1:6380
42580:M 25 Apr 2021 20:50:16.186 * Starting BGSAVE for SYNC with target: disk
42580:M 25 Apr 2021 20:50:16.187 * Background saving started by pid 77759
42580:M 25 Apr 2021 20:50:16.187 * Replica 127.0.0.1:6381 asks for synchronization
42580:M 25 Apr 2021 20:50:16.188 * Full resync requested by replica 127.0.0.1:6381
42580:M 25 Apr 2021 20:50:16.188 * Waiting for end of BGSAVE for SYNC
77759:C 25 Apr 2021 20:50:16.188 # Failed opening the RDB file dump-6379.rdb (in server root dir /) for saving: Permission denied

其实日志说的很明白了,就是权限的问题,普通用户不能在root目录下创建文件。需要修改如下几个地方。

1、dir "/" 修改为 dir "/home/hl/redis",改成自己实际的redis安装目录。

2、pidfile "/var/run/redis.pid" 修改为 pidfile "/home/hl/redis/run/redis.pid",手动创建run目录。

3、logfile "" 修改为 logfile "/home/hl/redis/logs/redis.log"。需要手动创建logs目录。

重启redis就可以了。

77907:M 25 Apr 2021 21:01:31.490 * Replica 127.0.0.1:6380 asks for synchronization
77907:M 25 Apr 2021 21:01:31.491 * Partial resynchronization not accepted: Replication ID mismatch (Replica asked for '82b6f43c59d5e853c5752c2e12065718260e917d', my replication IDs are 'f27fc99c8768000e3e76e44f28e835e318760ec9' and '3c7011ce4e39066acc8aed2e8d9a66377596b8e1')
77907:M 25 Apr 2021 21:01:31.491 * Replication backlog created, my new replication IDs are '246c830e07b9a1e175c3934fdcb1572ef690b400' and '0000000000000000000000000000000000000000'
77907:M 25 Apr 2021 21:01:31.491 * Starting BGSAVE for SYNC with target: disk
78497:C 25 Apr 2021 21:01:31.541 * DB saved on disk
78497:C 25 Apr 2021 21:01:31.541 * RDB: 2 MB of memory used by copy-on-write
77907:M 25 Apr 2021 21:01:31.549 * Background saving started by pid 78497
77907:M 25 Apr 2021 21:01:31.549 * Background saving terminated with success
77907:M 25 Apr 2021 21:01:31.549 * Synchronization with replica 127.0.0.1:6380 succeeded
77907:M 25 Apr 2021 21:02:07.781 * Replica 127.0.0.1:6381 asks for synchronization
77907:M 25 Apr 2021 21:02:07.781 * Full resync requested by replica 127.0.0.1:6381
77907:M 25 Apr 2021 21:02:07.781 * Starting BGSAVE for SYNC with target: disk
77907:M 25 Apr 2021 21:02:07.804 * Background saving started by pid 78529
78529:C 25 Apr 2021 21:02:07.806 * DB saved on disk
78529:C 25 Apr 2021 21:02:07.806 * RDB: 2 MB of memory used by copy-on-write
77907:M 25 Apr 2021 21:02:07.877 * Background saving terminated with success
77907:M 25 Apr 2021 21:02:07.878 * Synchronization with replica 127.0.0.1:6381 succeeded

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值