Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed instructions for building and using redis5 cluster under Linux (Centos7)

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

1. Brief description

In October 2018, Redis released a stable version of version 5.0, and introduced a variety of new features, one of which is to abandon the cluster mode of Ruby and change to redis-cli written in C language, which greatly reduces the complexity of cluster construction. Updates to the cluster can be found in the release notes for Redis5, as follows:

The cluster manager was ported from Ruby (redis-trib.rb) to C code inside redis-cli. Check `redis-cli-- cluster help `for more info.

You can check the Redis official website to see how the cluster is built. The connection is as follows

Https://redis.io/topics/cluster-tutorial

There should be at least three nodes in the cluster, each with a backup node. Six servers are required.

If the conditions are limited, pseudo-distribution can be built. The following step is to build a Redis cluster with 6 nodes on a Linux server.

2. Create a cluster step 2.1, create a directory

Create a new directory: mkdir / usr/local/redis-cluster

Download the source code, decompress and compile ​ wget http://download.redis.io/releases/redis-5.0.0.tar.gztar xzf redis-5.0.0.tar.gzcd redis-5.0.0makemake install PREFIX=/usr/local/redis3, and create 6 Redis configuration files

Six configuration files cannot be in the same directory, which we define here as follows:

/ root/software/redis/redis-cluster-conf/7001/redis.conf

/ root/software/redis/redis-cluster-conf/7002/redis.conf

/ root/software/redis/redis-cluster-conf/7003/redis.conf

/ root/software/redis/redis-cluster-conf/7004/redis.conf

/ root/software/redis/redis-cluster-conf/7005/redis.conf

/ root/software/redis/redis-cluster-conf/7006/redis.conf

Some operation commands are for reference only:

Cp redis.conf / usr/local/redis/bincd / usr/local/redis/cp-r bin.. / redis-cluster/redis01cd / usr/local/redis-cluster/redis01rm dump.rdb # Delete snapshot vim redis.conf

The contents of the configuration file are:

Port 7001 # Port cluster-enabled yes # enable cluster mode cluster-config-file nodes.confcluster-node-timeout 5000 # timeout appendonly yesdaemonize yes # background running protected-mode no # non-protected mode pidfile / var/run/redis_7001.pidbind 172.20.10.7 # 127.0.0.1 changed to native ip address, you can use ifconfig to view ip

Among them, port and pidfile need to be increased with different folders.

Create the remaining 5 instances:

[root@master redis-cluster] # cp-r redis01/ redis02 [root@master redis-cluster] # cp-r redis01/ redis03 [root@master redis-cluster] # cp-r redis01/ redis04 [root@master redis-cluster] # cp-r redis01/ redis05 [root@master redis-cluster] # cp-r redis01/ redis06

Modify port and pidfile under redis.conf of redis02 ~ redis06 respectively

4. Start the node

Enter the redis01, redis02, and... redis06 directories respectively and execute:. / redis-server. / redis.conf

Create a batch file with six Redis started simultaneously

Vim startall.sh

Add the following:

Cd redis01./redis-server redis.confcd.. cd redis02./redis-server redis.confcd.. cd redis03./redis-server redis.confcd.. cd redis04./redis-server redis.confcd.. cd redis05./redis-server redis.confcd.. Cd redis06./redis-server redis.confcd..

Then execute chmod Ubunx start-all.sh to make start-all.sh an executable file

Start:. / startall.sh in the current directory

View: ps aux | grep redis

5. Start the cluster

Because we use the 5.0.0 version of Redis to build the cluster, we only need to copy the redis-cli file in the compiled redis directory to the redis-cluster directory. (Redis version 5. 0 is started directly in C language.)

/ usr/local/redis-cluster/redis-cli-- cluster create 172.20.10.7 cluster-replicas 7001 172.20.10.7 cluster-replicas 7002 172.20.10.7 cluster-replicas 7003 172.20.10.7 7004 172.20.10.7

After startup, you can see the success message, as follows:

> > Performing hash slots allocation on 6 nodes...Master [0]-> Slots 0-5460Master [1]-> Slots 5461-10922Master [2]-> Slots 10923-16383Adding replica 172.20.10.7 to 172.20.10.7:7001Adding replica 172.20.10.7 Trying to optimize slaves allocation for anti-affinity [WARNING] Some slaves are in the same Host as their masterM: a4128b5e581c3722acd9b093c5f29f5056f680b0 172.20.10.7 slots 7001 slots: [0-5460] (5461 slots) masterM: d6fed6f21269b8469a3076ac5fb168bd20f70c26 172.20.10.7 slots 7002 slots: [5461-10922] (5462 slots) masterM: 51a0f62dacead745ce5351cdbe0bdbae553ce413 172.20.10.7 slots 7003 slots: [10923-16383] (5461 slots) masterS: 45cc35740ac67f7988bb75325871ba12d08a76e4 172.20.10.7 slots 7004 replicates a4128b5e581c3722acd9b093c5f29f5056f680b0S: 668054fe16cdf8741152cae863f5c636ed18b803 172.20.10.7 Vol 7005 replicates d6fed6f21269b8469a3076ac5fb168bd20f70c26S: ae39b7db285703f8c08412d6b04998c60a634295 172.20.10.7 7006 replicates 51a0f62dacead745ce5351cdbe0bdbae553ce413Can I set the above configuration? (type 'yes' to accept): yes

Enter yes to enter enter

> > Nodes configuration updated > > Assign a different config epoch to each node > > Sending CLUSTER MEET messages to join the clusterWaiting for the cluster to join. > > Performing Cluster Check (using node 172.20.10.7 slots 7001) M: a4128b5e581c3722acd9b093c5f29f5056f680b0 172.20.10.7 slots 7001 slots: [0-5460] (5461 slots) master 1 additional replica (s) M: d6fed6f21269b8469a3076ac5fb168bd20f70c26 172.20.10.7 slots: [5461-10922] (5462 slots) master 1 additional replica (s) S: 45cc35740ac67f7988bb75325871ba12d08a76e4 172.20.10.7 : 7004 slots: (0 slots) slave replicates a4128b5e581c3722acd9b093c5f29f5056f680b0M: 51a0f62dacead745ce5351cdbe0bdbae553ce413 172.20.10.7 51a0f62dacead745ce5351cdbe0bdbae553ce413 7003 slots: [10923-16383] (5461 slots) master 1 additional replica (s) S: 668054fe16cdf8741152cae863f5c636ed18b803 172.20.10.7 slave replicates d6fed6f21269b8469a3076ac5fb168bd20f70c26S 7005 slots: (0 slots) slave replicates d6fed6f21269b8469a3076ac5fb168bd20f70c26S: ae39b7db285703f8c08412d6b04998c60a634295 172.20.10.7 slave replicates d6fed6f21269b8469a3076ac5fb168bd20f70c26S 7006 slots: (0 slots) slave replicates 51a0f62dacead745ce5351cdbe0bdbae553ce413 [OK] All nodes agree about slots configuration. > Check for open slots... > > Check slots coverage... [OK] All 16384slots covered.

At this point, the Reids5 cluster has been built.

6. Cluster operation 6.1. Shut down the cluster.

Method 1:

Redis5 provides the tools to shut down the cluster in the following directory:

/ root/redis-5.0.0/utils/create-cluster

Open this file to modify the port for our own, as follows:

The port PROT is set to 7000 norm and 6, and the tool automatically accumulates 1 to generate 7001-7006 six nodes for operation.

Go ahead and modify the path and add the ip address. If you don't add it, it will default to 127.0.0.1.

After modification, execute the following command to shut down the cluster:

/ root/redis-5.0.0/utils/create-cluster/create-cluster stop

Method 2:

Write script files in the create-cluster directory: vim shutdown.sh

The contents are as follows:

/ usr/local/redis-cluster/redis-cli-c-h 172.20.10.7-p 7001 shutdown/usr/local/redis-cluster/redis-cli-c-h 172.20.10.7-p 7002 shutdown/usr/local/redis-cluster/redis-cli-c-h 172.20.10.7-p 7003 shutdown/usr/local/redis-cluster/redis-cli-c-h 172.20.10.7-p 7004 shutdown/usr/local/redis-cluster/redis-cli -c-h 172.20.10.7-p 7005 shutdown/usr/local/redis-cluster/redis-cli-c-h 172.20.10.7-p 7006 shutdown

Then execute chmod Ubunx shutdown.sh to make shutdown.sh an executable file

Start:. / shutdown.sh in the current directory

View: ps aux | grep redis

Official: / usr/local/redis-cluster/redis-cli-a xxx-c-h 192.168.5.100-p 8001

Hint:-an access server password,-c indicates cluster mode,-h specifies ip address,-p specifies port number

6.2. Restart the cluster

/ root/redis-5.0.0/utils/create-cluster/create-cluster start

6.3. Start the cluster using script files

Vim startall.sh adds the following: (remember to change your ip address)

/ usr/local/redis-cluster/redis-cli-- cluster create 172.20.10.7 cluster-replicas 7001 172.20.10.7 cluster-replicas 7002 172.20.10.7 cluster-replicas

Start:. / startall.sh

7. Test cluster

Execute under the redis-cluster directory

Redis01/redis-cli-h 192.168.25.153-p 7002-c

Where-c indicates that the redis,-h is connected in a cluster mode to specify the ip address, and-p specifies the port number

Cluster nodes queries cluster node information

Cluster info queries cluster status information

Summary

The above is the detailed explanation of building and using redis5 cluster under Linux (Centos7) introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to the website!

If you think this article is helpful to you, you are welcome to reprint it, please indicate the source, thank you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report