In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
working principle
Excerpt from redis official document: http://www.redis.cn/topics/cluster-tutorial.html
Introduction to Redis Cluster
A Redis cluster is an assembly that provides data sharing among multiple Redis nodes.
Redis clusters do not support commands to handle multiple keys, because this requires moving data between different nodes, thus not achieving the performance of Redis, which can lead to unpredictable errors under high load.
Redis clusters provide a certain degree of availability through partitioning and continue to process commands when a node is down or unreachable in the real environment. Advantages of Redis clusters:
Automatically split the data to different nodes. Some nodes in the entire cluster can continue to process commands if they fail or are unreachable. Data fragmentation of Redis Cluster
Redis cluster does not use consistent hash, but introduces the concept of hash slot.
The Redis cluster has 16384 hash slots, and each key passes the CRC16 check and modulates 16384 to decide which slot to place. Each node of the cluster is responsible for part of the hash slot. For example, if the current cluster has three nodes, then:
Node A contains hash slots 0 to 5500. Node B contains hash slots 5501 to 11000. Node C contains hash slots 11001 to 16384.
This structure is easy to add or remove nodes. For example, if I want to add a new node D, I need to get some slots from nodes A, B, C to D. If I want to remove node A, I need to move the slot in A to the B and C nodes, and then remove the A node without any slots from the cluster. Since moving hash slots from one node to another does not stop service, no matter adding, deleting or changing the number of hash slots of a node will not cause the cluster to be unavailable.
Master-Slave replication Model of Redis Cluster
In order to make the cluster still available when some nodes fail or most nodes can not communicate, the cluster uses the master-slave replication model, and each node will have a replica.
In our example, if node B fails in the absence of a replication model, the whole cluster will be unavailable because of the lack of slots in the range of 5501-11000.
However, when the cluster is created (or after a period of time), we add a slave node, A1 Magi B1, C1 for each node, then the whole cluster consists of three master nodes and three slave nodes, so that after node B fails, the cluster will elect B1 to continue to serve the new master node, and the whole cluster will not be unavailable because the slot cannot be found.
However, when both B and B 1 fail, the cluster is not available.
Redis installation process
1. Download the redis installation package
2. Decompression
Cd / apptar zxf redis-3.2.11.tar.gz mv redis-3.2.11.tar.gz redis
3. Compile and install
Cd redismake & & make install
4. Create relevant directories and copy relevant commands from src directory to bin directory
Mkdir-pv / app/redis/ {bin,conf,data,logs}
5. Use install_server.sh in utils to install redis server
Deployment process Redis-cluster build
1. Upload the compiled redis folder from the test package to the server that needs to be installed
2. Extract it to the app directory. The directory structure is as follows. Data,conf,logs is a directory created by yourself after compilation. It is used to store data files, configuration files, log files, and folders named by port numbers under the data directory, and to store the data files of each port number instance.
-rw-rw-r-- 1 root root 92766 Sep 21 22:20 00-RELEASENOTESdrwxr-xr-x 2 root root 4096 Dec 20 16:40 bin-rw-rw-r-- 1 root root 53 Sep 21 22:20 BUGSdrwxr-xr-x 2 root root 4096 Jan 4 15:37 conf-rw-rw-r-- 1 root root 1805 Sep 21 22:20 CONTRIBUTING-rw-rw-r-- 1 root root 1487 Sep 21 22:20 COPYINGdrwxr-xr-x 10 root root 4096 Jan 3 11:24 Datadrwxrwxr-x 7 root root 4096 Dec 20 14:50 deps-rw-rw-r-- 1 root root 11 Sep 21 22:20 INSTALLdrwxr-xr-x 2 root root 4096 Jan 4 15:37 logs-rw-rw-r-- 1 root root 151 Sep 21 22:20 Makefile-rw-rw-r-- 1 root root 4223 Sep 21 22:20 MANIFESTO-rw-rw-r-- 1 root root 6834 Sep 21 22:20 README.md-rw-rw-r-- 1 root root 46695 Sep 21 22:20 redis.conf-rwxrwxr-x 1 root root 271 Sep 21 22:20 runtest-rwxrwxr-x 1 root root 280 Sep 21 22:20 runtest-cluster-rwxrwxr-x 1 root root 281 Sep 21 22:20 runtest-sentinel-rw-rw-r-- 1 root root 7606 Sep 21 22:20 sentinel.confdrwxrwxr-x 2 root root 4096 Dec 20 14:51 srcdrwxrwxr-x 10 root root 4096 Sep 21 22:20 testsdrwxrwxr-x 7 root root 4096 Jan 4 14:36 utils
3. Modify the configuration file of each port. Take the configuration file of node1:7000 as an example, and modify it according to the situation.
Bind node1protected-mode yesport 7000tcp-backlog 511timeout 0tcp-keepalive 300daemonize yessupervised nopidfile / var/run/redis_7000.pidloglevel noticelogfile / app/redis/logs/redis_7000.logdatabases 16save 900 1save 300 10save 60 10000stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename dump.rdbdir / app/redis/data/7000slave-serve-stale-data yesslave-read-only yesrepl-diskless-sync norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noslave-priority 100appendonly noappendfilename "appendonly.aof" appendfsync everysecno-appendfsync-on-rewrite noauto-aof-rewrite -percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated yeslua-time-limit 5000cluster-enabled yescluster-config-file nodes-7000.confcluster-node-timeout 15000slowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0notify-keyspace-events "" hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-size-2list-compress-depth 0set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64hll-sparse-max-bytes 3000activerehashing yesclient- Output-buffer-limit normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60hz 10aof-rewrite-incremental-fsync yes
4. Start the service of the corresponding port (the master and slave of all nodes are started), take 7000 as an example
/ app/redis/bin/redis-server / app/redis/conf/7000.conf
5. Create a cluster
/ app/redis/bin/redis-trib.rb create node1:7000 node2:7000 node2:7000 [root@node1 bin] #. / redis-trib.rb check node1:7000 > Performing Cluster Check (using node node1:7000) M: 3b485951a72e16133464585dc2920c10ce75967b node1:7000 slots:5461-10922 (5461 slots) master 0 additional replica (s) M: 54d5eb9415289228b05b28fe585bd5ab6e9bc0bc node3:7000 slots:0-5460 (5461 slots) master 0 additional replica (s) M: b6dd7c3d5af4ffc37e70d7eb538a3f9b0ae5a84f node2:7000 slots:10923-16383 (5461 slots) master 0 additional replica (s) [OK] All nodes agree about slots configuration. > > Check for open slots... > Check slots coverage... [OK] All 16384 slots covered.
6. The slave node needs to be added after the data migration.
Data migration
According to the actual situation, refer to: https://www.18188.org/articles/2016/04/23/1461374145366.html for data migration.
1. Transfer all slot to one primary instance
[root@node1 bin] # / redis-trib.rb reshard-- from b6dd7c3d5af4ffc37e70d7eb538a3f9b0ae5a84f-- to 3b485951a72e16133464585dc2920c10ce75967b-- slots 5462-- yes node1:7000 [root@node1 bin] #. / redis-trib.rb reshard-- from 54d5eb9415289228b05b28fe585bd5ab6e9bc0bc-- to 3b485951a72e16133464585dc2920c10ce75967b-- slots 5462-- yes node1:7000
2. Download the original Ali Cloud redis backup rdb file to the corresponding directory
Cp / app/hins2533955_data_20180105195042.rdb / app/redis/data/7000/dump.rdb
3. Restart to read the backup file, restart the connection and use dbsize to check whether the data is imported.
/ app/redis/bin/redis-cli-h node1-p 7000 shutdown/app/redis/bin/redis-server / app/redis/conf/7000.conf
4. Reassign slot
[root@node1 bin] # / redis-trib.rb reshard-- from 3b485951a72e16133464585dc2920c10ce75967b-- to b6dd7c3d5af4ffc37e70d7eb538a3f9b0ae5a84f-- slots 5462-- yes node2:7000 [root@node1 bin] #. / redis-trib.rb reshard-- from 3b485951a72e16133464585dc2920c10ce75967b-- to 54d5eb9415289228b05b28fe585bd5ab6e9bc0bc-- slots 5462-- yes node3:7000
5. Add slave nodes, and the corresponding relationship of each node:
1.node1:7000 (master)-- "node4:7000 (slave) 2.node2:7000 (master) -" node5:7000 (slave) 3.node3:7000 (master)-"node6:7000 (slave) [root@node1 bin] #. / redis-trib.rb check node1.7000Invalid IP or Port (given as node1.7000)-use IP:Port format [root@node1 bin] #. / redis-trib.rb check node1:7000 > > Performing Cluster Check (using node node1:7000) M : 3b485951a72e16133464585dc2920c10ce75967b node1:7000 slots:10924-16383 (5460 slots) master 0 additional replica (s) M: b6dd7c3d5af4ffc37e70d7eb538a3f9b0ae5a84f node2:7000 slots:0-5461 (5462 slots) master 0 additional replica (s) M: 54d5eb9415289228b05b28fe585bd5ab6e9bc0bc node3:7000 slots:5462-10923 (5462 slots) master 0 additional replica (s) [OK] All nodes agree about slots configuration. > > Check for open slots... > Check slots coverage... [OK] All 16384 slots covered. [root@node1 bin] #. / redis-trib.rb add -node-- slave-- master-id 3b485951a72e16133464585dc2920c10ce75967b node4:7000 node1:7000 > > Adding node node4:7000 to cluster node1:7000 > Performing Cluster Check (using node node1:7000) M: 3b485951a72e16133464585dc2920c10ce75967b node1:7000 slots:10924-16383 (5460 slots) master 0 additional replica (s) M: b6dd7c3d5af4ffc37e70d7eb538a3f9b0ae5a84f node2:7000 slots:0-5461 (5462 slots) master 0 additional replica (s) M: 54d5eb9415289228b05b28fe585bd5ab6e9bc0bc node3:7000 slots:5462-10923 (5462 slots) master 0 additional replica (s) [OK] All nodes agree about slots configuration. Check for open slots... > > Check slots coverage... [OK] All 16384 slots covered. > > Send CLUSTER MEET to node node4:7000 to make it join the cluster.Waiting for the cluster to join... > Configure node as replica of node1:7000. [OK] New node added correctly. [root@node1 bin] #. / redis-trib.rb add-node-- slave-- master-id b6dd7c3d5af4ffc37e70d7eb538a3f9b0ae5a84f node5:7000 node2:7000 > Adding node node5:7000 to cluster node2:7000 > Performing Cluster Check (using node node2:7000) M: B6dd7c3d5af4ffc37e70d7eb538a3f9b0ae5a84f node2:7000 slots:0-5461 (5462 slots) master 0 additional replica (s) S: 8ff59145b1d3d7fd57923f3cb9c3444f7236d7b1 node4:7000 slots: (0 slots) slave replicates 3b485951a72e16133464585dc2920c10ce75967bM: 54d5eb9415289228b05b28fe585bd5ab6e9bc0bc node3:7000 slots:5462-10923 (5462 slots) master 0 additional replica (s) M: 3b485951a72e16133464585dc2920c10ce75967b node1:7000 slots:10924-16383 (5460 slots) master 1 additional replica (s) [OK] All nodes agree about slots configuration. > Check for open slots... > > Check slots coverage... [OK] All 16384slots covered. > Send CLUSTER MEET to node node5:7000 to make it join the cluster.Waiting for the cluster to join. > > Configure node as replica of node2:7000. [OK] New node added correctly. [root@node1 bin] #. / redis-trib.rb add-node-- slave-- master-id 54d5eb9415289228b05b28fe585bd5ab6e9bc0bc node6:7000 node3:7000 > > Adding node node6:7000 to cluster node3:7000 > Performing Cluster Check (using node node3:7000) M: 54d5eb9415289228b05b28fe585bd5ab6e9bc0bc node3:7000 slots:5462-10923 (5462 slots) master 0 additional replica (s) S: C09449b9dce5af4ac485ccedb664188229d75430 node5:7000 slots: (0 slots) slave replicates b6dd7c3d5af4ffc37e70d7eb538a3f9b0ae5a84fS: 8ff59145b1d3d7fd57923f3cb9c3444f7236d7b1 node4:7000 slots: (0 slots) slave replicates 3b485951a72e16133464585dc2920c10ce75967bM: b6dd7c3d5af4ffc37e70d7eb538a3f9b0ae5a84f node2:7000 slots:0-5461 (5462 slots) master 1 additional replica (s) M: 3b485951a72e16133464585dc2920c10ce75967b node1:7000 slots:10924-16383 (5460 slots) master 1 additional replica (s) [OK] All nodes agree about slots configuration. > > Check for open slots... > Check slots coverage... [OK] All 16384 slots covered. > > Send CLUSTER MEET to node node6 : 7000 to make it join the cluster.Waiting for the cluster to join. > Configure node as replica of node3:7000. [OK] New node added correctly. [root@node1 bin] # / redis-trib.rb check node1:7000 > Performing Cluster Check (using node node1:7000) M: 3b485951a72e16133464585dc2920c10ce75967b node1:7000 slots:10924-16383 (5460 slots) master 1 additional replica (s) S: 8ff59145b1d3d7fd57923f3cb9c3444f7236d7b1 node4:7000 slots: (0 slots) slave replicates 3b485951a72e16133464585dc2920c10ce75967bS: 7501954b635724d66285afbb95841f4b49df5645 node6:7000 slots: (0 slots) slave Replicates 54d5eb9415289228b05b28fe585bd5ab6e9bc0bcS: c09449b9dce5af4ac485ccedb664188229d75430 node5:7000 slots: (0 slots) slave replicates b6dd7c3d5af4ffc37e70d7eb538a3f9b0ae5a84fM: 54d5eb9415289228b05b28fe585bd5ab6e9bc0bc node3:7000 slots:5462-10923 (5462 slots) master 1 additional replica (s) M: b6dd7c3d5af4ffc37e70d7eb538a3f9b0ae5a84f node2:7000 slots:0-5461 (5462 slots) master 1 additional replica (s) [OK] All nodes agree about slots configuration. > > Check for open slots... > Check slots coverage... [OK] All 16384slots covered.
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.