Home Database Redis Example of building a redis cluster under Windows

Example of building a redis cluster under Windows

Dec 03, 2019 pm 05:06 PM
redis windows

Example of building a redis cluster under Windows

Redis Cluster:

If deployed to multiple computers, it will be the same as a normal cluster; because Redis is single-threaded and multi-core The CPU can only use one core, so if it is deployed on the same computer and runs multiple Redis instances to form a cluster, the CPU utilization can be improved.

Recommended:

redis video tutorial

Build a Redis cluster under Windows system:

Requires 4 components:

Redis, Ruby language operating environment, Redis Ruby driver redis-xxxx.gem, tool for creating Redis cluster redis-trib.rb

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

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 driver. redis-xxxx.gem

1. Download and install Redis

The GitHub path is as follows: https://github.com/MSOpenTech/redis/releases/

Redis provides Download files in msi and zip formats. Download zip format version 3.0.504 here.

Just decompress the downloaded Redis-x64-3.0.504.zip. For ease of use, it is recommended to place it in the root directory of the drive letter. Next, and change the directory name to Redis, such as: C:\Redis or D:\Redis

Start 3 different Redis instances through the configuration file. Since the default port of Redis is 6379, 6380 is used here. , 6381, and 6382 to run 3 Redis instances.

Note: In order to avoid unnecessary errors, try to save the configuration file in utf8 format and do not contain comments;

There are two ways to save logs in the configuration file (save in file, Save to System Log) Please choose one of them according to your needs:

loglevel notice                 #The recording level of the log, notice is suitable for the production environment

logfile "D:/ Redis/Logs/redis6380_log.txt" #Specify the path to keep the log. The default is to create it in the Redis installation directory. If there are subdirectories, you need to create them manually, such as the Logs directory here

syslog-enabled yes #Whether to use System log

syslog-ident redis6380 #In the identification name of the system log

, the method of saving in a file is used, so first create a new Logs under the Redis directory D:/Redis The contents of the folder


redis.6380.conf are as follows:

port 6380      
loglevel notice    
logfile "D:/Redis/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

The contents of redis.6381.conf are as follows:

port 6381       
loglevel notice   
logfile "D:/Redis/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 The contents are as follows:

port 6382       
loglevel notice    
logfile "D:/Redis/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

The configuration content 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 3 redis services. The command is as follows:

Note : It is best to use the full path for configuration files such as redis.6380.conf to avoid problems when restarting the Redis cluster. The blogger’s installation directory is D:/Redis

D:/Redis/redis-server.exe --service-install D:/Redis/redis.6380.conf --service-name redis6380
D:/Redis/redis-server.exe --service-install D:/Redis/redis.6381.conf --service-name redis6381
D:/Redis/redis-server.exe --service-install D:/Redis/redis.6382.conf --service-name redis6382
Copy after login

To start these three services, the command is as follows:

D:/Redis/redis-server.exe --service-start --service-name Redis6380
D:/Redis/redis-server.exe --service-start --service-name Redis6381
D:/Redis/redis-server.exe --service-start --service-name Redis6382
Copy after login

Execution result:

##2. Download and install rubyExample of building a redis cluster under Windows

2.1. The download path is as follows:

http:/ /dl.bintray.com/oneclick/rubyinstaller/rubyinstaller-2.2.4-x64.exe

After downloading, double-click to install. Similarly, for ease of operation, it is recommended to install it in the root directory of the drive letter. For example: C:\Ruby22-x64, select the last two options here during installation,

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

2.2. Download the Redis driver in ruby ​​environment. Considering compatibility, the download here is version 3.2.2Example of building a redis cluster under Windows

https://rubygems.org/gems/ redis/versions/3.2.2

Note: Download the driver in the related link item in the lower right corner of the page

The command is as follows:

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

Actual operation As follows: Example of building a redis cluster under Windows

2.3. Download the ruby ​​script file redis-trib.rb officially provided by Redis to create a Redis cluster. The path is as follows: Example of building a redis cluster under Windows

https:// raw.githubusercontent.com/MSOpenTech/redis/3.0/src/redis-trib.rb

If you open this link instead of downloading, but open a page, then save the page as redis-trib.rb

It is recommended to save it to the Redis directory.

注意:因为redis-trib.rb是ruby代码,必须用ruby来打开,若redis-trib.rb无法识别,需要手动选择该文件的打开方式:

Example of building a redis cluster under Windows

Example of building a redis cluster under Windows

**选择ruby为的打开方式后,redis-trib.rb的logo都会发生改变,如下图:

Example of building a redis cluster under Windows

3.创建Redis集群

CMD下切换到Redis目录,使用redis-trib.rb来创建Redis集群:

redis-trib.rb create --replicas 0 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382
Copy after login

执行结果:

Example of building a redis cluster under Windows

Example of building a redis cluster under Windows

检验是否真的创建成功,输入以下命令:

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

出现以下信息,说明创建的Redis集群是没问题的

1Example of building a redis cluster under Windows

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

D:/Redis/redis-cli.exe -c -p 6380
Copy after login

-c 表示 cluster

-p 表示 port 端口号

1Example of building a redis cluster under Windows

输入dbsize查询 记录总数

dbsize
Copy after login

或者一次输入完整命令:

D:/Redis/redis-cli.exe -c -p 6380 dbsize
Copy after login

结果如下:

1Example of building a redis cluster under Windows

输入cluster info可以从客户端的查看集群的信息:

cluster info
Copy after login

结果如下:

Example of building a redis cluster under Windows

更多redis知识请关注redis使用教程栏目。

The above is the detailed content of Example of building 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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

Can vs code run in Windows 8 Can vs code run in Windows 8 Apr 15, 2025 pm 07:24 PM

VS Code can run on Windows 8, but the experience may not be great. First make sure the system has been updated to the latest patch, then download the VS Code installation package that matches the system architecture and install it as prompted. After installation, be aware that some extensions may be incompatible with Windows 8 and need to look for alternative extensions or use newer Windows systems in a virtual machine. Install the necessary extensions to check whether they work properly. Although VS Code is feasible on Windows 8, it is recommended to upgrade to a newer Windows system for a better development experience and security.

How to run sublime after writing the code How to run sublime after writing the code Apr 16, 2025 am 08:51 AM

There are six ways to run code in Sublime: through hotkeys, menus, build systems, command lines, set default build systems, and custom build commands, and run individual files/projects by right-clicking on projects/files. The build system availability depends on the installation of Sublime Text.

How to solve complex BelongsToThrough relationship problem in Laravel? Use Composer! How to solve complex BelongsToThrough relationship problem in Laravel? Use Composer! Apr 17, 2025 pm 09:54 PM

In Laravel development, dealing with complex model relationships has always been a challenge, especially when it comes to multi-level BelongsToThrough relationships. Recently, I encountered this problem in a project dealing with a multi-level model relationship, where traditional HasManyThrough relationships fail to meet the needs, resulting in data queries becoming complex and inefficient. After some exploration, I found the library staudenmeir/belongs-to-through, which easily installed and solved my troubles through Composer.

vscode cannot install extension vscode cannot install extension Apr 15, 2025 pm 07:18 PM

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

Can vscode be used for mac Can vscode be used for mac Apr 15, 2025 pm 07:36 PM

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

laravel installation code laravel installation code Apr 18, 2025 pm 12:30 PM

To install Laravel, follow these steps in sequence: Install Composer (for macOS/Linux and Windows) Install Laravel Installer Create a new project Start Service Access Application (URL: http://127.0.0.1:8000) Set up the database connection (if required)

How to use the Redis cache solution to efficiently realize the requirements of product ranking list? How to use the Redis cache solution to efficiently realize the requirements of product ranking list? Apr 19, 2025 pm 11:36 PM

How does the Redis caching solution realize the requirements of product ranking list? During the development process, we often need to deal with the requirements of rankings, such as displaying a...

Can vscode run in Windows 7 Can vscode run in Windows 7 Apr 15, 2025 pm 07:27 PM

VS Code is still available on Windows 7, but is highly not recommended. Windows 7 lacks security updates and patches, resulting in security risks and VS Code compatibility issues. Although simple code editing is barely competent, it is recommended to upgrade to Windows 10 or later for complex development or for extensions.

See all articles