windows wsl docker redis主从同步错误处理
目录
问题
在master中存入数据后,并没有同步到slave中
overcommit_memory is set to 0
WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
1. 添加.wslconfig文件
在 C:\Users<username> 创建.wslconfig 文件,文件内容如下
[wsl2]
kernelCommandLine = "sysctl.vm.overcommit_memory=1"
2. 重启wsl
wsl --shutdown
然后重启docker
Failed trying to load the MASTER synchronization DB from disk: No such file or directory
1:S 11 Jul 2022 16:00:44.569 # Failed trying to load the MASTER synchronization DB from disk: No such file or directory
1:S 11 Jul 2022 16:00:44.570 * Reconnecting to MASTER 172.25.0.101:6379 after failure
1:S 11 Jul 2022 16:00:44.570 * MASTER <-> REPLICA sync started
1:S 11 Jul 2022 16:00:44.570 * Non blocking connect for SYNC fired the event.
1:S 11 Jul 2022 16:00:44.571 * Master replied to PING, replication can continue...
1:S 11 Jul 2022 16:00:44.571 * Partial resynchronization not possible (no cached master)
redis官方配置redis.conf
其中有这么一段
# -----------------------------------------------------------------------------
#
# Replica can load the RDB it reads from the replication link directly from the
# socket, or store the RDB to a file and read that file after it was completely
# received from the master.
#
# In many cases the disk is slower than the network, and storing and loading
# the RDB file may increase replication time (and even increase the master's
# Copy on Write memory and replica buffers).
# However, parsing the RDB file directly from the socket may mean that we have
# to flush the contents of the current database before the full rdb was
# received. For this reason we have the following options:
#
# "disabled" - Don't use diskless load (store the rdb file to the disk first)
# "on-empty-db" - Use diskless load only when it is completely safe.
# "swapdb" - Keep current db contents in RAM while parsing the data directly
# from the socket. Replicas in this mode can keep serving current
# data set while replication is in progress, except for cases where
# they can't recognize master as having a data set from same
# replication history.
# Note that this requires sufficient memory, if you don't have it,
# you risk an OOM kill.
repl-diskless-load disabled
我们将上面的属性设置为on-empty-db即可
样例
给出的样例仅仅用于windows wsl docker本地测试,不具有正式环境部署参考价值
master
port 6379
protected-mode no
repl-diskless-sync no
repl-disable-tcp-nodelay no
# 这里不开启的话,slave不一定能同步成功
repl-diskless-load on-empty-db
# 开启AOF
appendonly yes
# 每秒钟备份
appendfsync everysec
slaver
port 6379
protected-mode no
slaveof 172.25.0.101 6379
slave-read-only yes
slave-serve-stale-data yes
# 这里不开启的话,slave不一定能同步成功
repl-diskless-load on-empty-db
# 开启AOF
appendonly yes
# 每秒钟备份
appendfsync everysec
参考
https://www.361shipin.com/blog/1512884685401751552
https://www.phpnanshen.com/article/156.html
https://download.redis.io/redis-stable/redis.conf
https://github.com/redis/redis/issues/4102

浙公网安备 33010602011771号