Redis dump file prevents slave mode - redis

I have a redis master and slave configuration. What I'm finding is that if I restart the slave while there is a dump.rdb file in the directory, the instance starts as a master with no connected slaves rather than obeying the slaveof command in the config file. If I restart the service after deleting the dump.rdb, then the slave will come back online and connect to the master as expected.
Is this expected behavior? If so, is there a way to allow a slave to be restarted and go directly into slave mode?
Edit: This is running on Windows.

Related

how to check the message published from redis sentinel to redis master?

Question Background:
I deploy a redis cluster in k8s cluster and use Redis-Sentinel to implement ha for redis cluster. My redis cluster structure likes below:
One master
One slave
three sentinel (serve a specific redis cluster)
When i login the container of the one of sentinels, i execute a command:
sentinel sentinels mymaster
Luckly, i get a desirable output. These are two sentinel's infos. After a period of time, i execute "sentinels mymaster" command again, i found that there is a additional sentinel and don't find this instance through IP address or runId。
I know that sentinel discover other sentinels and master and slave through sub the channel of sentinel:hello in redis master.
Question:
how to check the message published from redis sentinel to redis master? I have opened log for master and set the log level to debug.
You can see the Sentinel's activity (when it discovers a sentinel, a replica, failsover to a new master, etc.) in the sentinel log file, not the master. If a sentinel is running on a host, it will be in the same directory the master or replica log file is. For me on CentOS it's /var/log/redis/sentinel.log.

Correct shutdown sequence for Redis cluster

Suppose I have the following Redis replication setup:
3 machines
Each machine has a Redis server and a Redis sentinel.
One of the servers is set as master, the other two are its slaves.
What would be the correct sequence and commands to gracefully shutdown this setup, all while keeping the existing master as master and existing slaves as slaves (meaning, no failover or reconfig should take place)
Thanks.
Shutdown sequence
You should shutdown sentinels first, to avoid alarms/notifications and failover. Then you can shutdown slaves and master.
Shutdown command
You can gracefully shutdown Redis instances (sentinel, slave and master) with the shutdown command.
For Redis version older than 3.0 (not very sure), there's no shutdown command for Redis sentinel. But you can just use killall or kill -9 process_id to kill it without any side effect.
============================================================================
UPDATE
In my original answer, I suggested shutdown slaves and master first, to avoid alarms from sentinel. In fact, there's another way to avoid alarms. You can simply remove the master from sentinel before shutdown the master: SENTINEL REMOVE <name>. After removing the master, you don't need to care the shutdown order any more.
How about the startup order?
If you use SENTINEL MONITOR <name> <ip> <port> <quorum> command to dynamically add a master to monitor, you can startup sentinel, and add masters dynamically. Instead, if you add the master with sentinel's configuration file, you can startup Redis first, to avoid alarms from sentinel.

Sentinel work fail after rename config command of redis

I've installed stablest redis(ver 3.2). Everything work fine until I renamed CONFIG command of redis, sentinel could not promote slave to be master.
Think the problem is sentinel still use CONFIG command (has been renamed) to change configuration of redis.
Is there any way to change configuration of sentinel (via redis-cli or configuration files sentinel.conf) to adapt redis configuration (renamed config command). If there isn't, how about changing source code?
Thanks
After google, I found solution for this problem.
I replace redis/src/sentinel.c via this redis github, rebuild and install redis from source.
Then I could add a directive to sentinel.conf to configure sentinel use renamed config command.
sentinel config-command mymaster <renamed-command>

Redis.conf for slave with sentinel

Should I use exact mirror of redis.conf on slave, if it would be promoted as master when failover activates.
For example should I appendonly yes to slave ?
The slaves configuration are different than the master one, so you will need to have 1 config file per server, plus one sentinel config file. Here you have a nice tutorial to make it work (basically) https://seanmcgary.com/posts/how-to-build-a-fault-tolerant-redis-cluster-with-sentinel

Redis master/slave replication - single point of failure?

How does one upgrade to a newer version of Redis with zero downtime? Redis slaves are read-only, so it seems like you'd have to take down the master and your site would be read-only for 45 seconds or more while you waited for it to reload the DB.
Is there a way around this?
Redis Team has very good documentation on this
Core Steps:
Setup your new Redis instance as a slave for your current Redis instance. In order to do so you need a different server, or a server that has enough RAM to keep two instances of Redis running at the same time.
If you use a single server, make sure that the slave is started in a different port than the master instance, otherwise the slave will not be able to start at all.
Wait for the replication initial synchronization to complete (check the slave log file).
Make sure using INFO that there are the same number of keys in the master and in the slave. Check with redis-cli that the slave is working as you wish and is replying to your commands.
Configure all your clients in order to use the new instance (that is, the slave).
Once you are sure that the master is no longer receiving any query (you can check this with the MONITOR command), elect the slave to master using the SLAVEOF NO ONE command, and shut down your master.
Full Documentation:
Upgrading or restarting a Redis instance without downtime
When taking the node offline, promote the slave to master using the SLAVEOF command, then when you bring it back online you set it up as a slave and it will copy all data from the online node.
You may also need to make sure your client can handle changed/missing master nodes appropriately.
If you want to get really fancy, you can set up your client to promote a slave if it detects an error writing to the master.
You can use Redis Sentinel for doing this, the sentinel will automatically promote a slave as new master.
you can find more info here http://redis.io/topics/sentinel.
Sentinel is a system used to manage redis servers , it monitors the redis master and slaves continuously, and whenever a master goes down it will automatically promote a slave in to master. and when the old master is UP it will be made as slave of the new master.
Here there will be no downtime or manual configuration of config file is needed.
You can visit above link to find out how to configure sentinel for your redis servers.
Note, you may have to check and set the following config to write to your slave.
("Since Redis 2.6 by default slaves are read-only")
redis-cli config set slave-read-only no
-- Example
-bash-4.1$ redis-cli info
Server
redis_version:2.6.9
-bash-4.1$ redis-cli slaveof admin2.mypersonalsite.com 6379
OK
-bash-4.1$ redis-cli set temp 42
(error) READONLY You can't write against a read only slave.
-bash-4.1$ redis-cli slaveof no one
OK
-bash-4.1$ redis-cli set temp 42
OK
-bash-4.1$ redis-cli get temp
"42"
-bash-4.1$ redis-cli config set slave-read-only no
OK
-bash-4.1$ redis-cli slaveof admin2.mypersonalsite.com 6379
OK
-bash-4.1$ redis-cli set temp 42
OK
-bash-4.1$ redis-cli get temp
"42"