Redis集群部署及常用的操作命令
简单说下自己测试搭建简单的Redis集群的大体步骤: 1.首先你的有6个redis(官方说最少6个,3master,3slave),可以先在一台机器
简单说下自己测试搭建简单的Redis集群的大体步骤:
1.首先你的有6个redis(官方说最少6个,3master,3slave),可以先在一台机器上搭建,搭建到多台上应该只需要改变启动命令即可(可能需要一些ssh无密钥什么的,只是猜测)
在网上随便可以找到的配置多个redis,(总体有两种方式,一种是虚拟的,貌似走的都是一个redis,一种是将配置好的redis复制成六份,配置相应的端口等,我选择的后者显得更真实一些)
然后把他们全部打开,可以写一个脚本,或者一个一个打开,作为一个新世纪的年轻人,我当然选择一个一个打开它们......
[root@localhost ~]# ps -ef | grep redis
root 3427 1 0 7月17 ? 00:02:59 src/redis-server *:6379
root 3454 1 0 7月17 ? 00:06:09 src/redis-server *:7001 [cluster]
root 3460 1 0 7月17 ? 00:06:19 src/redis-server *:7002 [cluster]
root 3467 1 0 7月17 ? 00:05:59 src/redis-server *:7003 [cluster]
root 3473 1 0 7月17 ? 00:05:59 src/redis-server *:7004 [cluster]
root 3477 1 0 7月17 ? 00:05:57 src/redis-server *:7005 [cluster]
root 5867 1 0 12:02 ? 00:00:06 src/redis-server *:7000 [cluster]
root 5938 5913 0 13:17 pts/1 00:00:00 grep --color=auto redis
2.将6个独立redis设置为集群,so easy 一句话搞定。其中 --replicas 参数是将6台redis分别分配了主从关系(master挂掉slave可以顶替,但是还没有具体深入研究)
./redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005
在开启过程中可能会遇到很多问题,各种奇怪的报错,那就要安装ruby和gem的一些东东,搞不明白是什么,反正就是依赖吧~ ,只能说按照这个来会绕开很多坑。
# yum install ruby-devel.x86_64
# wget
# gem install -l ./redis-3.2.1.gem
执行这些代码之后再去执行上面建立集群的命令,如果成功的话,会看到下面的样子:
>>> Creating cluster
Connecting to node 127.0.0.1:7000: OK
Connecting to node 127.0.0.1:7001: OK
Connecting to node 127.0.0.1:7002: OK
Connecting to node 127.0.0.1:7003: OK
Connecting to node 127.0.0.1:7004: OK
Connecting to node 127.0.0.1:7005: OK
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
127.0.0.1:7000
127.0.0.1:7001
127.0.0.1:7002
Adding replica 127.0.0.1:7003 to 127.0.0.1:7000
Adding replica 127.0.0.1:7004 to 127.0.0.1:7001
Adding replica 127.0.0.1:7005 to 127.0.0.1:7002
M: ad52e4f7c14da4b8b1e8e48603c9e5515a4cec7a 127.0.0.1:7000
slots:0-5460 (5461 slots) master
M: d3058a19483d7be5c30c042779e56130f6ebf074 127.0.0.1:7001
slots:5461-10922 (5462 slots) master
M: 5814305e71552ab45c44b9b8233681a63c3a57b1 127.0.0.1:7002
slots:10923-16383 (5461 slots) master
S: e50676757acbe7c6a21e8abf4eda26ababb08285 127.0.0.1:7003
replicates ad52e4f7c14da4b8b1e8e48603c9e5515a4cec7a
S: ab307ba26d6dabe8edb2f2a7287be6f01aa46d88 127.0.0.1:7004
replicates d3058a19483d7be5c30c042779e56130f6ebf074
S: 11174332eb6ad40c0327750536fa776d706caf85 127.0.0.1:7005
replicates 5814305e71552ab45c44b9b8233681a63c3a57b1
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 127.0.0.1:7000)
M: ad52e4f7c14da4b8b1e8e48603c9e5515a4cec7a 127.0.0.1:7000
slots:0-5460 (5461 slots) master
M: d3058a19483d7be5c30c042779e56130f6ebf074 127.0.0.1:7001
slots:5461-10922 (5462 slots) master
M: 5814305e71552ab45c44b9b8233681a63c3a57b1 127.0.0.1:7002
slots:10923-16383 (5461 slots) master
M: e50676757acbe7c6a21e8abf4eda26ababb08285 127.0.0.1:7003
slots: (0 slots) master
replicates ad52e4f7c14da4b8b1e8e48603c9e5515a4cec7a
M: ab307ba26d6dabe8edb2f2a7287be6f01aa46d88 127.0.0.1:7004
slots: (0 slots) master
replicates d3058a19483d7be5c30c042779e56130f6ebf074
M: 11174332eb6ad40c0327750536fa776d706caf85 127.0.0.1:7005
slots: (0 slots) master
replicates 5814305e71552ab45c44b9b8233681a63c3a57b1
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
3.测试集群。
可以用下面的命令查看集群的状态,从下面可以看出有4个master,2个slave~~~,这个是由于我太年轻kill了7000的redis又加入了进来,原先他的slave 7003 也变成了master顶替了他。

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

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

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.

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 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

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

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

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 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 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
