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
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
The main command is executed on the
main command operation client
Modifyredis.conf
Configuration 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-
View in the src directoryThe execution results are as followsredis-trib.rb
In higher versions, the startup operation has been moved toredis-cli
Startup requires two downloads of two files, namelyruby
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
yes command is as follows
Check the configuration file information again, which is recorded All cluster informationStart the client to store data
Because cluster deployment is used, the cluster can be operated through theSpecify the port to connect the client-c
Note:parameter, if not specified What is more, when operating the redis command, the prompt
(error) MOVED 5798 127.0.0.1:6380-c
Operation 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
# 连接指定的集群客户端 [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 informationcluster nodesEnter 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:portIgnore a node without solt
cluster forget <id>Manual failover
cluster failover
redis- trib command
Add noderedis-trib.rb add-nodeDelete node
redis-trib.rb del-nodeReshard
redis-trib.rb reshard3. Master-slave offline and master-slave switching1. Simulate slave offline operation
Execute on the slave serverObserve 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 machineCtrl C
Download service
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!

Redis是现在最热门的key-value数据库,Redis的最大特点是key-value存储所带来的简单和高性能;相较于MongoDB和Redis,晚一年发布的ES可能知名度要低一些,ES的特点是搜索,ES是围绕搜索设计的。

本篇文章给大家带来了关于redis的相关知识,其中主要介绍了关于redis的一些优势和特点,Redis 是一个开源的使用ANSI C语言编写、遵守 BSD 协议、支持网络、可基于内存、分布式存储数据库,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于redis的相关知识,其中主要介绍了Redis Cluster集群收缩主从节点的相关问题,包括了Cluster集群收缩概念、将6390主节点从集群中收缩、验证数据迁移过程是否导致数据异常等,希望对大家有帮助。

本篇文章给大家带来了关于redis的相关知识,其中主要介绍了Redis实现排行榜及相同积分按时间排序,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,希望对大家有帮助。

本篇文章给大家带来了关于redis的相关知识,其中主要介绍了关于原子操作中命令原子性的相关问题,包括了处理并发的方案、编程模型、多IO线程以及单命令的相关内容,下面一起看一下,希望对大家有帮助。

本篇文章给大家带来了关于redis的相关知识,其中主要介绍了Redis实现排行榜及相同积分按时间排序,本文通过实例代码给大家介绍的非常详细,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于redis的相关知识,其中主要介绍了bitmap问题,Redis 为我们提供了位图这一数据结构,位图数据结构其实并不是一个全新的玩意,我们可以简单的认为就是个数组,只是里面的内容只能为0或1而已,希望对大家有帮助。

redis error就是redis数据库和其组合使用的部件出现错误,这个出现的错误有很多种,例如Redis被配置为保存数据库快照,但它不能持久化到硬盘,用来修改集合数据的命令不能用。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.