Lets try to set sentinel for redis in windows machine.
Copy past the redis-windows.conf in to two new files redis-windows1.conf and redis-windows2.conf and make these changes in it
1:- redis-windows1.conf
port 6380
slaveof 127.0.0.1 6379
2:- redis-windows2.conf
port 6381
slaveof 127.0.0.1 6379
create a sentinel.conf and add following line. Make sure to make this files as read only else when you start sentinel service it will be overwritten and your sentinel service will not be started properly.
1:- sentinel.conf
1 2 3 4 5 6 7 | port 26379 sentinel monitor Redis_Master 127.0.0.1 6379 1 sentinel down-after-milliseconds Redis_Master 30000 sentinel parallel-syncs Redis_Master 1 sentinel failover-timeout Redis_Master 180000 logfile "C:/redis-windows/sentinel_26379.log" syslog-enabled yes |
1 2 3 4 5 6 7 8 9 10 11 | C:\Windows\system32>sc create Redis_Master DisplayName="Redis_Master" binPath= "\"C:\redis-windows\redis-server.exe\" --service-run \"C:\redis-windows\redis-windows.conf\" [SC] CreateService SUCCESS C:\Windows\system32>sc create Redis_Slave1 DisplayName="Redis_Slave1" binPath= "\"C:\redis-windows\redis-server.exe\" --service-run \"C:\redis-windows\redis-windows1.conf\" [SC] CreateService SUCCESS C:\Windows\system32>sc create Redis_Slave2 DisplayName="Redis_Slave2" binPath= "\"C:\redis-windows\redis-server.exe\" --service-run \"C:\redis-windows\redis-windows2.conf\" [SC] CreateService SUCCESS C:\Windows\system32>sc create Redis_Sentinel DisplayName="Redis_Sentinel" binPath= "\"C:\redis-windows\redis-server.exe\" --service-run \"C:\redis-windows\sentinel.conf\" --sentinel [SC] CreateService SUCCESS |
Start all the service
C:\Windows\system32>net start Redis_Master
The Redis_Master service is starting.
The Redis_Master service was started successfully.
C:\Windows\system32>net start Redis_Slave1
The Redis_Slave1 service is starting.
The Redis_Slave1 service was started successfully.
C:\Windows\system32>net start Redis_Slave2
The Redis_Slave2 service is starting.
The Redis_Slave2 service was started successfully.
C:\Windows\system32>net start Redis_Sentinel
The Redis_Sentinel service is starting.
The Redis_Sentinel service was started successfully.
Check sentinel is ruuning using below command
1 2 3 4 5 6 7 8 9 10 | C:\Windows\system32>redis-cli -p 26379 info sentinel # Sentinel sentinel_masters:1 sentinel_tilt:0 sentinel_running_scripts:0 sentinel_scripts_queue_length:0 sentinel_simulate_failure_flags:0 master0:name=Redis_Master,status=ok,address=127.0.0.1:6379,slaves=0,sentinels=1 C:\Windows\system32> |
To check which is master node use belwo command
C:\Windows\system32>redis-cli -p 26379 sentinel get-master-addr-by-name Redis_Master
1) “127.0.0.1”
2) “6379”
C:\Windows\system32>net stop Redis_Master
The Redis_Master service was stopped successfully.
Now stop Redis_Master service from Windows Services. Execute the above command again after 30 seconds. You can see that one of the slaves is re-configured as Master.
C:\Windows\system32>redis-cli -p 26379 sentinel get-master-addr-by-name Redis_Master
1) “127.0.0.1”
2) “6380”
1 2 3 4 5 6 7 8 9 | Note:- To delete service in windows use below command and always run the cmd in administrators mode. sc delete Redis_Master DisplayName="Redis_Master" binPath= "\"C:\redis-windows\redis-server.exe\" –-service-run \"C:\redis-windows\redis-windows.conf\" sc delete Redis_Slave1 DisplayName="Redis_Slave1" binPath= "\"C:\redis-windows\redis-server.exe\" –-service-run \"C:\redis-windows\redis-windows1.conf\" sc delete Redis_Slave2 DisplayName="Redis_Slave2" binPath= "\"C:\redis-windows\redis-server.exe\" –-service-run \"C:\redis-windows\redis-windows1.conf\" sc delete Redis_Sentinel DisplayName="Redis_Sentinel" binPath= "\"C:\redis-windows\redis-server.exe\" –-service-run \"C:\redis-windows\sentinel.conf\" –-sentinel |
No comments:
Post a Comment