Redis clustered Redis cluster under windows:
If you deploy to more than one computer, it is the same as a normal cluster; Because Redis is single-threaded, multicore CPUs can only use a single core,
So on the same computer, you can increase CPU utilization by running multiple Redis instances and composing the instances into a cluster.
To build a Redis cluster under Windows system:
4 Parts Required:
Redis, Ruby language runtime, Redis's Ruby driver Redis-3.2.2.gem, the tools to create Redis clusters redis-trib.rb
Install Redis and run 3 instances (Redis cluster requires at least 3 nodes, less than 3 cannot be created);
Use the REDIS-TRIB.RB tool to create a Redis cluster, because the file is written in Ruby, so you need to install the Ruby development environment and drive Redis-3.2.2.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 format, here download Zip format 3.0.504 Version
The download to the Redis-x64-3.0.504.zip decompression, in order to facilitate the use of the directory name to Redis, and placed in the D packing directory (D:/redis),
The configuration file launches 3 different Redis instances, and because the Redis default port is 6379, it uses 6380, 6381, and 6382来 to run 3 Redis instances.
Note: To avoid unnecessary errors, save the configuration file in UTF8 format and do not include annotations;
To record Redis logs, you need to create a new logs folder under Redis directory D:/redis
Redis.6380.conf content is as follows:
Port 6380 loglevel Notice logfile "d:/redis/logs/redis6380_log.txt" appendonly yesappendfilename " Appendonly.6380.aof " cluster-enabled Yes cluster-config-file nodes.6380.confcluster-node-timeout 15000cluster-slave-validity-factor 10cluster-migration-barrier 1cluster-require-full-coverage Yes
Redis.6381.conf content is as follows:
Port 6381 loglevel Notice logfile "d:/redis/logs/redis6381_log.txt" appendonly yesappendfilename " Appendonly.6381.aof " cluster-enabled Yes cluster-config-file nodes.6381.confcluster-node-timeout 15000cluster-slave-validity-factor 10cluster-migration-barrier 1cluster-require-full-coverage Yes
Redis.6382.conf content is as follows:
Port 6382 loglevel Notice logfile "d:/redis/logs/redis6382_log.txt" appendonly yesappendfilename " Appendonly.6382.aof " cluster-enabled Yes cluster-config-file nodes.6382.confcluster-node-timeout 15000cluster-slave-validity-factor 10cluster-migration-barrier 1cluster-require-full-coverage Yes
The configuration content is interpreted as follows:
Port 6380 #端口号 loglevel Notice #日志的记录级别, notice is the logfile "D:/redis/logs/redis6380_log.txt" for the production environment Specifies the keep path of log, which is created in the Redis installation directory by default, if a subdirectory needs to be created manually, so the logs directory syslog-enabled Yes #是否使用系统日志 syslog-ident redis6380 # The identity name of the system log appendonly Yes #数据的保存为aof格式 appendfilename "appendonly.6380.aof" #数据保存文件 cluster-enabled Yes # Whether to turn on cluster cluster-config-file nodes.6380.conf cluster-node-timeout 15000 cluster-slave-validity-factor 10 Cluster-migration-barrier 1 Cluster-require-full-coverage Yes
Save the above configuration files to the D:/redis directory and use these profiles to install the 3 Redis services, as follows:
Note: redis.6380.conf and other configuration files to use the full path to avoid restarting the Redis cluster problem, the installation directory here 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
To start these 3 services, the command is as follows:
D:/redis/redis-server.exe--service-start--service-name redis6382d:/redis/redis-server.exe--service-start-- Service-name Redis6381d:/redis/redis-server.exe--service-start--service-name Redis6380
Execution Result:
2. Download and install Ruby 2.1. The download path is as follows:
Http://dl.bintray.com/oneclick/rubyinstaller/rubyinstaller-2.2.4-x64.exe
After downloading, double-click Install, for easy operation, install to the C Packing directory (C:\Ruby22-x64),
The following two options are selected during installation:
ADD Ruby executables to your PATH
Associate. RB and. rbw files with this Ruby installation
This means adding ruby to the environment variables of the system, using Ruby commands directly in the CMD command, and actively associating. RB and. RBW formatted files.
2.2. Download the Redis driver in Ruby Environment, for compatibility, download is 3.2.2 version
https://rubygems.org/gems/redis/versions/3.2.2
Note: Download the related link in the bottom right corner of the page
To install the driver, the command is as follows:
C:\Ruby22-x64\bin\gem Install--local C:\Ruby22-x64\redis-3.2.2.gem
2.3. Download the Ruby script file Redis-trib.rb, which is officially provided by Redis to create a Redis cluster, with the following path:
Https://raw.githubusercontent.com/MSOpenTech/redis/3.0/src/redis-trib.rb
Open the link if it is not downloaded, but instead opens a page, save the page as a redis-trib.rb (. RB suffix, which is the save format for the Ruby file) and save it to the D:/redis directory.
3. Create a Redis cluster
CMD, switch to the Redis directory and use REDIS-TRIB.RB to create the Redis cluster:
REDIS-TRIB.RB Create--replicas 0 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382
Note: Because REDIS-TRIB.RB is Ruby code, you must open it with Ruby, and if REDIS-TRIB.RB is not recognized, you will need to manually select how to open the file:
* * When Ruby is selected for open mode, REDIS-TRIB.RB's logo will change, such as:
Execution Result:
When prompted, you need to enter yes manually, and when the following appears, the Redis cluster has been created
To verify that the creation was successful, enter the following command:
REDIS-TRIB.RB Check 127.0.0.1:6380
The following information appears stating that the Redis cluster created is not a problem
Use Redis client Redis-cli.exe to see the number of data records and cluster-related information
D:/redis/redis-cli.exe-c-P 6380
-C denotes cluster
-P indicates port port number
Enter the total number of dbsize query records
Dbsize
or enter the full command at once:
D:/redis/redis-cli.exe-c-P 6380 dbsize
The results are as follows:
Enter cluster info to view the cluster information from the client:
Cluster info
The results are as follows:
To build a Redis cluster under Windows