Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Redis Cluster-- installation configuration

2025-02-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Background

This article is mainly about the installation of Redis Cluster, let's use it first, feel what's going on, and then continue to learn about how to Cluster how to failover, add nodes, delete nodes, migrate slots and other functions.

Characteristics of Redis Cluster

(1) there are 16384 (0-16383) hash slots in Redis Cluster. When data is written, it is allocated to different nodes according to CRC16 ('key') 384hash slots.

(2) when the crash of some nodes in the whole cluster does not affect the continued use, if there is a cluster composed of three master of AMagi BMague C and three slave of A1 Magi B1, if B goes down, B1 will be automatically upgraded to master, and when B is restored, it will also automatically become the slave of B1 to ensure the high availability of the cluster.

(3) when the cluster load is too high to support the current business, you can add empty nodes, and then rebalance slot or reshard slot

Install Redis Cluster

(1) Environmental preparation

Redis version is 3.2.9. There are 6 redis instances running on 6 different hosts, including 3 as Master and 3 as their Slave respectively. The port uses the default port 6379.

Master1: sht-sgmhadoopcm-01 (172.16.101.54)

Slave1: sht-sgmhadoopdn-01 (172.16.101.58)

Master2: sht-sgmhadoopnn-01 (172.16.101.55)

Slave2: sht-sgmhadoopdn-02 (172.16.101.59)

Master3: sht-sgmhadoopnn-02 (172.16.101.56)

Slave3: sht-sgmhadoopdn-03 (172.16.101.60)

Modify the configuration file, which needs to be executed by each node, and modify the IP address of other nodes.

[root@sht-sgmhadoopcm-01 redis] # vim redis.confport 6379bind 172.16.101.54 appendonly yescluster-enabled yescluster-config-file nodes-6379.confcluster-node-timeout 15000

(2) install ruby on the nodes that need ruby

[root@sht-sgmhadoopcm-01 redis] # yum install ruby-y

The following step may report an error because the default version of ruby2.0.0 installed by CentOS7.3 is too low.

[root@sht-sgmhadoopcm-01 redis] # gem install redisFetching: redis-4.0.1.gem Successfully installed redis-4.0.1Parsing documentation for redis-4.0.1Installing ri documentation for redis-4.0.1Done installing documentation for redis after 2 seconds1 gem installed

(3) start all nodes

[root@sht-sgmhadoopcm-01 redis] # src/redis-server redis.conf [root@sht-sgmhadoopnn-02 redis] # src/redis-server redis.conf [root@sht-sgmhadoopnn-01 redis] # src/redis-server redis.conf [root@sht-sgmhadoopdn-01 redis] # src/redis-server redis.conf [root@sht-sgmhadoopdn-02 redis] # src/redis-server redis.conf [root@sht-sgmhadoopdn-03 redis] # src/redis-server redis.conf [root@sht-sgmhadoopnn -02 redis] # ps-ef | grep redisroot 1716 10 12:40? 00:00:00 src/redis-server 172.16.101.56 ef [cluster] root 1720 1504 0 12:41 pts/2 00:00:00 grep-- color=auto redis

(4) use redis-trib.rb script to create cluster

In the process of Create, hash slots has been assigned to three master and Slave has been worked out.

Option-replicas 1 means to create a slave server node for each created master server node

[root@sht-sgmhadoopcm-01 redis] # ruby src/redis-trib.rb create-- replicas 1 172.16.101.54 replicas 6379172.16.101.55 Performing hash slots allocation on 6379172.16.101.56 Performing hash slots allocation on 679 172.16.101.58 172.16.101.58 to 172.16.101.54:6379Adding replica 172.16.101.59 to 172.16.101.55:6379Adding replica 172.16.101.60 to 172.16.101.56 slots:0 6379M: 610aa83831404be545b25cc7f7322e987da1dd33 172.16.101.54 slots:0-5460 (5461 slots) masterM: 4c7348ac575a1a3bd4357e937a8f94f1654193cf 172.16.101.55 masterM 6379 slots:5461-10922 (5462 slots) masterM: ece3a80f6989fa7f8316d73ee30ceea84340f24e 172.16.101.56 masterM 6379 slots:10923-16383 (5461 slots) masterS: 28e8d5c8fd12533622d8110f8d262cb50120ca02 172.16.101.58 b50ba506525ee547823b3d9a7e5a095933e3ff42 6379 replicates 610aa83831404be545b25cc7f7322e987da1dd33S: b50ba506525ee547823b3d9a7e5a095933e3ff42 172.16.101.59 28e8d5c8fd12533622d8110f8d262cb50120ca02 6379 replicates 4c7348ac575a1a3bd4357e937a8f94f1654193cfS: c79de1092011ed395ee772969274c0567c2b5dd1 172.16.101.60 b50ba506525ee547823b3d9a7e5a095933e3ff42? (type 'yes' to accept): yes > > Nodes configuration updated > > Assign a different config epoch to each node > > Sending CLUSTER MEET messages to join the clusterWaiting for the cluster to join. > > Performing Cluster Check (using node 172.16.101.54 master 6379) M: 610aa83831404be545b25cc7f7322e987da1dd33 172.16.101.54 master 6379 slots:0-5460 (5461 slots) master 1 additional replica (s) S: b50ba506525ee547823b3d9a7e5a095933e3ff42 172.16.101.59 master 6379 slots: (0 slots) slave replicates 4c7348ac575a1a3bd4357e937a8f94f1654193cfS: 28e8d5c8fd12533622d8110f8d262cb50120ca02 172.16.101.58: 6379 slots: (0 slots) slave replicates 610aa83831404be545b25cc7f7322e987da1dd33M: 4c7348ac575a1a3bd4357e937a8f94f1654193cf 172.16.101.55 master 6379 slots:5461-10922 (5462 slots) master 1 additional replica (s) M: ece3a80f6989fa7f8316d73ee30ceea84340f24e 172.16.101.56 slots:10923-16383 (5461 slots) master 1 additional replica (s) S: c79de1092011ed395ee772969274c0567c2b5dd1 172.16.101.60 master 6379 slots: (0 slots) slave replicates ece3a80f6989fa7f8316d73ee30ceea84340f24e [OK] All nodes agree about slots configuration. > Check for open slots... > > Check slots coverage... [OK] All 16384 slots covered.

(5) View the basic information of Cluster

[root@sht-sgmhadoopcm-01 redis] # src/redis-cli-c-h 172.16.101.54-p 6379172.16.101.54 info replication# Replicationrole:masterconnected_slaves:1slave0:ip=172.16.101.58,port=6379,state=online,offset=2591 Lag=0master_repl_offset:2591repl_backlog_active:1repl_backlog_size:1048576repl_backlog_first_byte_offset:2repl_backlog_histlen:2590172.16.101.54:6379 > cluster infocluster_state:okcluster_slots_assigned:16384cluster_slots_ok:16384cluster_slots_pfail:0cluster_slots_fail:0cluster_known_nodes:6cluster_size:3cluster_current_epoch:6cluster_my_epoch:1cluster_stats_messages_sent:4462cluster_stats_messages_received:4462172.16.101.54:6379 > cluster Nodesb50ba506525ee547823b3d9a7e5a095933e3ff42 172.16.101.59:6379 slave 4c7348ac575a1a3bd4357e937a8f94f1654193cf 0 1532497136876 5 connected610aa83831404be545b25cc7f7322e987da1dd33 172.16.101.54:6379 myself Master-00 1 connected 0-546028e8d5c8fd12533622d8110f8d262cb50120ca02 172.16.101.58 connected4c7348ac575a1a3bd4357e937a8f94f1654193cf 6379 slave 610aa83831404be545b25cc7f7322e987da1dd33 01532497135872 4 connected4c7348ac575a1a3bd4357e937a8f94f1654193cf 172.16.101.551579 master-01532497133867 2 connected 5461-10922ece3a80f6989fa7f8316d73ee30ceea84340f24e 172.16.101.56 slave 610aa83831404be545b25cc7f7322e987da1dd33 6379 master-0153249134870 3 connected 10923-16383c79de1092011ed395ee772969274c0567c2b5dd1 172.101.60 slave ece3a80f6989fa7f8316d73ee30ceea84340f24e 01532497137878 6 connected [root@sht-sgmhadoopcm-01 redis] # cat nodes-6379.confb50ba506525ee547823b3d9a7e5a095933e3ff42 172.16.101.59 slave 4c7348ac575a1a3bd4357e937a8f94f1654193cf 01532493960094 connected610aa83831404be545b25cc7f7322e987da1dd33 172.16.101.54 Master-01 connected 0-546028e8d5c8fd12533622d8110f8d262cb50120ca02 172.16.101.58 connected4c7348ac575a1a3bd4357e937a8f94f1654193cf 6379 slave 610aa83831404be545b25cc7f7322e987da1dd33 01532493955077 4 connected4c7348ac575a1a3bd4357e937a8f94f1654193cf 172.16.101.55 slave ece3a80f6989fa7f8316d73ee30ceea84340f24e 01532493958087 2 connected 5461-10922ece3a80f6989fa7f8316d73ee30ceea84340f24e 172.16.101.56 slave ece3a80f6989fa7f8316d73ee30ceea84340f24e 01532493956080 3 connected 1093956080 3 16383c79de1092011ed395ee772969274c0567c2b5dd1 172.16.101.60 slave ece3a80f6989fa7f8316d73ee30ceea84340f24e 01532493959091 6 connectedvars currentEpoch 6 lastVoteEpoch 0

FAQ

Error1: ruby2.0.0 version is too low

[root@sht-sgmhadoopcm-01 redis] # gem install redisFetching: redis-4.0.1.gem ERROR: Error installing redis: redis requires Ruby version > = 2.2.2.

Solution:

[root@sht-sgmhadoopcm-01 redis] # ruby-- versionruby 2.0.0p648 (2015-12-16) [x86_64-linux] [root@sht-sgmhadoopcm-01 redis] # gpg-keyserver hkp://keys.gnupg.net-recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB [root@sht-sgmhadoopcm-01 redis] # curl-sSL https://get.rvm.io | bash-s stable [root@sht-sgmhadoopcm-01 redis] # find /-name rvm-print/usr/local/rvm/usr / local/rvm/src/rvm/usr/local/rvm/src/rvm/bin/rvm/usr/local/rvm/src/rvm/lib/rvm/usr/local/rvm/src/rvm/scripts/rvm/usr/local/rvm/bin/rvm/usr/local/rvm/lib/rvm/usr/local/rvm/scripts/rvm [root@sht-sgmhadoopcm-01 redis] # source / usr/local/rvm/scripts/rvm [root@sht-sgmhadoopcm-01 redis] # rvm list known [root@sht -sgmhadoopcm-01 redis] # rvm install 2.4.1 [root@sht-sgmhadoopcm-01 redis] # rvm use 2.4.1Using / usr/local/rvm/gems/ruby-2.4.1 [root@sht-sgmhadoopcm-01 redis] # rvm use 2.4.1-defaultUsing / usr/local/rvm/gems/ruby-2.4.1 [root@sht-sgmhadoopcm-01 redis] # rvm remove 2.3.4ruby-2.3.4-# already goneUsing / usr/local/rvm / gems/ruby-2.4.1 [root@sht-sgmhadoopcm-01 redis] # ruby--versionruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]

Error2: add node data is not empty

[root@sht-sgmhadoopcm-01 redis] # src/redis-trib.rb add-node 172.16.101.66:6379 172.16.101.54:6379. [ERR] Node 172.16.101.66:6379 is not empty. Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in database 0.

Solution:

(1) Delete aof and rdb files

(2) Delete nodes-6379.conf configuration file

(3) execute flushdb and flushall

Reference link

Https://redis.io/topics/cluster-tutorial

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report