In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Redis Cluster:
Redis cluster is an assembly that provides data sharing among multiple Redis nodes. Cluster nodes work together to build a decentralized network. Each node in the cluster has an equal identity, and each node saves its own data and cluster state. Gossip protocol is used to communicate between nodes, which ensures the synchronization of node state information.
Redis cluster data is managed by partitions, and each node holds a subset of the cluster data. Data is allocated in a way called hash slot, which is different from the traditional consistent hash. The Redis cluster has 16384 hash slots, and each key passes the CRC16 check and modulates 16384 to decide which slot to place.
In order to make the cluster available when some nodes fail or most nodes cannot communicate, the cluster uses the master-slave replication model. When reading the data, the data is obtained from the corresponding master node according to the consistent hashing algorithm. If the master dies, a corresponding salve node will be started to act as the master.
Build a Redis cluster under the Windows system:
4 parts are required:
Redis, Ruby language runtime environment, Ruby-driven redis-xxxx.gem of Redis, redis-trib.rb, a tool for creating Redis clusters
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. Since the file is written in Ruby, you need to install the Ruby development environment and drive 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, and zip version 3.0.504 is downloaded here.
Decompress the downloaded Redis-x64-3.0.504.zip. For convenience, it is recommended to put it in the root directory of the drive letter and change the directory name to Redis, such as C:\ Redis or D:\ Redis.
Three different Redis instances are started through the configuration file, and since the default port of Redis is 6379, 6380, 6381, and 6382 are used to run the three Redis instances.
Note: to avoid unnecessary errors, try to save the configuration file in utf8 format and do not contain comments
The following two ways to save logs in the configuration file (save in file and save to System Log), please select one of them according to your needs:
The recording level of loglevel notice # logs. Notice is suitable for production environment.
Logfile "D:/Redis/Logs/redis6380_log.txt" # specifies the maintenance path of log. By default, it is created under the Redis installation directory. If there are subdirectories to be created manually, the Logs directory at this location
Syslog-enabled yes # whether to use Syslog
Syslog-ident redis6380 # ID name in Syslog
The method of saving in a file is used here, so first create a new Logs folder under the Redis directory D:/Redis
The 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
The 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
The 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 explained as follows:
The recording level of port 6380 # port number loglevel notice # log. Notice is the logfile "Logs/redis6380_log.txt" # suitable for production environment. Specify the retention path of log. By default, it is created under the Redis installation directory. If there are any subdirectories, you need to create them manually. Whether the Logs directory syslog-enabled yes # at this location uses Syslog syslog-ident redis6380 # in the identification name of Syslog appendonly yes # data is saved in aof format appendfilename "appendonly.6380.aof" # data save file cluster-enabled yes # whether to enable cluster cluster-config-file nodes.6380.confcluster-node-timeout 15000cluster-slave-validity-factor 10cluster-migration-barrier 1cluster-require-full-coverage yes
Save the above configuration files to the Redis directory and install the three redis services using these configuration files, with the following command:
Note: redis.6380.conf and other configuration files are best to use the full path to avoid problems in 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 redis6380D:/Redis/redis-server.exe-service-install D:/Redis/redis.6381.conf-service-name redis6381D:/Redis/redis-server.exe-service-install D:/Redis/redis.6382.conf-service-name redis6382
Start the three services with the following command:
D:/Redis/redis-server.exe-service-start-service-name Redis6380D:/Redis/redis-server.exe-service-start-service-name Redis6381D:/Redis/redis-server.exe-service-start-service-name Redis6382
Execution result:
two。 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 the installation. Similarly, for convenience of operation, it is also recommended to install in the root directory of the drive letter, such as: C:\ Ruby22-x64. The last two options are selected here during installation.
It means to add ruby to the environment variable of the system, and the command of ruby can be used directly in the cmd command.
2.2. Download the driver of Redis in ruby environment. For compatibility, version 3.2.2 is downloaded here.
Https://rubygems.org/gems/redis/versions/3.2.2
Note: download in the related links in the lower right corner of the page
To install the driver, the command is as follows:
Gem install-local path_to_gem/filename.gem
The actual operation is as follows:
2.3. Download the ruby script file redis-trib.rb provided officially by Redis to create a Redis cluster, as follows:
Https://raw.githubusercontent.com/MSOpenTech/redis/3.0/src/redis-trib.rb
Open the link if you open a page instead of downloading, save the page as redis-trib.rb
It is recommended to save it to the directory of Redis.
Note: because redis-trib.rb is ruby code, you must use ruby to open it. If redis-trib.rb does not recognize it, you need to manually select how to open the file:
* * when you select ruby as the opening method, the logo of redis-trib.rb will change, as shown below:
3. Create a Redis cluster
Change to the Redis directory under CMD, and use redis-trib.rb to create a Redis cluster:
Redis-trib.rb create-- replicas 0 127.0.0.1 6380 127.0.1
Execution result:
To verify that the creation is really successful, enter the following command:
Redis-trib.rb check 127.0.0.1:6380
The following message appears, indicating that the created Redis cluster is fine.
Use Redis client Redis-cli.exe to view the number of data records and cluster-related information
D:/Redis/redis-cli.exe-c-p 6380
-c stands for cluster
-p represents the 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:
These are the details of the example of building a redis cluster under Windows. Please pay more attention to other related articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.