redis slave won't sync with master

2020-06-07 06:20发布

The redis slave won't sync with the master.

Connectivity:

I can connect to the master when I issue

HOST_NAME=fakehost
redis-cli -h $HOST_NAME

and check the master status using a command like INFO, so connectivity is not an issue.

Settings:

From the slave box, I issued

SLAVEOF $HOST_NAME 6379

And received an OK.

When I issue the INFO command on the slave, I get

# Replication
role:slave
master_host:<removed>
master_port:6379
master_link_status:down
master_last_io_seconds_ago:-1
master_sync_in_progress:0
master_link_down_since_seconds:1379450797
slave_priority:100
slave_read_only:1
connected_slaves:0

On the master box, I issue info and get

# Replication
role:master
connected_slaves:0

So obviously I'm not connected.

Logs

[11225] 17 Sep 14:31:33.225 * Connecting to MASTER...
[11225] 17 Sep 14:31:33.226 * MASTER <-> SLAVE sync started
[11225] 17 Sep 14:31:33.226 * Non blocking connect for SYNC fired the event.
[11225] 17 Sep 14:31:33.226 * Master replied to PING, replication can continue...
[11225] 17 Sep 14:31:33.227 # MASTER aborted replication with an error: ERR Unable to perform background save

Tests

Test that dump.rdb is created on BGSAVE

BGSAVE
> OK

Test that dump.rdb is created on SAVE

SAVE
> OK

Thanks in advance.

8条回答
Bombasti
2楼-- · 2020-06-07 07:12

I discovered that protected mode was on when I tried to set this up using Redis 5.0.5. When I logged into the putative master on its eth0 interface (as opposed to loopback or UNIX socket) I got this message when I tried to run "INFO":

IP_ADDRESS_REDACTED:6379> info
DENIED Redis is running in protected mode because protected mode is
enabled, no bind address was specified, no authentication password
is requested to clients. In this mode connections are only accepted
from the loopback interface. If you want to connect from external
computers to Redis you may adopt one of the following solutions:
1) Just disable protected mode sending the command 'CONFIG SET 
protected-mode no' from the loopback interface by connecting to Redis
from the same host the server is running, however MAKE SURE Redis is
not publicly accessible from internet if you do so. Use CONFIG REWRITE 
to make this change permanent. 2) Alternatively you can just disable
the protected mode by editing the Redis configuration file, and
setting the protected mode option to 'no', and then restarting the
server. 3) If you started the server manually just for testing,
restart it with the '--protected-mode no' option. 4) Setup a bind
address or an authentication password. NOTE: You only need to do one
of the above things in order for the server to start accepting
connections from the outside.

I followed the instructions and the slave connected immediately.

查看更多
等我变得足够好
3楼-- · 2020-06-07 07:15

For me, it was because I had requirepass set, but did not set a masterauth setting.

查看更多
登录 后发表回答