Home  >  Article  >  Operation and Maintenance  >  Configure redis sentinel mode under window

Configure redis sentinel mode under window

little bottle
little bottleforward
2019-04-29 10:28:594709browse

1. First make two copies of the redis you downloaded. Mine are named as follows

Create a folder under the D drive, I named it redis

  • Redis-master
  • Redis-slave1
  • Redis-slave2

2. Modify the configuration file

  • 2.1 Modify the redis-master configuration file redis.windows.conf

  • port 6379

  • bind 127.0.0.1

2.2 Modify redis-slave1 and Configuration file of redis-slave2

  • Configuration file of redis-slave1
port 6380
bind 127.0.0.1
slaveof 127.0.0.1 6379
#redis-slave2的配置文件
port 6381
bind 127.0.0.1
slaveof 127.0.0.1 6379

3. Create new sentinel configuration files and name them

sentinel.conf 
sentinel26479.conf
sentinel26579.conf

Sentinel configuration file content
sentinel.conf

port 26379
#master
sentinel monitor master 127.0.0.1 6380 1
sentinel down-after-milliseconds master 5000
sentinel config-epoch master 1
sentinel leader-epoch master 1

sentinel26479.conf

port 26479
#slave1
sentinel monitor master 127.0.0.1 6380 1
sentinel down-after-milliseconds master 5000
sentinel config-epoch master 1
sentinel leader-epoch master 1

sentinel26579.conf

port 26579
#slave1
sentinel monitor master 127.0.0.1 6380 1
sentinel down-after-milliseconds master 5000
sentinel config-epoch master 1
sentinel leader-epoch master 1

Sentinel configuration file description

1. port :当前Sentinel服务运行的端口  
2.sentinel monitor mymaster 127.0.0.1 6379 2:Sentinel去监视一个名为mymaster的主redis实例,这个主实例的IP地址为本机地址127.0.0.1,端口号为6379,而将这个主实例判断为失效至少需要2个 Sentinel进程的同意,只要同意Sentinel的数量不达标,自动failover就不会执行  
3.sentinel down-after-milliseconds mymaster 5000:指定了Sentinel认为Redis实例已经失效所需的毫秒数。当 实例超过该时间没有返回PING,或者直接返回错误,那么Sentinel将这个实例标记为主观下线。只有一个 Sentinel进程将实例标记为主观下线并不一定会引起实例的自动故障迁移:只有在足够数量的Sentinel都将一个实例标记为主观下线之后,实例才会被标记为客观下线,这时自动故障迁移才会执行  
4.sentinel parallel-syncs mymaster 1:指定了在执行故障转移时,最多可以有多少个从Redis实例在同步新的主实例,在从Redis实例较多的情况下这个数字越小,同步的时间越长,完成故障转移所需的时间就越长  
5.sentinel failover-timeout mymaster 15000:如果在该时间(ms)内未能完成failover操作,则认为该failover失败

4. That’s all the configuration files. Let’s test to see if it’s successful

4.1 Start each redis service separately

redis-server.exe redis.windows.conf

4.2 Then start the client service under each redis respectively, corresponding to the following commands respectively

redis-cli.exe -h 127.0.0.1 -p 6379
redis-cli.exe -h 127.0.0.1 -p 6380
redis-cli.exe -h 127.0.0.1 -p 6381

Test whether the data is synchronized, enter it on the master client
I set a key as li in the master, The value is kaixuan

. You can see that both slave machines have synchronized data. When I try to write data on the slave machine, it is not allowed. It tells me that it is read-only, so the data can only be written from the master machine. Enter, so as to achieve read and write separation
Configure redis sentinel mode under window
5. We start 3 sentinels

The commands are as follows

redis-server.exe sentinel.conf --sentinel
redis-server.exe sentinel26479.conf --sentinel
redis-server.exe sentinel26579.conf --sentinel

The following tests the master and slave Switching

But after my host hangs up, whether the slave can successfully become the host

Check the current redis status first

Enter

on the client respectively
info replication

Configure redis sentinel mode under window
Now down the host
Configure redis sentinel mode under window
We found that the slave with port 6380 has now become the host, indicating that our sentinel has worked, OK!

Related tutorials: redis video tutorial

The above is the detailed content of Configure redis sentinel mode under window. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete