search
HomeDatabaseRedisHow to implement Redis7.0 deployment cluster

Redis7.0 Deployment Cluster Detailed Version

The cluster architecture is a way to connect multiple computers through the network and use a unified management method to externally appear as a single computer providing services

The role of the cluster:

  • Distribute the access pressure of a single server and achieve load balancing

  • Distribute the storage of a single server Pressure and achieve scalability

  • Reduce the business disaster caused by the downtime of a single server

How to implement Redis7.0 deployment cluster

1 , Redis cluster internal structure design

Data storage design

  • Through algorithm design, calculate the location where the key should be saved

  • All storage spaces are planned to be cut into 16384 parts, and each host saves a part. Each part represents a storage space, not a key storage space.

  • The key is calculated according to the The results are placed in the corresponding storage space

  • Enhance scalability (new storage space is added, officially called slot)

Internal communication design of the cluster

  • Each database communicates with each other and saves the numbered data of the slot in each library

  • Once hit, return directly

  • Once a miss, inform the specific location

2. Building the internal structure of the cluster

In the virtual machine Start multiple windows for cluster construction demonstration

How to implement Redis7.0 deployment cluster

The main command is executed on themain command operation client

Modifyredis.confConfiguration file

Add the following content

cluster-enabled yes # 启动为节点
cluster-config-file nodes-6379.conf # cluster配置文件名,该文件属于自动生成,仅用于快速查找文件并查询文件内容
cluster-node-timeout 10000 # 节点服务响应超时时间,用于判定该节点是否下线或切换为从节点
cluster-migration-barrier <count> # master连接的slave最小数量

Quickly copy 5 points of the configuration file and replace the ports inside

[root@localhost conf]# sed "s/6379/6380/g" redis-6379.conf > redis-6380.conf 
[root@localhost conf]# sed "s/6379/6381/g" redis-6379.conf > redis-6381.conf 
[root@localhost conf]# sed "s/6379/6382/g" redis-6379.conf > redis-6382.conf 
[root@localhost conf]# sed "s/6379/6383/g" redis-6379.conf > redis-6383.conf 
[root@localhost conf]# sed "s/6379/6384/g" redis-6379.conf > redis-6384.conf 
[root@localhost conf]# sed "s/6379/6385/g" redis-6379.conf > redis-6385.conf

After all execution, you can check the content through the cat command to ensure it has been modified

Start the redis service cluster

# 在第一个窗口执行6379服务
redis-server redis-6379.conf
# 在第二个窗口执行6380服务
redis-server redis-6380.conf
# 在第三个窗口执行6381服务
redis-server redis-6381.conf
# 下面的代码依次类推到6385

Execute the command to view redis Process and port

ps -ef | grep redis-

How to implement Redis7.0 deployment cluster

##Connection node

View in the src directory

redis-trib.rb

In higher versions, the startup operation has been moved to

redis-cli

Startup requires two downloads of two files, namely

ruby and gem

# 下载命令也会将gem一起
yum -y install rubygems

 # --cluster create 创建集群
 # --cluster-replicas 1 指定集群的内部结构(1代表一个master连接1个slave,2代表一个master连接两个save)
 # 后面的连接端口按数量实现master连接哪一个slave,1对1,1对2
 redis-cli --cluster create 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384 --cluster-replicas 1
The execution results are as follows

How to implement Redis7.0 deployment cluster

The results of viewing the configuration information are as follows

How to implement Redis7.0 deployment cluster

The information after executing the

yes command is as follows

How to implement Redis7.0 deployment cluster

Check the configuration file information again, which is recorded All cluster information

Start the client to store data

Because cluster deployment is used, the cluster can be operated through the

-c parameter, if not specified What is more, when operating the redis command, the prompt (error) MOVED 5798 127.0.0.1:6380

Note:

-cOperation cluster

redis-cli -c
# 创建key,通过返回信息可以知道key存储到6380下了
127.0.0.1:6379> set name 123
-> Redirected to slot [5798] located at 127.0.0.1:6380
OK
Specify the port to connect the client

# 连接指定的集群客户端
[root@localhost data]# redis-cli -c -p 6382
# 获取key
127.0.0.1:6382> get name
-> Redirected to slot [5798] located at 127.0.0.1:6380
"123"
127.0.0.1:6380>

Cluster node operation command

View cluster node information

cluster nodes

Enter a slave node redis and switch its master node

cluster replicate <master-id>

Discover a new node and add a new master node

cluster meet ip:port

Ignore a node without solt

cluster forget <id>

Manual failover

cluster failover

redis- trib command

Add node

redis-trib.rb add-node

Delete node

redis-trib.rb del-node

Reshard

redis-trib.rb reshard

3. Master-slave offline and master-slave switching

1. Simulate slave offline operation

Execute on the slave server

Ctrl CDownload service

Observe the status of the connected host , the host will mark the slave as failed if it cannot connect to the slave within 10 seconds. Other cluster services will fail to connect, and other services will receive the message

Start the slave again, and the host will reconnect. On the slave machine

If the master machine goes offline, the slave machine will switch to a certain slot. When the master machine comes back online, the original master machine will become the slave machine

The above is the detailed content of How to implement Redis7.0 deployment cluster. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:亿速云. If there is any infringement, please contact admin@php.cn delete
Redis's Server-Side Operations: What It OffersRedis's Server-Side Operations: What It OffersApr 29, 2025 am 12:21 AM

Redis'sServer-SideOperationsofferFunctionsandTriggersforexecutingcomplexoperationsontheserver.1)FunctionsallowcustomoperationsinLua,JavaScript,orRedis'sscriptinglanguage,enhancingscalabilityandmaintenance.2)Triggersenableautomaticfunctionexecutionone

Redis: Database or Server? Demystifying the RoleRedis: Database or Server? Demystifying the RoleApr 28, 2025 am 12:06 AM

Redisisbothadatabaseandaserver.1)Asadatabase,itusesin-memorystorageforfastaccess,idealforreal-timeapplicationsandcaching.2)Asaserver,itsupportspub/submessagingandLuascriptingforreal-timecommunicationandserver-sideoperations.

Redis: The Advantages of a NoSQL ApproachRedis: The Advantages of a NoSQL ApproachApr 27, 2025 am 12:09 AM

Redis is a NoSQL database that provides high performance and flexibility. 1) Store data through key-value pairs, suitable for processing large-scale data and high concurrency. 2) Memory storage and single-threaded models ensure fast read and write and atomicity. 3) Use RDB and AOF mechanisms to persist data, supporting high availability and scale-out.

Redis: Understanding Its Architecture and PurposeRedis: Understanding Its Architecture and PurposeApr 26, 2025 am 12:11 AM

Redis is a memory data structure storage system, mainly used as a database, cache and message broker. Its core features include single-threaded model, I/O multiplexing, persistence mechanism, replication and clustering functions. Redis is commonly used in practical applications for caching, session storage, and message queues. It can significantly improve its performance by selecting the right data structure, using pipelines and transactions, and monitoring and tuning.

Redis vs. SQL Databases: Key DifferencesRedis vs. SQL Databases: Key DifferencesApr 25, 2025 am 12:02 AM

The main difference between Redis and SQL databases is that Redis is an in-memory database, suitable for high performance and flexibility requirements; SQL database is a relational database, suitable for complex queries and data consistency requirements. Specifically, 1) Redis provides high-speed data access and caching services, supports multiple data types, suitable for caching and real-time data processing; 2) SQL database manages data through a table structure, supports complex queries and transaction processing, and is suitable for scenarios such as e-commerce and financial systems that require data consistency.

Redis: How It Acts as a Data Store and ServiceRedis: How It Acts as a Data Store and ServiceApr 24, 2025 am 12:08 AM

Redisactsasbothadatastoreandaservice.1)Asadatastore,itusesin-memorystorageforfastoperations,supportingvariousdatastructureslikekey-valuepairsandsortedsets.2)Asaservice,itprovidesfunctionalitieslikepub/submessagingandLuascriptingforcomplexoperationsan

Redis vs. Other Databases: A Comparative AnalysisRedis vs. Other Databases: A Comparative AnalysisApr 23, 2025 am 12:16 AM

Compared with other databases, Redis has the following unique advantages: 1) extremely fast speed, and read and write operations are usually at the microsecond level; 2) supports rich data structures and operations; 3) flexible usage scenarios such as caches, counters and publish subscriptions. When choosing Redis or other databases, it depends on the specific needs and scenarios. Redis performs well in high-performance and low-latency applications.

Redis's Role: Exploring the Data Storage and Management CapabilitiesRedis's Role: Exploring the Data Storage and Management CapabilitiesApr 22, 2025 am 12:10 AM

Redis plays a key role in data storage and management, and has become the core of modern applications through its multiple data structures and persistence mechanisms. 1) Redis supports data structures such as strings, lists, collections, ordered collections and hash tables, and is suitable for cache and complex business logic. 2) Through two persistence methods, RDB and AOF, Redis ensures reliable storage and rapid recovery of data.

See all articles

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools