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

Brief introduction of Redis Cluster Architecture

2025-04-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the knowledge of "introduction to Redis Cluster Architecture". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. Brief introduction of Redis Cluster (Redis Cluster):

(1) edis is an open source key value storage system, which is favored by the majority of Internet companies. The redis3.0 version only supports singleton mode before, and clusters are supported only in version 3.0 and later. Here I use the latest version, redis-5.0.7.

(2) redis cluster adopts P2P mode, which is completely decentralized, and there are no central nodes or proxy nodes.

(3) there is no unified entry to the redis cluster. When the client (client) connects to the cluster, it can connect to any node (node) in the cluster. The nodes in the cluster communicate with each other (PING-PONG mechanism), and each node is a redis instance.

Second, the environment needed to build the cluster:

(1) Redis cluster needs at least 3 nodes, because the voting fault tolerance mechanism requires more than half of the nodes to think that a node is dead only if it is dead, so two nodes cannot form a cluster.

(2) to ensure the high availability of the cluster, each node needs to have a slave node, that is, a backup node, so the Redis cluster needs at least 6 servers.

(3) install ruby

3. Deploy clusters:

In order to save resources, two virtual machines are prepared here, each with three network cards, so that there are a total of six network cards, that is, six redis instances are running at the same time.

Role IP address redis1192.168.220.131redis2192.168.220.164redis3192.168.220.165redis4192.168.220.135redis5192.168.220.166redis6192.168.220.167 step 1: install the redis service first step 2: modify the configuration file All nodes have the same vim / etc/redis/6379.conf1 configuration. The first step is to comment out the bind entry: / / the bind option in redis listens to all network cards by default. 2. Do the following: protected-mode no / / close protected mode port 6379 / / Open listening port daemonize yes / / start cluster-enabled yes as an independent process / / enable cluster function cluster-config-file nodes-6379.conf / / Cluster name file location cluster-node-timeout 15000 / / Cluster timeout setting appendonly yes / / enable aof persistence

(1) restart the service:

/ etc/init.d/redis_6379 restart

(2) after restarting, there will be two more files in the / var/lib/redis/6379 directory:

Appendonly.aof: persisting files

Nodes-6379.conf: the node starts the generated configuration file for the first time

Step 3: this step only needs to be done in the master master server

1. Import key Fil

Keyserver hkp://keys.gnupg.net-recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3

two。 Install rvm:

Curl-sSL https://get.rvm.io | bash-s stable

3. Execute environment variables:

Source / etc/profile.d/rvm.shrvm list known / / lists the installable versions of Ruby

4. Install the Ruby2.4.1 version

Rvm install 2.4.1

5. Use the Ruby2.4.1 version

Rvm use 2.4.1ruby-v / / View the current Ruby2.4.1 version

6. Install Redis again

Gem install redis

7. Restart redis

/ etc/init.d/redis_6379 restart step 4: create a cluster

The six instances are divided into three groups, with one master and one slave for each group.-replicas 1 means each group has one slave. When you interact below, you need to enter yes before you can create it.

Create a cluster using the redis-trib.rb tool in the source code extraction directory.

Redis-cli-- cluster create 192.168.220.131 cluster-replicas 6379 192.168.220.164purl 6379 192.168.220.165purl 6379 192.168.220.135 purl 6379 192.168.220.166 cluster-replicas 1 step 5:

1. Feel free to log in to a redis and create a pair of key values:

Redis-cli-h 192.168.220.164-p 6379 / / Connect 164this host

two。 At this point, we connect and log in to another host to check the key name

Redis-cli-h 192.168.220.131-p 6379 / / Connect to this host

This is the end of the introduction to Redis Cluster Architecture. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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