Home Database Redis How to build a redis cluster under windows

How to build a redis cluster under windows

Mar 05, 2021 am 09:28 AM
redis cluster

How to build a redis cluster under windows

Foreword:

Clustering refers to providing the same service by adding the number of servers, so as to achieve a stable and efficient state. Why use redis cluster? The redis cluster can enhance the reading and writing capabilities of redis.

Now let’s formally learn about redis cluster.

Preparation work:

Requires 4 components: Redis, Ruby language runtime environment, Redis Ruby driver redis-xxxx.gem, and the tool to create a Redis cluster redis-trib.rb. Use the redis-trib.rb tool to create a Redis cluster. Since this file is written in ruby ​​language, you need to install the Ruby development environment and drive redis-xxxx.gem.

How to build a redis cluster under windows

1) Download the Redis installation file: https://github.com/MSOpenTech/redis/releases/, Redis provides download files in msi and zip formats, download zip here Format Redis-x64-3.2.100 version.

2) Download the Ruby installation file: http://dl.bintray.com/oneclick/rubyinstaller/rubyinstaller-2.2.4-x64.exe

3) Download Redis in the Ruby environment Driver: https://rubygems.org/gems/redis/versions/3.2.2. Considering compatibility, the 3.2.2 version is downloaded here.

Note: Download the related link in the lower right corner of the page.中

How to build a redis cluster under windows

4) Download the ruby ​​script file redis-trib.rb officially provided by Redis to create a Redis cluster. The path is as follows: https://raw.githubusercontent.com/MSOpenTech /redis/3.0/src/redis-trib.rb

Install Redis

Just decompress the downloaded Redis-x64-3.2.100.zip. For ease of use, it is recommended to put it in In the root directory of the drive letter, such as: D:\Redis-Cluster\Redis-x64-3.2.100.

Install Redis and run 3 instances (Redis cluster requires at least 3 nodes, less than 3 cannot be created);

Start 6 different Redis instances through configuration files, Since the default port of Redis is 6379, 6380, 6381, 6382, 6383, 6384, and 6385 are used here to run 6 Redis instances.

Note:

(1) In order to avoid unnecessary errors, try to save the configuration file in utf8 format and do not include comments;

(2) The following in the configuration file There are two ways to save logs (save in files and save in System Log). Please choose one according to your needs:

loglevel notice    #日志的记录级别,notice是适合生产环境的
logfile "D:/Redis-Cluster/Redis-x64-3.2.100/Logs/redis6380_log.txt" #指定log的保持路径,默认是创建在Redis安装目录下,如果有子目录需要手动创建,如此处的Logs目录
syslog-enabled yes    #是否使用系统日志   
syslog-ident redis6380    #在系统日志的标识名
Copy after login

The method of saving in files is used here, so first save in the Redis directory Create a new Logs folder under D:\Redis-Cluster\Redis-x64-3.2.100.

In the root directory of the Redis installation, create configuration files with encoding format utf-8: redis.6380.conf, redis.6381.conf, redis.6382.conf, redis.6383.conf, redis. 6384.conf, redis.6385.conf.

redis.6380.conf、

port 6380      
loglevel notice    
logfile "D:/Redis-Cluster/Redis-x64-3.2.100/Logs/redis6380_log.txt"       
appendonly yes
appendfilename "appendonly.6380.aof"   
cluster-enabled yes                                    
cluster-config-file nodes.6380.conf
cluster-node-timeout 15000
cluster-slave-validity-factor 10
cluster-migration-barrier 1
cluster-require-full-coverage yes
Copy after login

redis.6381.conf、

port 6381       
loglevel notice   
logfile "D:/Redis-Cluster/Redis-x64-3.2.100/Logs/redis6381_log.txt"       
appendonly yes
appendfilename "appendonly.6381.aof"    
cluster-enabled yes                                    
cluster-config-file nodes.6381.conf
cluster-node-timeout 15000
cluster-slave-validity-factor 10
cluster-migration-barrier 1
cluster-require-full-coverage yes
Copy after login

redis.6382.conf、

port 6382       
loglevel notice    
logfile "D:/Redis-Cluster/Redis-x64-3.2.100/Logs/redis6382_log.txt"         
appendonly yes
appendfilename "appendonly.6382.aof"    
cluster-enabled yes                                    
cluster-config-file nodes.6382.conf
cluster-node-timeout 15000
cluster-slave-validity-factor 10
cluster-migration-barrier 1
cluster-require-full-coverage yes
Copy after login

redis.6383.conf、

port 6383       
loglevel notice    
logfile "D:/Redis-Cluster/Redis-x64-3.2.100/Logs/redis6383_log.txt"         
appendonly yes
appendfilename "appendonly.6383.aof"    
cluster-enabled yes                                    
cluster-config-file nodes.6383.conf
cluster-node-timeout 15000
cluster-slave-validity-factor 10
cluster-migration-barrier 1
cluster-require-full-coverage yes
Copy after login

redis.6384.conf、

port 6384       
loglevel notice    
logfile "D:/Redis-Cluster/Redis-x64-3.2.100/Logs/redis6384_log.txt"         
appendonly yes
appendfilename "appendonly.6384.aof"    
cluster-enabled yes                                    
cluster-config-file nodes.6384.conf
cluster-node-timeout 15000
cluster-slave-validity-factor 10
cluster-migration-barrier 1
cluster-require-full-coverage yes
Copy after login

redis.6385.conf

port 6385       
loglevel notice    
logfile "D:/Redis-Cluster/Redis-x64-3.2.100/Logs/redis6385_log.txt"         
appendonly yes
appendfilename "appendonly.6385.aof"    
cluster-enabled yes                                    
cluster-config-file nodes.6385.conf
cluster-node-timeout 15000
cluster-slave-validity-factor 10
cluster-migration-barrier 1
cluster-require-full-coverage yes
Copy after login

(Learning video sharing: redis video tutorial)

The configuration is explained as follows:

port 6380                                 #端口号
loglevel notice                           #日志的记录级别,notice是适合生产环境的
logfile "Logs/redis6380_log.txt"          #指定log的保持路径,默认是创建在Redis安装目录下,如果有子目录需要手动创建,如此处的Logs目录
syslog-enabled yes                        #是否使用系统日志
syslog-ident redis6380                    #在系统日志的标识名
appendonly yes                            #数据的保存为aof格式
appendfilename "appendonly.6380.aof"      #数据保存文件
cluster-enabled yes                       #是否开启集群
cluster-config-file nodes.6380.conf
cluster-node-timeout 15000
cluster-slave-validity-factor 10
cluster-migration-barrier 1
cluster-require-full-coverage yes
Copy after login

Save the above configuration files to the Redis directory, and use these configuration files to install 6 A redis service, the command is as follows:

D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-install D:/Redis-Cluster/Redis-x64-3.2.100/redis.6380.conf --service-name redis6380
D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-install D:/Redis-Cluster/Redis-x64-3.2.100/redis.6381.conf --service-name redis6381
D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-install D:/Redis-Cluster/Redis-x64-3.2.100/redis.6382.conf --service-name redis6382
D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-install D:/Redis-Cluster/Redis-x64-3.2.100/redis.6383.conf --service-name redis6383
D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-install D:/Redis-Cluster/Redis-x64-3.2.100/redis.6384.conf --service-name redis6384
D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-install D:/Redis-Cluster/Redis-x64-3.2.100/redis.6385.conf --service-name redis6385
Copy after login

Note:

1) It is best to use the full path for configuration files such as redis.6380.conf to avoid problems when restarting the Redis cluster

2) The uninstall command is:

D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-uninstall D:/Redis-Cluster/Redis-x64-3.2.100/redis.6380.conf --service-name redis6380
D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-uninstall D:/Redis-Cluster/Redis-x64-3.2.100/redis.6381.conf --service-name redis6381
D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-uninstall D:/Redis-Cluster/Redis-x64-3.2.100/redis.6382.conf --service-name redis6382
D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-uninstall D:/Redis-Cluster/Redis-x64-3.2.100/redis.6383.conf --service-name redis6383
D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-uninstall D:/Redis-Cluster/Redis-x64-3.2.100/redis.6384.conf --service-name redis6384
D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-uninstall D:/Redis-Cluster/Redis-x64-3.2.100/redis.6385.conf --service-name redis6385
Copy after login

Start these 6 services. The command is as follows:

D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-start --service-name redis6380
D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-start --service-name redis6381
D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-start --service-name redis6382
D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-start --service-name redis6383
D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-start --service-name redis6384
D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-start --service-name redis6385
Copy after login

Execution result:

How to build a redis cluster under windows

##Install ruby

(1) Ruby environment installation.

Double-click the downloaded "rubyinstaller-2.2.4-x64.exe" to install it. Similarly, for ease of operation, it is recommended to install it in the root directory of the drive letter, such as: C:\Ruby22-x64, install When you select the last two options here,

How to build a redis cluster under windows

means adding ruby ​​to the system's environment variables, and you can use ruby ​​commands directly in the cmd command

(1) Install the Redis driver in the Ruby environment

Copy the downloaded "Redis driver file in the Ruby environment (redis-3.2.2.gem)" to the Ruby installation root directory (C:\Ruby22- x64).

Then execute the installation command as follows:

gem install --local path_to_gem/filename.gem
Copy after login

How to build a redis cluster under windows

Create Redis cluster

Put the downloaded ruby ​​script file redis- trib.rb" file to the Redis installation root directory (D:\Redis-Cluster\Redis-x64-3.2.100).

(1) Use redis-trib.rb to create a Redis cluster

Switch to the Redis directory under MD (D:\Redis-Cluster\Redis-x64-3.2.100)

D:/Redis-Cluster/Redis-x64-3.2.100/redis-trib.rb create --replicas 1 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0. 0.1:6384 127.0.0.1:6385


D:\Redis-Cluster\Redis-x64-3.2.100>redis-trib.rb create --replicas 1 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384 127.0.0.1:6385
>>> Creating cluster
Connecting to node 127.0.0.1:6380: OK
Connecting to node 127.0.0.1:6381: OK
Connecting to node 127.0.0.1:6382: OK
Connecting to node 127.0.0.1:6383: OK
Connecting to node 127.0.0.1:6384: OK
Connecting to node 127.0.0.1:6385: OK
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
127.0.0.1:6380
127.0.0.1:6381
127.0.0.1:6382
Adding replica 127.0.0.1:6383 to 127.0.0.1:6380
Adding replica 127.0.0.1:6384 to 127.0.0.1:6381
Adding replica 127.0.0.1:6385 to 127.0.0.1:6382
M: bb6ef615bb0ae13275943caec0db9d30b9f35c5e 127.0.0.1:6380   slots:0-5460      (5461 slots) master
M: b4d120f2983ad683f7b68992e1ba414722238db7 127.0.0.1:6381   slots:5461-10922  (5462 slots) master
M: 837779b3965e2c9d4dd4385750aaaaf9a9039fb0 127.0.0.1:6382   slots:10923-16383 (5461 slots) master
S: 5d154137180284d926ef51a91fc75f9438249ef8 127.0.0.1:6383   replicates bb6ef615bb0ae13275943caec0db9d30b9f35c5e
S: ad151680a3e36cf2083ef822be0bdb075a7d36de 127.0.0.1:6384   replicates b4d120f2983ad683f7b68992e1ba414722238db7
S: 9a2260a5a6a2add84b622a453a6a7b86a29d180d 127.0.0.1:6385   replicates 837779b3965e2c9d4dd4385750aaaaf9a9039fb0
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join...
>>> Performing Cluster Check (using node 127.0.0.1:6380)M: bb6ef615bb0ae13275943caec0db9d30b9f35c5e 127.0.0.1:6380   slots:0-5460      (5461 slots) master
M: b4d120f2983ad683f7b68992e1ba414722238db7 127.0.0.1:6381   slots:5461-10922  (5462 slots) master
M: 837779b3965e2c9d4dd4385750aaaaf9a9039fb0 127.0.0.1:6382   slots:10923-16383 (5461 slots) master
M: 5d154137180284d926ef51a91fc75f9438249ef8 127.0.0.1:6383   slots:            (0 slots)    master   replicates bb6ef615bb0ae13275943caec0db9d30b9f35c5e
M: ad151680a3e36cf2083ef822be0bdb075a7d36de 127.0.0.1:6384   slots:            (0 slots)    master   replicates b4d120f2983ad683f7b68992e1ba414722238db7
M: 9a2260a5a6a2add84b622a453a6a7b86a29d180d 127.0.0.1:6385   slots:            (0 slots)    master   replicates 837779b3965e2c9d4dd4385750aaaaf9a9039fb0
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
Copy after login

Remarks:

(1)--replicas #指定集群中每个主节点配备几个从节点,这里设置为1。

(2)redis-trib.rb工具的使用

、create:创建集群
、check:检查集群
、info:查看集群信息
、fix:修复集群
、reshard:在线迁移slot
、rebalance:平衡集群节点slot数量
、add-node:将新节点加入集群
、del-node:从集群中删除节点
、set-timeout:设置集群节点间心跳连接的超时时间
、call:在集群全部节点上执行命令
、import:将外部redis数据导入集群
Copy after login

(2)检验是否真的创建成功

输入以下命令:

redis-trib.rb check 127.0.0.1:6380
Copy after login

如果现实信息如下,则说明创建的Redis集群是没问题。

D:\Redis-Cluster\Redis-x64-3.2.100>redis-trib.rb check 127.0.0.1:6380
Connecting to node 127.0.0.1:6380: OK
Connecting to node 127.0.0.1:6383: OK
Connecting to node 127.0.0.1:6382: OK
Connecting to node 127.0.0.1:6384: OK
Connecting to node 127.0.0.1:6385: OK
Connecting to node 127.0.0.1:6381: OK
>>> Performing Cluster Check (using node 127.0.0.1:6380)
M: bb6ef615bb0ae13275943caec0db9d30b9f35c5e 127.0.0.1:6380   slots:0-5460      (5461 slots) master   1 additional replica(s)
S: 5d154137180284d926ef51a91fc75f9438249ef8 127.0.0.1:6383   slots:            (0 slots)    slave    replicates bb6ef615bb0ae13275943caec0db9d30b9f35c5e
M: 837779b3965e2c9d4dd4385750aaaaf9a9039fb0 127.0.0.1:6382   slots:10923-16383 (5461 slots) master   1 additional replica(s)
S: ad151680a3e36cf2083ef822be0bdb075a7d36de 127.0.0.1:6384   slots:            (0 slots)    slave    replicates b4d120f2983ad683f7b68992e1ba414722238db7
S: 9a2260a5a6a2add84b622a453a6a7b86a29d180d 127.0.0.1:6385   slots:            (0 slots)    slave    replicates 837779b3965e2c9d4dd4385750aaaaf9a9039fb0
M: b4d120f2983ad683f7b68992e1ba414722238db7 127.0.0.1:6381   slots:5461-10922  (5462 slots) master   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

D:\Redis-Cluster\Redis-x64-3.2.100>
Copy after login

(3)信息查询

使用Redis客户端Redis-cli.exe来查看数据记录数,以及集群相关信息

How to build a redis cluster under windows

原文作者:cctext

原文链接:https://www.cnblogs.com/yy3b2007com/p/11033009.html

相关推荐:redis数据库教程

The above is the detailed content of How to build a redis cluster under windows. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to build the redis cluster mode How to build the redis cluster mode Apr 10, 2025 pm 10:15 PM

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

How to clear redis data How to clear redis data Apr 10, 2025 pm 10:06 PM

How to clear Redis data: Use the FLUSHALL command to clear all key values. Use the FLUSHDB command to clear the key value of the currently selected database. Use SELECT to switch databases, and then use FLUSHDB to clear multiple databases. Use the DEL command to delete a specific key. Use the redis-cli tool to clear the data.

How to use the redis command How to use the redis command Apr 10, 2025 pm 08:45 PM

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).

How to use redis lock How to use redis lock Apr 10, 2025 pm 08:39 PM

Using Redis to lock operations requires obtaining the lock through the SETNX command, and then using the EXPIRE command to set the expiration time. The specific steps are: (1) Use the SETNX command to try to set a key-value pair; (2) Use the EXPIRE command to set the expiration time for the lock; (3) Use the DEL command to delete the lock when the lock is no longer needed.

How to read redis queue How to read redis queue Apr 10, 2025 pm 10:12 PM

To read a queue from Redis, you need to get the queue name, read the elements using the LPOP command, and process the empty queue. The specific steps are as follows: Get the queue name: name it with the prefix of "queue:" such as "queue:my-queue". Use the LPOP command: Eject the element from the head of the queue and return its value, such as LPOP queue:my-queue. Processing empty queues: If the queue is empty, LPOP returns nil, and you can check whether the queue exists before reading the element.

How to use single threaded redis How to use single threaded redis Apr 10, 2025 pm 07:12 PM

Redis uses a single threaded architecture to provide high performance, simplicity, and consistency. It utilizes I/O multiplexing, event loops, non-blocking I/O, and shared memory to improve concurrency, but with limitations of concurrency limitations, single point of failure, and unsuitable for write-intensive workloads.

How to implement the underlying redis How to implement the underlying redis Apr 10, 2025 pm 07:21 PM

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.

How to read the source code of redis How to read the source code of redis Apr 10, 2025 pm 08:27 PM

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.

See all articles