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
Is Redis a SQL or NoSQL Database? The Answer ExplainedIs Redis a SQL or NoSQL Database? The Answer ExplainedApr 18, 2025 am 12:11 AM

RedisisclassifiedasaNoSQLdatabasebecauseitusesakey-valuedatamodelinsteadofthetraditionalrelationaldatabasemodel.Itoffersspeedandflexibility,makingitidealforreal-timeapplicationsandcaching,butitmaynotbesuitableforscenariosrequiringstrictdataintegrityo

Redis: Improving Application Performance and ScalabilityRedis: Improving Application Performance and ScalabilityApr 17, 2025 am 12:16 AM

Redis improves application performance and scalability by caching data, implementing distributed locking and data persistence. 1) Cache data: Use Redis to cache frequently accessed data to improve data access speed. 2) Distributed lock: Use Redis to implement distributed locks to ensure the security of operation in a distributed environment. 3) Data persistence: Ensure data security through RDB and AOF mechanisms to prevent data loss.

Redis: Exploring Its Data Model and StructureRedis: Exploring Its Data Model and StructureApr 16, 2025 am 12:09 AM

Redis's data model and structure include five main types: 1. String: used to store text or binary data, and supports atomic operations. 2. List: Ordered elements collection, suitable for queues and stacks. 3. Set: Unordered unique elements set, supporting set operation. 4. Ordered Set (SortedSet): A unique set of elements with scores, suitable for rankings. 5. Hash table (Hash): a collection of key-value pairs, suitable for storing objects.

Redis: Classifying Its Database ApproachRedis: Classifying Its Database ApproachApr 15, 2025 am 12:06 AM

Redis's database methods include in-memory databases and key-value storage. 1) Redis stores data in memory, and reads and writes fast. 2) It uses key-value pairs to store data, supports complex data structures such as lists, collections, hash tables and ordered collections, suitable for caches and NoSQL databases.

Why Use Redis? Benefits and AdvantagesWhy Use Redis? Benefits and AdvantagesApr 14, 2025 am 12:07 AM

Redis is a powerful database solution because it provides fast performance, rich data structures, high availability and scalability, persistence capabilities, and a wide range of ecosystem support. 1) Extremely fast performance: Redis's data is stored in memory and has extremely fast read and write speeds, suitable for high concurrency and low latency applications. 2) Rich data structure: supports multiple data types, such as lists, collections, etc., which are suitable for a variety of scenarios. 3) High availability and scalability: supports master-slave replication and cluster mode to achieve high availability and horizontal scalability. 4) Persistence and data security: Data persistence is achieved through RDB and AOF to ensure data integrity and reliability. 5) Wide ecosystem and community support: with a huge ecosystem and active community,

Understanding NoSQL: Key Features of RedisUnderstanding NoSQL: Key Features of RedisApr 13, 2025 am 12:17 AM

Key features of Redis include speed, flexibility and rich data structure support. 1) Speed: Redis is an in-memory database, and read and write operations are almost instantaneous, suitable for cache and session management. 2) Flexibility: Supports multiple data structures, such as strings, lists, collections, etc., which are suitable for complex data processing. 3) Data structure support: provides strings, lists, collections, hash tables, etc., which are suitable for different business needs.

Redis: Identifying Its Primary FunctionRedis: Identifying Its Primary FunctionApr 12, 2025 am 12:01 AM

The core function of Redis is a high-performance in-memory data storage and processing system. 1) High-speed data access: Redis stores data in memory and provides microsecond-level read and write speed. 2) Rich data structure: supports strings, lists, collections, etc., and adapts to a variety of application scenarios. 3) Persistence: Persist data to disk through RDB and AOF. 4) Publish subscription: Can be used in message queues or real-time communication systems.

Redis: A Guide to Popular Data StructuresRedis: A Guide to Popular Data StructuresApr 11, 2025 am 12:04 AM

Redis supports a variety of data structures, including: 1. String, suitable for storing single-value data; 2. List, suitable for queues and stacks; 3. Set, used for storing non-duplicate data; 4. Ordered Set, suitable for ranking lists and priority queues; 5. Hash table, suitable for storing object or structured 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

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)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor