In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
I. related concepts of Redis cluster
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 AOF full persistence:
It can ensure the high availability of data.
Timely downtime during writing will not destroy what already exists in the log file. If downtime occurs during writing, you can use the redis-check-aof tool to solve the problem after restarting Redis.
If the log is too large, Redis can automatically enable the rewrite mechanism to generate new files to store the aof log
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.
Disadvantages of AOF full persistence:
For the same number of datasets, AOF files are usually larger than RDB files. RDB is faster than AOF in recovering large datasets.
According to the difference of synchronization strategy, the running efficiency of AOF is often slower than that of RDM. In a word, the efficiency of synchronization policy per second is relatively high, and the efficiency of synchronization disable policy is as efficient as RDB.
If both RDB and AOF exist at the same time, the AOF mode is preferred.
II. Deploy Redis clusters
1. The environment is as follows:
There are a total of six centos servers, with three master corresponding to one slave
In order to avoid the collapse of the entire cluster due to the downtime of the physical server, you can also configure multiple Redis instances on one server to achieve cross-master-slave replication. The so-called crossover is master in node01, but the corresponding slave master corresponds to slave in node03, while node03 corresponds to slave in node01.
The above is just a Redis cluster deployed on multiple servers.
But I am mainly deploying multiple nodes on a single server, so there will be multiple instances on node6
You can download the required software package before configuration, or you can download and prepare it by yourself. Link: https://pan.baidu.com/s/1mJGBD7b0QyR_II4mSpdD8Q
Extraction code: 72hi
2. Configure Redis instance
Here is an example of the configuration of node01. The configuration of other nodes is basically the same as that of node1.
[root@node1 /] # mkdir redis # personal habit [root@node1 /] # cd redis/ [root@node1 redis] # rz # upload the required software package [root@node1 redis] # ls # node node only needs the redis4.0 package The remaining two packages are redis-3.3.0.gem redis-4.0.14.tar.gz ruby-2.3.1.tar.gz [root@node1 redis] # tar zxf redis-4.0.14.tar.gz # unpacking [root@node1 redis] # mv redis-4.0.14 / usr/local/redis # Mobile and renaming [root@node1 redis] # cd / usr/local/ required for installing the ruby environment Redis/ # enter the directory [root@node1 redis] # make & & make install # compile and install [root@node1 redis] #. / utils/install_server.sh # initialize redis # all options for initialization remain default Enter all the way to confirm, is to confirm the listening port, configuration files, log files, pid storage Is this ok? Then press ENTER to go on or Ctrl-C to abort.Copied / tmp/6379.conf = > / etc/init.d/redis_6379Installing service...Successfully added to CHK configs successful added to runlevels 345 starting Redis server...Installation successful! Path and other information # when these messages appear, the initialization is successful [root@node1 redis] # echo "512" > / proc/sys/net/core/somaxconn # and then make some optimizations [root@node1 redis] # echo "vm.overcommit_memory = 1" > / etc/sysctl.conf [root@node1 redis] # sysctl-pvm.overcommit_memory = 1 [root@node1 redis] # echo "never" > / sys/ Kernel/mm/transparent_hugepage/enabled [root@node1 redis] # vim / etc/redis/6379.conf # Edit the configuration file bind 0.0.0.0 # find the line that is not commented 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 cluster-enabled yes # if there are any comments You need to remove the comment symbol cluster-node-timeout 5000 # modify appendonly yes # and change it to yes [root@node1 redis] # / etc/init.d/redis_6379 restart # restart the service to make the configuration effective [root@node1 redis] # netstat-anput | grep 6379 # confirm that ports 6379 and 16379 tcp 00 0.0.0.0yes 6379 have been monitored 0.0.0.0 * LISTEN 44263/redis-server tcp 0 00.0.0.0 16379 0.0.0.0 LISTEN 44263/redis-server can configure the above in turn on other node servers. Except node6 3. Configure multiple Redis instances of node06 hosts on this node, I will configure it to run multiple Redis database instances, so the configuration is not exactly the same as that of the previous five nodes Carefully configure [root@node6 /] # mkdir redis [root@node6 /] # cd redis/ [root@node6 redis] # rz [root@node6 redis] # tar zxf redis-4.0.14.tar.gz [root@node6 redis] # mv redis-4.0.14 / usr/local/redis [root@node6 redis] # cd / usr/local/redis/ [root@node6 redis] # make & & make install # compile and install After installation, there is no need to initialize [root@node6 redis] # redis-server # to start this command, there will be 3 warnings. These three warnings are the three options we need to optimize: [root@node6 redis] # echo "512" > / proc/sys/net/core/somaxconn [root@node6 redis] # echo "vm.overcommit_memory = 1" > > / etc/sysctl.conf [root@node6 redis] # sysctl-pvm.overcommit_memory = 1 [root@node6 redis] # echo "never" > / sys/kernel/mm/transparent_hugepage/ enabled [root @ node6 redis] # vim redis.conf # Edit configuration file bind 0.0.0.0port 7000 # the default port for redis is 6379 Here I changed it to 7000, in order to identify daemonize yes # to enable the background daemon to run cluster-enabled yes # in the background to turn on the timeout between cluster cluster-node-timeout 5000 # cluster nodes, in millisecond appendonly yes # whether to enable synchronization to disk appendfilename "appendonly-7000.aof" # aof log name, because there are multiple instances on this host So each port is different, so use the port to name the log name [root@node6 redis] # mkdir-p / usr/local/redis-cluster/ {7000.7004} # 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@node6 redis] # cp redis.conf / usr/local/redis-cluster/7000/ [root@node6 redis] # cp redis.conf / usr/local/redis-cluster/7001/ [root@node6 redis] # cp redis.conf / usr/local/redis-cluster/7002/ [root @ node6 redis] # cp redis.conf / usr/local/redis-cluster/7003/ [root@node6 redis] # cp redis.conf / usr/local/redis-cluster/7004/
# then change the port number corresponding to the Redis instance in the copied configuration files below
[root@node6 redis] # cd / usr/local/redis-cluster/ [root@node6 redis-cluster] # ls7000 7001 7002 7003 7004 [root@node6 redis-cluster] # sed-is / 7000is 7001is g 7001/redis.conf [root@node6 redis-cluster] # sed-is / 7002is g 7002/redis.conf [root@node6 redis-cluster] # sed-is / 7000qqq7003is g 7003/redis.conf [root@node6 redis-cluster] # sed-is / 7000is 7004 / g 7004/redis.conf [root@node6 redis-cluster] # cd 7000 / # go to the 7000 instance directory [root@node6 7000] # redis-server redis.conf # launch the instance 8142cd C 13 Feb 10cd 4417.501 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo8142:C 13 Feb 10monetype Bits=64, commit=00000000, modified=0, pid=8142, and just started8142:C 13 Feb 10 modified=0 44 17 50 1 # Configuration loaded# are entered into each instance directory in turn Start the instance, so I won't demonstrate it here.
4. Host node01 installs and configures the running environment of ruby to facilitate the management of Redis clusters
[root@node1 /] # yum-y install rpm-build openssl openssl-devel # installation dependency package [root@node1 /] # cd / redis/ [root@node1 redis] # lsredis-3.3.0.gem redis-4.0.14.tar.gz ruby-2.3.1.tar.gz [root@node1 redis] # tar zxf ruby-2.3.1.tar.gz # Unpack [root@node1 redis] # cd ruby-2.3 .1 / [root@node1 ruby-2.3.1] #. / configure-- prefix=/usr/local/ruby & & make & & make install # this environment takes a long time to compile [root@node1 ruby-2.3.1] # ln-s / usr/local/ruby/bin/* / usr/local/bin/ # softlink for commands [root@node1 ruby-2.3.1] # ln-s / usr/local / redis/src/redis-trib.rb / usr/local/bin/ [root@node1 ruby-2.3.1] # ln-s / usr/local/ruby/bin/* / usr/bin/ [root@node1 ruby-2.3.1] # cd. [root@node1 redis] # gem install redis-3.3.0.gem # return to the directory with the gem file Install 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# range if the above information indicates that the installation is successful
5. Configure each node in the cluster
[root@node1 /] # redis-cli-p 6379 # Log in to the ben'di local instance 127.0.0.1 CLUSTER MEET 192.168.171.134 6379 # add each node to the cluster OK127.0.0.1:6379 > CLUSTER MEET 192.168.171.135 6379OK127.0.0.1:6379 > CLUSTER MEET 192.168.171.136 6379OK127.0.0.1:6379 > CLUSTER MEET 192.168.171.137 6379OK127 .0.0.1: 6379 > CLUSTER MEET 192.168.171.138 7000 # this is because node6 modified the port number OK127.0.0.1:6379 > set test aaa # because no hash slot is assigned So you cannot add data (error) CLUSTERDOWN Hash slot not served 127.0.0.1 CLUSTER INFO 6379 > CLUSTER INFO # check the status of the cluster cluster_state:fail # and you will find that here is the cluster_slots_assigned:0127.0.0.1:6379 of fail failure > exit# below we assign slot points, be careful to configure # 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@node1 /] # redis-cli-h 192.168.171.133-p 6379 cluster addslots {0.5461} OK [root@node1 /] # redis-cli-h 192.168.171.134-p 6379 cluster addslots {5462... 10922} OK [root@node1 /] # redis-cli-h 192.168.171.135-p 6379 cluster addslots {10923. 16383} OK [root@node1 /] # redis-cli-p 6379-c # enter the cluster Need to add-c option 127.0.0.1 CLUSTER NODES # to view cluster node information # 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 need to log in to which instance 127.0.0.1 node04 6379 > CLUSTER NODES # can execute this command first View the ID of the corresponding node So that you can next specify [root@node1 /] # redis-cli-h 192.168.171.136-p 6379 # Log in to node4192.168.171.136:6379 > CLUSTER REPLICATE 4397bb3e5e43fdf1700551d0a2587f502e6c02a8OK# and add the node id192.168.171.136:6379 > exit # of node1 to exit the node [root@node1 /] # redis-cli-h 192.168.171.137-p 6379192.168.171.137 > CLUSTER REPLICATE 1eca51f415ba5194a95d5400176daa5713d64990OK# Is the node id192.168.171.137:6379 > exit [root@node1 /] # redis-cli-h 192.168.171.138-p 7000192.168.171.138redis-cli 7000 > CLUSTER REPLICATE ee71a2fd995f35992ce69328096ccd50fc68f89eOK#. Above is the node id of node3.
At this point, the cluster can read and write data normally, as follows: [root@node1 /] # redis-cli-h 192.168.171.133-p 6379-c 192.168.171.133set test aaa- > Redirected to slot [6918] located at 192.168.171.134:6379OK192.168.171.134:6379 > get test "aaa" 192.168.171.1346379 > 6, use the commands installed by ruby to manage the Redis cluster [root@node1 /] # redis-trib.rb check 127.0.0.1 redis-trib.rb check 637
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.