search
HomeDatabaseRedisHow to build a redis cluster under centos

How to build a redis cluster under centos

May 27, 2023 am 10:04 AM
rediscentos

Essential tools:

redis-3.0.0.tar

redis-3.0.0.gem (ruby and redis interface)

Analysis:

First of all, the number of clusters requires a base number. Here is a simple redis cluster (6 redis instances for clustering).

Operates on one server, so only 6 different port numbers are required. They are: 7001, 7002, 7003, 7004, 7005, 7006.

Steps:

1. Upload redis-3.0.0.tar to the server (specify your own software directory), and decompress redis-3.0.0.tar.

2. Install the c language environment (after installing centos, it comes with the c language environment)

yum install gcc-c++

3. Enter the redis-3.0.0 directory

make

4. Install redis to the /usr/local/redis directory

make install prefix=/usr/local/redis

5. Check whether the installation is successful (the bin directory appears)

How to build a redis cluster under centos

6. Start redis on the front end ( Enter the bin directory in the picture above)

./redis-server (open)

./redis-cli shutdown (close)

How to build a redis cluster under centos

7. Backend startup

You need to copy the redis.conf file in the redis decompressed source package (under the redis-3.0.0 directory) to the bin directory

Modify redis.conf file, change daemonize to yes first use vim redis.conf

How to build a redis cluster under centos

Use the command backend to start redis

Execute in the bin directory./redis-server redis.conf

Check whether the startup is successful

How to build a redis cluster under centos

How to close the backend startup:

./redis-cli shutdown

The above is a separate redis installation, then Come down and build a cluster!

Install ruby

yum install ruby
yum install rubygems

Upload the following files to the linux system

redis-3.0.0.gem (ruby and redis interface)

Enter the directory and execute: gem install redis-3.0.0.gem

Copy the following files in the src directory under the redis-3.0.0 package to /usr/local/ redis/redis-cluster/

Prerequisite: Create a new redis-cluster directory first

How to build a redis cluster under centos

Building a cluster requires at least 3 hosts. If each host If you configure another slave machine, at least 6 machines are required.

The port design is as follows: 7001-7006

Step 1: Copy a 7001 machine

Enter the /usr/local/redis/ directory and execute cp bin ./redis- cluster/7001 –r

Step 2: If persistent files exist, delete

rm -rf appendonly.aof dump.rdb

Step 3: Set cluster parameters

How to build a redis cluster under centos

Step 4: Modify the port

How to build a redis cluster under centos

Step 5: Copy the 7002-7006 machine

Give me the directory structure of the desktop system:

How to build a redis cluster under centos

Next, set up one-click to start all redis or close the redis group:

First, create a new file. You can use vim to open a file that does not exist, and then The save exists. (The start-all.sh and shutdown-all.sh in the picture above are the ones I created)

start-all.sh:

cd 7001
./redis-server redis.conf
cd ..
cd 7002
./redis-server redis.conf
cd ..
cd 7003
./redis-server redis.conf
cd ..
cd 7004
./redis-server redis.conf
cd ..
cd 7005
./redis-server redis.conf
cd ..
cd 7006
./redis-server redis.conf
cd ..

shutdow-all.sh:

cd 7001
./redis-cli -p 7001 shutdown
cd ..
cd 7002
./redis-cli -p 7002 shutdown
cd ..
cd 7003
./redis-cli -p 7003 shutdown
cd ..
cd 7004
./redis-cli -p 7004 shutdown
cd ..
cd 7005
./redis-cli -p 7005 shutdown
cd ..
cd 7006
./redis-cli -p 7006 shutdown
cd ..

Next modify the permissions of those two files and set them as startable script files

chmod u+x start-all.sh

chmod u+x shutdown-all.sh

Next use ruby ​​to connect these clusters for management

/redis-trib.rb create --replicas 1 192.168.78.133:7001 192.168.78.133:7002 192.168.78.133:7003 192.168.78.133:7004 192.168.78.133:7005 192.168.78.133: 7006

appears:

connecting to node 192.168.242.137:7001: ok
connecting to node 192.168.242.137:7002: ok
connecting to node 192.168.242.137:7003: ok
connecting to node 192.168.242.137:7004: ok
connecting to node 192.168.242.137:7005: ok
connecting to node 192.168.242.137:7006: ok
>>> performing hash slots allocation on 6 nodes...
using 3 masters:
192.168.242.137:7001
192.168.242.137:7002
192.168.242.137:7003
adding replica 192.168.242.137:7004 to 192.168.242.137:7001
adding replica 192.168.242.137:7005 to 192.168.242.137:7002
adding replica 192.168.242.137:7006 to 192.168.242.137:7003
m: 8240cd0fe6d6f842faa42b0174fe7c5ddcf7ae24 192.168.242.137:7001
  slots:0-5460 (5461 slots) master
m: 4f52a974f64343fd9f1ee0388490b3c0647a4db7 192.168.242.137:7002
  slots:5461-10922 (5462 slots) master
m: cb7c5def8f61df2016b38972396a8d1f349208c2 192.168.242.137:7003
  slots:10923-16383 (5461 slots) master
s: 66adf006fed43b3b5e499ce2ff1949a756504a16 192.168.242.137:7004
  replicates 8240cd0fe6d6f842faa42b0174fe7c5ddcf7ae24
s: cbb0c9bc4b27dd85511a7ef2d01bec90e692793b 192.168.242.137:7005
  replicates 4f52a974f64343fd9f1ee0388490b3c0647a4db7
s: a908736eadd1cd06e86fdff8b2749a6f46b38c00 192.168.242.137:7006
  replicates cb7c5def8f61df2016b38972396a8d1f349208c2
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.242.137:7001)
m: 8240cd0fe6d6f842faa42b0174fe7c5ddcf7ae24 192.168.242.137:7001
  slots:0-5460 (5461 slots) master
m: 4f52a974f64343fd9f1ee0388490b3c0647a4db7 192.168.242.137:7002
  slots:5461-10922 (5462 slots) master
m: cb7c5def8f61df2016b38972396a8d1f349208c2 192.168.242.137:7003
  slots:10923-16383 (5461 slots) master
m: 66adf006fed43b3b5e499ce2ff1949a756504a16 192.168.242.137:7004
  slots: (0 slots) master
  replicates 8240cd0fe6d6f842faa42b0174fe7c5ddcf7ae24
m: cbb0c9bc4b27dd85511a7ef2d01bec90e692793b 192.168.242.137:7005
  slots: (0 slots) master
  replicates 4f52a974f64343fd9f1ee0388490b3c0647a4db7
m: a908736eadd1cd06e86fdff8b2749a6f46b38c00 192.168.242.137:7006
  slots: (0 slots) master
  replicates cb7c5def8f61df2016b38972396a8d1f349208c2
[ok] all nodes agree about slots configuration.
>>> check for open slots...
>>> check slots coverage...
[ok] all 16384 slots covered.

It means success!

Test it, enter the 7001 directory and execute: ./redis-cli -h 192.168.242.137 -p 7001 –c

How to build a redis cluster under centos

The above is the detailed content of How to build a redis cluster under centos. 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: Beyond SQL - The NoSQL PerspectiveRedis: Beyond SQL - The NoSQL PerspectiveMay 08, 2025 am 12:25 AM

Redis goes beyond SQL databases because of its high performance and flexibility. 1) Redis achieves extremely fast read and write speed through memory storage. 2) It supports a variety of data structures, such as lists and collections, suitable for complex data processing. 3) Single-threaded model simplifies development, but high concurrency may become a bottleneck.

Redis: A Comparison to Traditional Database ServersRedis: A Comparison to Traditional Database ServersMay 07, 2025 am 12:09 AM

Redis is superior to traditional databases in high concurrency and low latency scenarios, but is not suitable for complex queries and transaction processing. 1.Redis uses memory storage, fast read and write speed, suitable for high concurrency and low latency requirements. 2. Traditional databases are based on disk, support complex queries and transaction processing, and have strong data consistency and persistence. 3. Redis is suitable as a supplement or substitute for traditional databases, but it needs to be selected according to specific business needs.

Redis: Introduction to a Powerful In-Memory Data StoreRedis: Introduction to a Powerful In-Memory Data StoreMay 06, 2025 am 12:08 AM

Redisisahigh-performancein-memorydatastructurestorethatexcelsinspeedandversatility.1)Itsupportsvariousdatastructureslikestrings,lists,andsets.2)Redisisanin-memorydatabasewithpersistenceoptions,ensuringfastperformanceanddatasafety.3)Itoffersatomicoper

Is Redis Primarily a Database?Is Redis Primarily a Database?May 05, 2025 am 12:07 AM

Redis is primarily a database, but it is more than just a database. 1. As a database, Redis supports persistence and is suitable for high-performance needs. 2. As a cache, Redis improves application response speed. 3. As a message broker, Redis supports publish-subscribe mode, suitable for real-time communication.

Redis: Database, Server, or Something Else?Redis: Database, Server, or Something Else?May 04, 2025 am 12:08 AM

Redisisamultifacetedtoolthatservesasadatabase,server,andmore.Itfunctionsasanin-memorydatastructurestore,supportsvariousdatastructures,andcanbeusedasacache,messagebroker,sessionstorage,andfordistributedlocking.

Redis: Unveiling Its Purpose and Key ApplicationsRedis: Unveiling Its Purpose and Key ApplicationsMay 03, 2025 am 12:11 AM

Redisisanopen-source,in-memorydatastructurestoreusedasadatabase,cache,andmessagebroker,excellinginspeedandversatility.Itiswidelyusedforcaching,real-timeanalytics,sessionmanagement,andleaderboardsduetoitssupportforvariousdatastructuresandfastdataacces

Redis: A Guide to Key-Value Data StoresRedis: A Guide to Key-Value Data StoresMay 02, 2025 am 12:10 AM

Redis is an open source memory data structure storage used as a database, cache and message broker, suitable for scenarios where fast response and high concurrency are required. 1.Redis uses memory to store data and provides microsecond read and write speed. 2. It supports a variety of data structures, such as strings, lists, collections, etc. 3. Redis realizes data persistence through RDB and AOF mechanisms. 4. Use single-threaded model and multiplexing technology to handle requests efficiently. 5. Performance optimization strategies include LRU algorithm and cluster mode.

Redis: Caching, Session Management, and MoreRedis: Caching, Session Management, and MoreMay 01, 2025 am 12:03 AM

Redis's functions mainly include cache, session management and other functions: 1) The cache function stores data through memory to improve reading speed, and is suitable for high-frequency access scenarios such as e-commerce websites; 2) The session management function shares session data in a distributed system and automatically cleans it through an expiration time mechanism; 3) Other functions such as publish-subscribe mode, distributed locks and counters, suitable for real-time message push and multi-threaded systems and other scenarios.

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

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools