In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Blog outline:
I. related concepts of Redis cluster
II. Deploy Redis clusters
1. Deployment environment 2, configure Redis instance 3, configure multi-Redis instance of node06 host 4, host node01 install and configure the running environment of ruby, it is convenient to manage Redis cluster 5, configure each node in the cluster 6, use the command of ruby installation to manage Redis cluster 7, add 6380 instance of node06 to Redis cluster 8, assign slave node 9 to newly joined master, delete master node operation 1, Redis cluster related concepts
Redis has supported cluter since version 3.0, using hash slots, which can consolidate multiple Redis instances together to form a cluster, that is, data can be stored on multiple nodes in the cluster.
The cluster of Redis is an acentric structure. In the cluster, the identity of each master is equal, each node saves the data and the state of the entire cluster, and knows the slot that the other node is responsible for, and sends heartbeat information regularly, can timely detect the abnormal node in the cluster, and take the way of voting to determine whether the node is unavailable, if the number of votes is more than half of the nodes in the cluster. It is considered that the node is not available, and it is precisely because of this feature that a Redis cluster should be deployed with at least three or more nodes.
The cluster role has slots (slots) assigned between master and slave,master, and the slot number is 0-16383 (16384 in total).
By default, each cluster node has two TCP ports listening, one is 6379 (for listening for client access connections) and the other is 16379 (for node communication between clusters). Note that the firewall needs to release traffic from these two ports.
All data in Redis is stored in memory and then saved to disk asynchronously from time to time (this is called "semi-persistent mode"); each data change can also be written to an append only file (aof) (this is called "full persistence mode").
There are two ways of persistence provided by Redis, one is RDB persistence (the principle is that the database in memory of Redis records dump regularly to RDB on disk), and the other is AOF (append only file) persistence (the principle is that the operation log of Redis is written to the file in an additional way).
Advantages and disadvantages of RDB
Advantages of RDB semi-persistence:
Include only one file, which is good for file backup; disaster recovery is faster than aof persistence; and performance is maximized. For the Redis service process, at the beginning of persistence, the only thing it needs to do is to fork the child process, and then the child process completes the persistence work, which can greatly prevent the service process from performing IO operations. Compared with the AOF mechanism, if the dataset is too large, the RDB startup efficiency will be higher.
The disadvantage of RDB semi-persistence: because RDB assists in data persistence through the help child process, if the dataset is large, it may cause the entire service to stop for hundreds of milliseconds, or even 1 second.
Advantages and disadvantages of AOF
Advantages of AOF full persistence:
It can ensure high availability of data; when downtime occurs during writing, it will not destroy the content already in the log file. If there is a downtime during writing, you can restart Redis and use redis-check-aof tool to solve this problem. If the log is too large, Redis can automatically enable rewrite mechanism to generate new files to store aof logs. This mechanism can bring higher data security and data persistence. Three synchronization strategies are provided in Redis, namely synchronization per second, synchronization per modification, and async.
The disadvantage of AOF full persistence: AOF files are usually larger than RDB files for the same number of datasets. The recovery speed of RDB is faster than that of AOF when recovering large datasets; according to the different synchronization strategies, AOF tends to be slower than RDM in running efficiency. In a word, the efficiency of synchronization per second policy is relatively high, and the efficiency of synchronization disable policy is as efficient as RDB.
If RDB and AOF exist at the same time, the AOF mode is preferred.
2. Deploy Redis cluster 1. The environment is as follows:
There are a total of six centos servers above. It is realized that three master correspond to one slave (multiple Redis instances can also be configured on one server, but instead of master-slave on the same physical server, master-slave replication can be carried out using cross-master-slave. The so-called crossover means that master is in node01, but the corresponding slave master corresponding slave is in node03, and node03 corresponding slave is in node01. The advantage of this is to avoid the collapse of the entire cluster due to the downtime of the physical server, which is just a slight hint below and can be studied by yourself.
In order to show that multiple Redis instances are configured on the same host, multiple Redis instances will be configured on node06, and the rest of the nodes will each be responsible for one Redis instance.
Before proceeding with the next configuration, please download the source package provided by me (in fact, the version deployed here is Redis4.0, and the version is lower, and some convenient configurations cannot be carried out. Please refer to my blog post on deploying Redis 5.0).
2. Configure Redis instance
Here is an example of the configuration of node01, which can be copied by other nodes.
[root@node01 ~] # ls | grep redis # upload the package I provided using the rz command in xshell As follows: redis-4.0.14.tar.gz [root@node01 ~] # tar zxf redis-4.0.14.tar.gz-C / usr/local/ # unpack [root@node01 ~] # cd / usr/local/ # switch to the specified path [root@node01 local] # mv redis-4.0.14 redis # change the directory name [root@node01 local] # cd redis/ # to the decompressed directory [root@node01 Redis] # make & & make install # No configuration required Directly compile and install [root@node01 redis] #. / utils/install_server.sh # initialize Redis. All options for initialization remain default Enter all the way to confirm that # is confirming the listening port, configuration file, log file, pid storage path and other information. # omitting part of the content Successfully added to chkconfig successful added to runlevels 345 starting Redis server...Installation successful completion # indicates that the initialization is successful # and then make some optimizations. It is as follows: [root@node01 redis] # echo "512" > / proc/sys/net/core/somaxconn [root@node01 redis] # echo "vm.overcommit_memory = 1" > > / etc/sysctl.conf [root@node01 redis] # sysctl-pvm.overcommit_memory = 1 [root@node01 redis] # echo "never" > / sys/kernel/mm/transparent_hugepage/ enabled [root @ node01 redis] # vim / etc/redis/6379.conf # Edit configuration file Modify the following bind 0.0.0.0 # to find the line that is not commented, and change it to 0.0.0.0daemonize yes#. If there is a comment symbol, you need to delete the comment symbol in order to take effect. After the cluster-enabled yescluster-node-timeout 5000appendonly yes# modification is completed, save and exit. [root@node01 redis] # / etc/init.d/redis_6379 restart # restart the Redis service [root@node01 redis] # netstat-anpt | grep redis # make sure that ports 6379 and 16379 are listening
Do the above configuration in turn on other node servers, except for the host node06, as the configuration of multiple Redis instances of a single host will be shown on node06 later.
3. Configure multiple Redis instances of node06 hosts
On the node06 node, I will configure it to run multiple Redis database instances, so the configuration is not exactly the same as the previous five nodes, so please configure it carefully.
[root@node06 ~] # tar zxf redis-4.0.14.tar.gz-C / usr/local/ [root@node06 ~] # cd / usr/local/ [root@node06 local] # mv redis-4.0.14 redis [root@node06 local] # cd redis/ [root@node06 redis] # make & & make install # after compilation and installation There is no need to initialize [root@node06 redis] # redis-server # start to view the items that need to be optimized # the optimized configuration of the first few nodes is obtained from the prompt information after the execution of the command. Then optimize the configuration of these prompts! [root@node06 redis] # echo "512" > / proc/sys/net/core/somaxconn [root@node06 redis] # echo "vm.overcommit_memory = 1" > > / etc/sysctl.conf [root@node06 redis] # sysctl-pvm.overcommit_memory = 1 [root@node06 redis] # echo "never" > / sys/kernel/mm/transparent_hugepage/ enabled [root @ node06 redis] # vim redis.conf # Edit the template configuration file in the current directory .0.0.0port 6379daemonize yes # start the background daemon In order to run cluster-enabled yes # in the background to enable the timeout between cluster cluster-node-timeout 5000 # cluster nodes in milliseconds, whether appendonly yes # enables synchronization to disk appendfilename "appendonly-6379.aof" # aof log name # after editing, you can save and exit [root@node06 redis] # mkdir-p / usr/local/redis-cluster/ {6379. 6382} # above is intended to run several Redis instances Just create a few directories. Here I name the directory after the port number of the instance (temporarily planning to run 4 Redis instances) # the following is to copy the modified configuration file to the specified directory: [root@node06 redis] # cp redis.conf / usr/local/redis-cluster/6379/ [root@node06 redis] # cp redis.conf / usr/local/redis-cluster/6380/ [root@node06 redis] # cp redis.conf / usr/local/redis-cluster/6381/ [root @ node06 redis] # cp redis.conf / usr/local/redis-cluster/6382/# then change each copied configuration file to the port number corresponding to the Redis instance [root@node06 redis] # cd / usr/local/redis-cluster/ [root@node06 redis-cluster] # sed-is / 6379is 6380/redis.conf [root@node06 redis-cluster] # sed-is / 6379max 6381andg 6381/redis.conf [root@node06 redis] -cluster] # sed-is / 6379Univer 6382max 6382/redis.conf [root@node06 redis-cluster] # cd 6379 # change to the 6379 directory [root@node06 6379] # redis-server redis.conf # launch the configuration file 101582is C 04 Nov 23is 37purl 04.988 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo101582:C 04 Nov is 370lv 4.988 # Redis version=4.0.14 Bits=64, commit=00000000, modified=0, pid=101582 The next step is to launch each instance [root@node06 6379] # cd.. / 6380 [root@node06 6380] # redis-server redis.conf [root@node06 6380] # cd.. / 6381 [root@node06 6381] # redis-server redis.conf [root@node06 6381] # cd.. / 6382 [root@node06 6382] # redis-server redis.conf [root@node06 6382] # netstat-anpt | grep redis # check the listening of Redis-related ports
The above response information for checking Redis port snooping is as follows:
4. Host node01 installs and configures the running environment of ruby Easy to manage Redis cluster [root@node01 ~] # yum-y install rpm-build openssl openssl-devel # installation depends on [root@node01 ~] # ls | egrep "gem | ruby" # upload the following two packages to the host node01redis-3.3.0.gemruby-2.3.1.tar.gz [root@node01 ~] # tar zxf ruby-2.3.1.tar.gz-C / usr/src # unpack [root@node01 ~] # cd / Usr/src/ruby-2.3.1/ # enters the unzipped directory [root@node01 ruby-2.3.1] # / configure-- prefix=/usr/local/ruby & & make & & make install # compilation and installation The following is a soft link to the generated command [root@node01 ruby-2.3.1] # ln-sf / usr/local/ruby/bin/* / usr/local/bin/ [root@node01 ruby-2.3.1] # ln-sf / usr/local/redis/src/redis-trib.rb / usr/local/bin/ [root@node01 ruby-2.3.1] # cd # back to the directory where the .gem file is located [root] @ node01 ~] # gem install redis-3.3.0.gem # execution of this command Successfully installed redis-3.3.0Parsing documentation for redis-3.3.0Installing ri documentation for redis-3.3.0Done installing documentation for redis after 0 seconds1 gem installed# returns the above information indicates success 5. Configure each node in the cluster [root@node01 ~] # redis-cli-p 6379 # Log in to the local Redis instance # the following is to add each node participating in the cluster to the cluster 127.0.0.1 Redis 6379 > CLUSTER MEET 192.168.20.3 6379OK127.0.0.1:6379 > CLUSTER MEET 192.168.20.4 6379OK127.0.0.1:6379 > CLUSTER MEET 192.168.20.5 6379OK127.0.0.1:6379 > CLUSTER MEET 192 .168.20.6 6379OK127.0.0.1:6379 > CLUSTER MEET 192.168.20.7 6379OK127.0.0.1:6379 > set a b # although node addition is complete However, since there is no hash slot assigned, data cannot be added (error) CLUSTERDOWN Hash slot not served127.0.0.1:6379 > CLUSTER INFO # to check the status of the cluster cluster_state:fail # failed 192.168.20.3 cluster_state:fail 6379 > exit# then assign slot points to the nodes in the cluster # you must be careful in assigning slots, once the allocation is wrong, it is troublesome # although you can replace "add" with "del" in the command But I didn't succeed # must allocate 0 to 16383 completely, preferably equally # just assign it to the node as master My node01 to node03 is master [root@node01 ~] # redis-cli-h 192.168.20.2-p 6379 cluster addslots {0.5461} OK [root@node01 ~] # redis-cli-h 192.168.20.3-p 6379 cluster addslots {5462... 10922} OK [root@node01 ~] # redis-cli-h 192.168.20.4-p 6379 cluster addslots {10923.16383} OK [root@node01 ~] # redis-cli-p 6379-c # enter the cluster Need to add "- c" option 127.0.0.1 CLUSTER NODES 6379 > CLUSTER NODES # to view the node information in the cluster # the next step is to bind each slave slave node to master # node04 as the slave node of node01, node05 as the slave node of node02, and 6379 instance of node06 as the slave node of node03 # you can execute this command first if you need to log in to which instance 127.0.0.1 node04 6379 > CLUSTER NODES # View the ID of the corresponding node So that you can next specify [root@node01 ~] # redis-cli-h 192.168.20.5-p 6379 # Log in to node04192.168.20.5:6379 > CLUSTER REPLICATE 5cd3d0eec161a7bcc785202397fd8363074ae9c2# what is specified above is node01 node IDOK192.168.20.5:6379 > exit # exit instance [root@node01 ~] # redis-cli-h 192.168.20.6-p 6379 # Log in to node05192.168.20.6:6379 > CLUSTER REPLICATE e2de936c380eb2239f0a349dcbfba5daa74fa1d7# specified above Is the node IDOK192.168.20.6:6379 > exit # of node02 to exit the instance [root@node01 ~] # redis-cli-h 192.168.20.7-p 6379 # Log in to the 6379 instance of node06 192.168.20.7exit 6379 > CLUSTER REPLICATE dd03b02213df3a91608d1f4ae8080c37f4790d7c# above is the node IDOK192.168.20.7:6379 > exit of the specified node03
At this point of configuration, you can view the node information of the cluster again and find that the master and slave correspond to each other, as follows:
At this point, the cluster can read and write data normally, as follows:
[root@node01 ~] # redis-cli-h 192.168.20.2-p 6379-c # Log in to cluster 192.168.20.2 set b cOK6, use the command installed by ruby to manage the Redis cluster [root@node01 ~] # redis-trib.rb check 127.0.0.1 set 6379 # check the status of the cluster
The information returned by the above command is as follows:
7. Add 6380 instances of node06 to the node06 cluster 1) add nodes [root@node01 ~] # redis-trib.rb add-node 192.168.20.7 redis-trib.rb add-node 6380 192.168.20.2 redis-trib.rb add-node 6379 # when adding nodes, no other configuration is added. By default, after joining the cluster, the role is Redi.
The message returned is as follows:
2) after adding nodes, you need to assign corresponding slot points.
Because for a cluster to function properly, all slot points must be allocated, so when new nodes join, you need to reassign slot points to new nodes, as follows:
[root@node01 ~] # redis-trib.rb check 127.0.0.1 master 6379 # when you execute this command to confirm the newly joined node, master [root@node01 ~] # redis-trib.rb reshard 192.168.20.2 master 6379 # specify the cluster address and port How many slots do you want to move (from 1 to 16384)? 409 nodes. If there are four nodes, the average value is 4096, so enter 4096What is the receiving node ID? 010752fb2527317a938fcb5b4e73822db805b3a1# to specify the receiving node. That is, the ID Source node # 1:all # of the 6380 instance on the newly added node06 host specifies the slot point allocation from which node, enter "all" to select all nodes Do you want to proceed with the proposed reshard plan (yes/no)? Yes # enter "yes" to confirm
At this point, the new nodes are added and the corresponding slots are assigned, but. There is no slave node yet, so next assign a slave node to the newly added master.
8. Assign slave nodes to the newly joined master
There are two ways to assign slave nodes, one is to automatically bind to the master of non-slave nodes without specifying which master, and the other is to directly specify which master to bind to, both of which are written down here.
# method 1: [root@node01 ~] # redis-trib.rb add-node-- slave 192.168.20.7 slave 6381 192.168.20.7 slave 638 add 6381 instances on node06 to the cluster as slave # Note, the returned information must not be in red That means there is an error [root@node01 ~] # redis-trib.rb check 192.168.20.2 slave 637 check to confirm whether the newly added slave is bound to the 6380master instance of node06. # method 2: [root@node01 ~] # redis-trib.rb add-node-- slave-- master-id 010752fb2527317a938fcb5b4e73822db805b3a1 192.168.20.7 6380master 6382 192.168.20.2 node06 638 check the ID specified by the above command is the ID of the master of the 6380 instance Directly designated as 6380 slave node [root@node01 ~] # redis-trib.rb check 192.168.20.2 slave 6379 # to view the cluster status, you can see that there are two master6380 nodes, both of which are the newly added slave9 above and delete the master node.
To delete the master node is to reverse the operation of adding the master node. The slot points on the master node to be deleted need to be assigned to other master before the deletion operation can be performed. After deleting the master node, the corresponding slave of the master will also be transferred to the new master along with the slots slot.
Here is an example of removing 6380 instances from node06.
# remove slot point on 6380 instance [root@node01 ~] # redis-trib.rb reshard 192.168.20.2 How many slots do you want to move 6379 # specify cluster listening address How many slots do you want to move (from 1 to 16384)? 4096 # enter how many slots to delete What is the receiving node ID? 5cd3d0eec161a7bcc785202397fd8363074ae9c2# specified here, to whom will the slot on the primary node be assigned? Here is the IDSource node # 1:010752fb2527317a938fcb5b4e73822db805b3a1# of the 6379 instance of node02. Which primary node is specified here? The specified ID is the IDSource node # 2:done # input done of the 6380 instance on node06 to indicate the end of Do you want to proceed with the proposed reshard plan (yes/no)? Yes# enter "yes" to confirm # after the slot point is removed, remove the 6380 instance from the cluster as follows: [root@node01 ~] # redis-trib.rb del-node 192.168.20.2 redis-trib.rb del-node 6379 010752fb2527317a938fcb5b4e73822db805b3a1# the ID of the 6380 instance specified above
At this point, 6380 instances have been completely removed from the cluster, and the corresponding slave has also become the slave of node02 as the slot point is transferred to node02. Now looking at the cluster information, the master of node02 should correspond to three slave.
-this is the end of this article. Thank you for reading-
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.