Migrate Redis Node

Note of migrating redis from srv17 to srv16

redis.conf

Note: everything needed - do not forget correct ip address into bind

bind 192.168.0.16
port 6379
notify-keyspace-events "AKE"
maxmemory 9765625kb
maxmemory-policy allkeys-lru
slave-read-only yes
repl-diskless-sync yes

Redis service

Install service

C:\\Redis-x64-3.2.100> redis-server.exe --service-install C:\\Redis-x64-3.2.100\\redis.conf

[4132] 17 May 10:59:21.136 # Granting read/write access to 'NT AUTHORITY\NetworkService' on: "C:\Redis-x64-3.2.100" "C:\Redis-x64-3.2.100\"

[4132] 17 May 10:59:21.137 # Redis successfully installed as a service.

Start service

C:\\Redis-x64-3.2.100> redis-server.exe --service-start

[1508] 17 May 11:04:19.567 # Redis service successfully started.

Check if redis is alive

C:\\Redis-x64-3.2.100> redis-cli -h srv16 ping

PONG

sentinel.conf

Note: same way as with redis - do not forget to change bind

bind 192.168.0.16
port 26379

Sentinel service

Install service

C:\Redis-x64-3.2.100> redis-server.exe --service-install --service-name redissentinel C:\Redis-x64-3.2.100\sentinel.conf --sentinel

[5144] 17 May 11:22:07.334 # Granting read/write access to 'NT AUTHORITY\NetworkService' on: "C:\Redis-x64-3.2.100" "C:\Redis-x64-3.2.100\"

[5144] 17 May 11:22:07.335 # Redis successfully installed as a service.

Start service

C:\Redis-x64-3.2.100> sc start redissentinel

SERVICE_NAME:  redissentinel
        TYPE:  10  WIN32_OWN_PROCESS
        STATE:  4  RUNNING

Check if whitnes is alive

C:\Redis-x64-3.2.100> redis-cli -h srv16 -p 26379 ping

PONG

Note: i was not able to start/delete servicevia redis-server by its name, to delete use sc delete redissentinel

Slave

Added to redis.conf line slaveof 192.168.0.17 6379 (srv17 was master at moment) and restarted service, now srv16 is slave of srv17

Role srv17

C:\Redis-x64-3.2.100> redis-cli -h srv16 info replication | findstr role

role:slave

Who is master right now:

C:\Redis-x64-3.2.100> redis-cli -h srv16 info replication | findstr master_host

master_host:192.168.0.17

Sentinel

Start monitoring mycluster, saying who is master now, his port and number of nodes in quorum

C:\Redis-x64-3.2.100> redis-cli -h srv16 -p 26379 sentinel monitor mycluster 192.168.0.17 6379 2

OK

Check if sentinel sees master

C:\Redis-x64-3.2.100> redis-cli -h srv16 -p 26379 sentinel get-master-addr-by-name mycluster

1. "192.168.0.17"
2. "6379"

Adding configuration changes

C:\Redis-x64-3.2.100> redis-cli -h srv16 -p 26379 sentinel set mycluster down-after-milliseconds 5000

OK

Check if we have quorum

C:\Redis-x64-3.2.100> redis-cli -h srv16 -p 26379 sentinel ckquorum mycluster

OK 4 usable Sentinels. Quorum and failover authorization can be reached

Save configs

Now, when everyhing is configured, we need flush settings to the disk

C:\Redis-x64-3.2.100> redis-cli -h srv16 config rewrite

OK

C:\Redis-x64-3.2.100> redis-cli -h srv16 -p 26379 sentinel flushconfig

OK

Note: if everything is ok, in both configs you will see bunch of new lines right after "Generated by CONFIG REWRITE" comment

Failover

Because removed node is master right now - we should make manual failover, but before check if we have quorum

# Step 1: Check who is master
redis-cli -h srv16 -p 26379 sentinel get-master-addr-by-name mycluster

# Step 2: check is quorum ok
redis-cli -h srv16 -p 26379 sentinel ckquorum mycluster

# Step 3: manual failover
redis-cli -h srv16 -p 26379 sentinel failover mycluster

# Step 4: Check who is master
redis-cli -h srv16 -p 26379 sentinel get-master-addr-by-name mycluster

# Turn off SRV16
sc stop redis
sc stop redissentinel
sc delete redis
sc delete redissentinel

Note: i was running them one by one, because it was quite scarry operation

Then shutdown redis and wait for a while

C:\\Redis-x64-3.2.100> redis-cli -h srv12 info replication

# Replication
role:master
connected_slaves:2
slave0:ip=192.168.0.16,port=6379,state=online,offset=3206080046244,lag=0
slave1:ip=192.168.0.15,port=6379,state=online,offset=3206079599208,lag=1

Then shutdown sentinel

C:\Redis-x64-3.2.100> redis-cli -h srv16 -p 26379 sentinel ckquorum mycluster

OK 3 usable Sentinels. Quorum and failover authorization can be reached

Forget old nodes

Sentinel will remember about old srv17 and wait for it to come back. To delete it forever you need to run following commands:

C:\Redis-x64-3.2.100> redis-cli -h srv16 -p 26379 sentinel reset mycluster

(integer) 1

C:\Redis-x64-3.2.100> redis-cli -h srv16 -p 26379 sentinel flushconfig

OK

C:\Redis-x64-3.2.100> redis-cli -h srv12 -p 26379 sentinel reset mycluster

(integer) 1

C:\Redis-x64-3.2.100> redis-cli -h srv12 -p 26379 sentinel flushconfig

OK

C:\Redis-x64-3.2.100> redis-cli -h drum -p 26379 sentinel reset mycluster

(integer) 1

C:\Redis-x64-3.2.100> redis-cli -h drum -p 26379 sentinel flushconfig

OK

Restore?

Theoretically, if we need to rollback everyhing - we gonna need to cleanup configs, start services, connect back to the cluster and everything should work