


Configure redis sentinel mode under window
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
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 respectivelyinfo replication
Now down the host
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Redis cluster mode deploys Redis instances to multiple servers through sharding, improving scalability and availability. The construction steps are as follows: Create odd Redis instances with different ports; Create 3 sentinel instances, monitor Redis instances and failover; configure sentinel configuration files, add monitoring Redis instance information and failover settings; configure Redis instance configuration files, enable cluster mode and specify the cluster information file path; create nodes.conf file, containing information of each Redis instance; start the cluster, execute the create command to create a cluster and specify the number of replicas; log in to the cluster to execute the CLUSTER INFO command to verify the cluster status; make

Redis uses hash tables to store data and supports data structures such as strings, lists, hash tables, collections and ordered collections. Redis persists data through snapshots (RDB) and append write-only (AOF) mechanisms. Redis uses master-slave replication to improve data availability. Redis uses a single-threaded event loop to handle connections and commands to ensure data atomicity and consistency. Redis sets the expiration time for the key and uses the lazy delete mechanism to delete the expiration key.

Steps to solve the problem that redis-server cannot find: Check the installation to make sure Redis is installed correctly; set the environment variables REDIS_HOST and REDIS_PORT; start the Redis server redis-server; check whether the server is running redis-cli ping.

To view all keys in Redis, there are three ways: use the KEYS command to return all keys that match the specified pattern; use the SCAN command to iterate over the keys and return a set of keys; use the INFO command to get the total number of keys.

The best way to understand Redis source code is to go step by step: get familiar with the basics of Redis. Select a specific module or function as the starting point. Start with the entry point of the module or function and view the code line by line. View the code through the function call chain. Be familiar with the underlying data structures used by Redis. Identify the algorithm used by Redis.

To view the Redis version number, you can use the following three methods: (1) enter the INFO command, (2) start the server with the --version option, and (3) view the configuration file.

Using the Redis directive requires the following steps: Open the Redis client. Enter the command (verb key value). Provides the required parameters (varies from instruction to instruction). Press Enter to execute the command. Redis returns a response indicating the result of the operation (usually OK or -ERR).

The following two methods can be used to clear data in Redis: FLUSHALL command: Delete all keys and values in the database. CONFIG RESETSTAT command: Reset all states of the database (including keys, values, and other statistics).
