In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Cluster cluster
Redis Cluster is a highly available solution provided by the government, a decentralized Redis cluster scheme. All Redis nodes are interconnected with each other (PING-PONG mechanism). Clients can connect to Cluster clusters directly with any node without haproxy middleware.
Summary:
1. Decentralized, fragmented storage, mapping all physical nodes to [0-16383] a total of 16384 slot (slots), not necessarily evenly distributed.
2. The Redis cluster is pre-divided into 16384 buckets. When you need to place a key-value in the Redis cluster, decide which bucket to put a key into according to the value of CRC16 (key) mod 16384.
3. Master-slave mechanism is supported. A master can have one or more slave nodes to ensure high availability of the cluster.
4. Master downtime needs to be voted on by all master in the cluster. If more than half of the nodes' communication times out, the current master is considered to be down.
5. If the master in the Cluster cluster does not have slave, the cluster will not be available when any master is down.
6. If more than half of the master of the cluster is down, the cluster will enter the fail state regardless of whether it has slave or not.
7. Slave nodes will not allocate slots
8. Cluster cluster supports up to 1000 nodes.
Environment
Three virtual machines, start redis double instances, deploy three master and three slave clusters. This time, we will explain the creation of the original Cluster cluster without using the official redis.trib.rb script, which is an official ruby script. Because in the production of the company, we used the official script to create a Cluster cluster with two instances of three virtual machines, and found that the last virtual machine was always its own 6379 and 6380, which formed a pair of masters and slaves, that is, not all three were masters and slaves of each other, and a pair of masters and slaves were their own instances.
172.16.1.7
172.16.1.31
172.16.1.61
# yum installs redis (requires epel source)
Yum install-y redis
# create multiple instances
Mkdir-p / data/redis/ {6379 Magi 6380} / {db,log}
Configuration file
[root@web02 6379] # cat / data/redis/6379/redis.conf bind 172.16.1.7protected-mode yesport 6379tcp-backlog 511timeout 0tcp-keepalive 300daemonize yessupervised nopidfile / data/redis/6379/redis.pidloglevel noticelogfile / data/redis/6379/log/redis.logdatabases 16save 900 1save 300 10save 60 10000stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename dump.rdbdir / data/redis/6379/dbslave-serve-stale-data yesslave-read-only yesrepl-diskless-sync norepl-diskless-sync-delay 5replyu 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 5000slowlog-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 00 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60hz 10aof-rewrite-incremental-fsync yes
# start redis instance
Redis-server / data/redis/6379/redis.conf
Redis-server / data/redis/6380/redis.conf
# configure requirepass authentication
# temporary configuration (do not restart configuration)
Redis-cli-h 172.16.1.7-p 6379172.16.1.7 redis-cli > config get requirepass1) "requirepass" 2) "172.16.1.7 requirepass 6379 > config set requirepass 123456OK172.16.1.7:6379 > config get requirepass (error) NOAUTH Authentication required.172.16.1.7:6379 > auth 123456OK172.16.1.7:6379 > config get requirepass1)" requirepass "2)" 123456 "
# permanent configuration, configuration file must be modified
# modify manually
Requirepass "123456"
# configuration saved directly on the command line
172.16.1.7 6380 > config rewrite
# this command will brush the configuration into the configuration file (to disk to make it permanent)
Requirepass "123456"
# swipe into the configuration files of redis.conf and nodes.conf. If you need to configure a cluster, you need to use it.
# cluster saveconfig command
Create a cluster cluster
Modify the configuration file
# each cluster node must start support for cluster clusters
Cluster-enabled yescluster-config-file nodes-6379.conf # (will be saved in the data directory) cluster-node-timeout 15000
# slaveof cannot be defined in a cluster cluster
Slaveof 172.16.1.61 6379cluster-enabled yescluster-config-file nodes-6380.confcluster-node-timeout 15000Reading the configuration file, at line 57 > > 'slaveof 172.16.1.61 6379'slaveof directive not allowed in cluster mode
# View the redis process, which is started in cluster mode
[root@web02 ~] # ps-ef | grep redisroot 1193 1 0 00:08? 00:00:01 redis-server 172.16.1.7 redis-server 172.16.1.7 redis-server [cluster] root 1212 1 0 00:24? 00:00:00 redis-server 172.16.1.7 ef 6380 [cluster]
# at this time, the status of the cluster is still fail, because other nodes have not been added and slots have not been allocated yet
Redis-cli-h 172.16.1.7-p 6379-a 123456172.16.1.7 connected 6379 > cluster infocluster_state:failcluster_slots_assigned:1cluster_slots_ok:1cluster_slots_pfail:0cluster_slots_fail:0cluster_known_nodes:1cluster_size:1cluster_current_epoch:0cluster_my_epoch:0cluster_stats_messages_sent:0cluster_stats_messages_received:0172.16.1.7:6379 > cluster nodes82424bf0ff964ca5486b7f904b95c155e6dceeb1: 6379 myself,master-2000 connected 15197
# add all nodes to the cluster on any node
# add the specified node to the cluster
Cluster meet 172.16.1.7 6380172.16.1.7 cluster meet 6379 > cluster nodes965276bda73d2bce4a44a8fab6e18f676de54f15 172.16.1.61V 6380 master-0 1543768223343 0 connected56572d4ef3b7e30c30a4956c87d4a6ea0050bef5 172.16.1.31 connected82424bf0ff964ca5486b7f904b95c155e6dceeb1 172.16.1.31 connected82424bf0ff964ca5486b7f904b95c155e6dceeb1 172.16.1.31master-01543768221299 2 connected673443984a3610fcaa2fcbf3d295f60b2f7f32ae 172.16.1.31master-01543768222323 3 connected26d3142fb8766e1cfc01978d01c17e287f4ebd38 172.16.1.61Ranger 6379 master-01543768225389 4 connected85142215ac8c6af9ad0a72fb6ac2a5d2be2608a1 172.16.1.7UR 6380 master-01543768224368 0 connected82424bf0ff964ca5486b7f904b95c155e6dceeb1 172.16.714379 myself Master-0 01 connected 15197172.16.1.7purl 6379 > cluster infocluster_state:failcluster_slots_assigned:1cluster_slots_ok:1cluster_slots_pfail:0cluster_slots_fail:0cluster_known_nodes:6cluster_size:1cluster_current_epoch:5cluster_my_epoch:1cluster_stats_messages_sent:96cluster_stats_messages_received:9
# specify the master node on the slave node
# set the current node to the slave of node_id, that is, specify the master node of the current node, and execute it on each slave node
[root@web02] # redis-cli-h 172.16.1.7-p 6380-a 123456172.16.1.7 myself 6380 > cluster nodes85142215ac8c6af9ad0a72fb6ac2a5d2be2608a1 172.16.1.7 myself Master-005 connected26d3142fb8766e1cfc01978d01c17e287f4ebd38 172.16.1.61 master-01543768446773 4 connected82424bf0ff964ca5486b7f904b95c155e6dceeb1 172.16.1.7 master-01543768444120 1 connected 15197965276bda73d2bce4a44a8fab6e18f676de54f15 172.16.1.61master-01543768445753 0 connected56572d4ef3b7e30c30a4956c87d4a6ea0050bef5 172.16.1.31master 6379 master-01543768441669 2 connected673443984a3610fcaa2fcbf3d295f60b2f7f32ae 172.16.1.31 master-01543768444734 3 connected172.16.1.7:6380 > cluster replicate 26d3142fb8766e1cfc01978d01c17e287f4ebd38OK
# final result
172.16.1.61 cluster nodes82424bf0ff964ca5486b7f904b95c155e6dceeb1 172.16.1.7 connected 1519756572d4ef3b7e30c30a4956c87d4a6ea0050bef5 172.16.1.31 connected 1519756572d4ef3b7e30c30a4956c87d4a6ea0050bef5 172.16.1.31 master-01 543768682754 2 connected965276bda73d2bce4a44a8fab6e18f676de54f15 172.16.1.61connected965276bda73d2bce4a44a8fab6e18f676de54f15 6380 myself,slave 56572d4ef3b7e30c30a4956c87d4a6ea0050bef5 00 0 connected85142215ac8c6af9ad0a72fb6ac2a5d2be2608a1 172.16.1.7 master 015437683780 5 connected673443984a3610fcaa2fcbf3d295f60b2f7f32ae 172.16.1.31 slave 82424bf0ff964ca5486b7f904b95c155e6dceeb1 0154376879697 3 connected26d3142fb8766e1cfc01978d01c17e287f4ebd38 172.16.1.61anger 6379 master-01543768681741 connected
Allocation slot
# redis3.0.0 stipulates that there are a total of 16384 slots, which are evenly distributed among three master nodes.
For i in {0... 5460}; do redis-cli-h 172.16.1.7-p 6379-a 123456 cluster addslots $I > / dev/null;donefor I in {5461... 10922}; do redis-cli-h 172.16.1.31-p 6379-a 123456 cluster addslots $I > / dev/null;donefor I in {10923... 16383}; do redis-cli-h 172.16.1.61-p 6379-a 123456 cluster addslots $I > / dev/null;done
# write the cluster configuration to disk, and each node needs to execute
Cluster saveconfig
# check cluster status
172.16.1.7slave 56572d4ef3b7e30c30a4956c87d4a6ea0050bef5 > cluster infocluster_state:okcluster_slots_assigned:16384cluster_slots_ok:16384cluster_slots_pfail:0cluster_slots_fail:0cluster_known_nodes:6cluster_size:3cluster_current_epoch:5cluster_my_epoch:1cluster_stats_messages_sent:2972cluster_stats_messages_received:2972172.16.1.7:6379 > cluster nodes965276bda73d2bce4a44a8fab6e18f676de54f15 172.16.1.61 slave 56572d4ef3b7e30c30a4956c87d4a6ea0050bef5 01543769558241 2 connected56572d4ef3b7e30c30a4956c87d4a6ea0050bef5 172.16.1.31 master-01543769553136 2 connected 5461-10922673443984a3610fcaa2fcbf3d295f60b2f7f32ae 172.16.1.31 master 6380 slave 82424bf0ff964ca5486b7f904b95c155e6dceeb1 01543769559263 3 connected26d3142fb8766e1cfc01978d01c17e287f4ebd38 172.16.1.61 master-01543769556196 4 connected 10923-15196 15198-1638385142215ac8c6af9ad0a72fb6ac2a5d2be2608a1 172.16.1.7master 6380 slave 26d3142fb8766e1cfc01978d01c17e287f4ebd38 01543769557220 5 connected82424bf0ff964ca5486b7f904b95c155e6dceeb1 172.16.1.76379 myself Master-01 connected 0-5460 15197
# configure cluster masterauth authentication after the cluster is created successfully, otherwise the cluster creation will fail
172.16.1.7 masterauth 6379 > config set masterauth 123456OK172.16.1.7:6379 > config get masterauth1) "masterauth" 2) "123456" 172.16.1.7 masterauth 6379 > config rewriteOK
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.