Home Database Redis How to set up a redis cluster

How to set up a redis cluster

Jun 06, 2019 pm 01:59 PM
redis cluster

How to set up a redis cluster

Brief description

In October 2018, Redis released the stable version 5.0, launching various new features, one of which was to give up Ruby's clustering method is changed to the redis-cli method written in C language, which greatly reduces the complexity of cluster construction. Updates about the cluster can be seen in the version notes of Redis5, as follows:

1

The cluster manager was ported from Ruby (redis-trib.rb) to C code inside redis-cli. check `redis-cli --cluster help ` for more info.

Copy after login

You can check the Redis official website to view the cluster construction method, the link is as follows

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

The following steps are to build a Redis cluster with 6 nodes on a Linux server.

Operation steps

Create directory

New directory:/root/software/redis

Download the source code and unzip and compile

1

2

3

4

wget http://download.redis.io/releases/redis-5.0.0.tar.gz

tar xzf redis-5.0.0.tar.gz

cd redis-5.0.0

make

Copy after login

Create 6 Redis configuration files

The 6 configuration files cannot be in the same directory. Here we define it as follows:

1

2

3

4

5

6

/root/software/redis/redis-cluster-conf/7001/redis.conf

/root/software/redis/redis-cluster-conf/7002/redis.conf

/root/software/redis/redis-cluster-conf/7003/redis.conf

/root/software/redis/redis-cluster-conf/7004/redis.conf

/root/software/redis/redis-cluster-conf/7005/redis.conf

/root/software/redis/redis-cluster-conf/7006/redis.conf

Copy after login

The content of the configuration file is:

1

2

3

4

5

6

7

8

port 7001  #端口

cluster-enabled yes #启用集群模式

cluster-config-file nodes.conf

cluster-node-timeout 5000 #超时时间

appendonly yes

daemonize yes #后台运行

protected-mode no #非保护模式

pidfile  /var/run/redis_7001.pid

Copy after login

The port and pidfile need to be adjusted according to different folders

Start the node

1

2

3

4

5

6

/root/software/redis/redis-5.0.0/src/redis-server  /root/software/redis/redis-cluster-conf/7001/redis.conf

/root/software/redis/redis-5.0.0/src/redis-server  /root/software/redis/redis-cluster-conf/7002/redis.conf

/root/software/redis/redis-5.0.0/src/redis-server  /root/software/redis/redis-cluster-conf/7003/redis.conf

/root/software/redis/redis-5.0.0/src/redis-server  /root/software/redis/redis-cluster-conf/7004/redis.conf

/root/software/redis/redis-5.0.0/src/redis-server  /root/software/redis/redis-cluster-conf/7005/redis.conf

/root/software/redis/redis-5.0.0/src/redis-server  /root/software/redis/redis-cluster-conf/7006/redis.conf

Copy after login

Start the cluster

1

/root/software/redis/redis-5.0.0/src/redis-cli --cluster create 192.168.2.40:7001 192.168.2.40:7002 192.168.2.40:7003 192.168.2.40:7004 192.168.2.40:7005 192.168.2.40:7006 --cluster-replicas 1

Copy after login

After startup, you can see the success message, as follows:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

>>> Performing hash slots allocation on 6 nodes...

Master[0] -> Slots 0 - 5460

Master[1] -> Slots 5461 - 10922

Master[2] -> Slots 10923 - 16383

Adding replica 192.168.2.40:7004 to 192.168.2.40:7001

Adding replica 192.168.2.40:7005 to 192.168.2.40:7002

Adding replica 192.168.2.40:7006 to 192.168.2.40:7003

>>> Trying to optimize slaves allocation for anti-affinity

[WARNING] Some slaves are in the same host as their master

M: 191c645200a8b4d267f71e3354c8248dbb533dde 192.168.2.40:7001

   slots:[0-5460] (5461 slots) master

M: 400a08d4e5a534c1b609988105d3e045395fbd12 192.168.2.40:7002

   slots:[5461-10922] (5462 slots) master

M: 684f6aa0fbccda295ce6818a8c01ee7255a7b002 192.168.2.40:7003

   slots:[10923-16383] (5461 slots) master

S: f2701549ae98315b432d73b49d139ee77d5685b4 192.168.2.40:7004

   replicates 684f6aa0fbccda295ce6818a8c01ee7255a7b002

S: 9fdc1e375436767ab815cbddd3df674f3bc2ca99 192.168.2.40:7005

   replicates 191c645200a8b4d267f71e3354c8248dbb533dde

S: e7742888ed85b37cff4a98e861e99bb16e8bae2c 192.168.2.40:7006

   replicates 400a08d4e5a534c1b609988105d3e045395fbd12

Can I set the above configuration? (type 'yes' to accept): yes

>>> Nodes configuration updated

>>> Assign a different config epoch to each node

>>> Sending CLUSTER MEET messages to join the cluster

Waiting for the cluster to join

....

>>> Performing Cluster Check (using node 192.168.2.40:7001)

M: 191c645200a8b4d267f71e3354c8248dbb533dde 192.168.2.40:7001

   slots:[0-5460] (5461 slots) master

   1 additional replica(s)

M: 684f6aa0fbccda295ce6818a8c01ee7255a7b002 192.168.2.40:7003

   slots:[10923-16383] (5461 slots) master

   1 additional replica(s)

S: 9fdc1e375436767ab815cbddd3df674f3bc2ca99 192.168.2.40:7005

   slots: (0 slots) slave

   replicates 191c645200a8b4d267f71e3354c8248dbb533dde

S: e7742888ed85b37cff4a98e861e99bb16e8bae2c 192.168.2.40:7006

   slots: (0 slots) slave

   replicates 400a08d4e5a534c1b609988105d3e045395fbd12

M: 400a08d4e5a534c1b609988105d3e045395fbd12 192.168.2.40:7002

   slots:[5461-10922] (5462 slots) master

   1 additional replica(s)

S: f2701549ae98315b432d73b49d139ee77d5685b4 192.168.2.40:7004

   slots: (0 slots) slave

   replicates 684f6aa0fbccda295ce6818a8c01ee7255a7b002

[OK] All nodes agree about slots configuration.

>>> Check for open slots...

>>> Check slots coverage...

[OK] All 16384 slots covered.

Copy after login

At this point, the Reids cluster is completed.

The above is the detailed content of How to set up a redis cluster. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Implementing Redis cluster using ThinkPHP6 Implementing Redis cluster using ThinkPHP6 Jun 20, 2023 am 08:36 AM

With the rapid development of the Internet, the problem of high concurrency has become more and more prominent. In response to this problem, the emergence of Redis has become an important solution. It solves the problem of excessive reading and writing pressure in traditional relational databases through memory reading and writing. However, single-node Redis still has performance bottlenecks under high concurrency conditions, so Redis clusters need to be used. This article will describe how to use ThinkPHP6 to implement a Redis cluster. 1. Introduction to Redis Cluster Redis Cluster is an official cluster provided by Redis.

Redis and Node.js cluster solution: how to achieve high availability Redis and Node.js cluster solution: how to achieve high availability Jul 29, 2023 pm 05:42 PM

Cluster solution for Redis and Node.js: How to achieve high availability Introduction: With the rapid development of the Internet, data processing has become increasingly large and complex. In order to ensure high availability and scalability of the system, we need to use a distributed cluster architecture to handle the needs of storing and processing large amounts of data. Redis, as a high-performance in-memory database, combined with Node.js as the back-end programming language, can build a highly available distributed cluster solution. This article will introduce how to use Redis and Node.js to implement

Redis cluster in Redis and how to use PHP Redis cluster in Redis and how to use PHP May 15, 2023 pm 03:22 PM

Redis is a powerful in-memory key-value pair storage database. It has higher performance and better scalability than regular RDBMS (relational database management system). One of the advantages of Redis is that it can be used as the core technology of distributed systems. In this article, we will explore the concept of Redis Cluster and how to use Redis Cluster in PHP. What is Redis cluster? Simply put, a Redis cluster is an aggregation of multiple Redis instances. Redis cluster allows us

Learn database functions in Go language and implement read and write operations in Redis cluster Learn database functions in Go language and implement read and write operations in Redis cluster Jul 29, 2023 pm 12:21 PM

Learn the database functions in Go language and implement read and write operations in Redis cluster Introduction: Database is an indispensable part of today's Internet applications, and Go language, as a simple and efficient programming language, also has good database operation capabilities. This article will introduce how to use database functions in Go language and implement read and write operations in Redis cluster. 1. Database functions in Go language Database operations in Go language are mainly implemented through the database/sql package. This package provides basic data

How to implement cluster deployment of PHP data cache through Redis? How to implement cluster deployment of PHP data cache through Redis? Aug 10, 2023 am 08:13 AM

How to implement cluster deployment of PHP data cache through Redis? Introduction: When PHP applications face high concurrency and large traffic, they often encounter database performance bottlenecks. At this time, using caching technology can greatly improve the performance and concurrency of the system. As a high-performance in-memory key-value database, Redis is widely used in the implementation of caching solutions. This article will introduce how to implement cluster deployment of PHP data cache through Redis to further improve performance and scalability. 1. Overview of Redis Cluster Redis

Redis and PHP cluster solution: how to achieve high availability and scalability Redis and PHP cluster solution: how to achieve high availability and scalability Jul 30, 2023 pm 08:51 PM

Redis and PHP cluster solution: How to achieve high availability and scalability Introduction: Redis is an open source, high-performance in-memory database that is often used to build fast and scalable applications. As a popular server-side scripting language, PHP can be used with Redis to achieve high availability and scalability cluster solutions. This article will introduce how to use Redis and PHP to build a high-availability and scalable cluster, and explain in detail through code examples. 1. Construction, installation and configuration of Redis cluster Re

How to use Redis and Julia languages ​​to implement high-availability cluster functions How to use Redis and Julia languages ​​to implement high-availability cluster functions Sep 20, 2023 am 10:58 AM

How to use Redis and Julia languages ​​to implement high-availability cluster functions Introduction: With the development of Internet business, the requirements for system availability are getting higher and higher. To ensure that systems can continue to provide services in the event of a failure, high availability has become one of the key requirements in various industries. This article will introduce how to use Redis and Julia languages ​​to implement high-availability cluster functions, and provide specific code examples. 1. What is a high-availability cluster? A high-availability cluster organizes multiple nodes together to form an overall system.

Redis cluster expansion plan and implementation details Redis cluster expansion plan and implementation details Jun 21, 2023 am 10:58 AM

Redis is a high-performance open source memory data storage service. It is increasingly favored by developers because of its fast read and write speed, persistent storage and support for multiple data structures. As the business continues to grow, the storage capacity of Redis can no longer meet the demand, and it needs to be expanded. This article will introduce the Redis cluster expansion plan and its implementation details. The concept of Redis cluster Redis cluster refers to connecting multiple Redis instances together to form a large set of Redis instances, which can improve Redis

See all articles