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

How to deploy redis cluster with docker

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Preface

Because I am a docker control, do not like to install a variety of environments, and the installation of redis-trib is also a bit cumbersome, just use docker to do redis cluster.

Pseudo-clusters are used in this article, and the real clusters can be put on different machines. The port is 7001-7006.

Working directory: / data/redis

Create a folder

First create a bunch of folders for the corresponding ports, here is the script

Create.sh

For i in `seq 7001 7006`do mkdir-p ${I} / datadone

Add execution permissions and execute

Chmod 777 create.sh./create.sh

Deploy redis

I don't like docker run, so I use docker-compose. Official document https://docs.docker.com/compose/overview/

Create docker-compose.yml

The reason for using publicisworldwide/redis-cluster image is that people have already written the configuration file. It is lazy if the configuration file is not mounted. Don't be like me.

Docker-compose.yml

Version: '3.4'x-image: & default-image publicisworldwide/redis-clusterx-restart: & default-restart alwaysx-netmode: & default-netmode hostservices: redis1: image: * default-image network_mode: * default-netmode restart: * default-restart volumes:-/ data/redis/7001/data:/data environment:-REDIS_PORT=7001 redis2: image: * default-image network_mode: * default-netmode restart: * default-restart volumes:-/ Data/redis/7002/data:/data environment:-REDIS_PORT=7002 redis3: image: * default-image network_mode: * default-netmode restart: * default-restart volumes:-/ data/redis/7003/data:/data environment:-REDIS_PORT=7003 redis4: image: * default-image network_mode: * default-netmode restart: * default-restart volumes:-/ data/redis/7004/data:/data environment:-REDIS_PORT=7004 redis5: image: * default -image network_mode: * default-netmode restart: * default-restart volumes:-/ data/redis/7005/data:/data environment:-REDIS_PORT=7005 redis6: image: * default-image network_mode: * default-netmode restart: * default-restart volumes:-/ data/redis/7006/data:/data environment:-REDIS_PORT=7006

Start all redis

Docker-compose up-d

If there is an error, it is a problem with the version.

View docker version

Docker-v

You can see the docker-compose.yml version supported by the docker version in the documentation. I copied it in order to make it easier for you to view it. In general, however, docker upgrades are fast and functional iterations are fast, so it's best to use the latest version.

Compose file formatDocker Engine release3.417.09.0+3.317.06.0+3.217.04.0+3.11.13.1+3.01.13.0+2.317.06.0+2.21.13.0+2.11.12.0+2.01.10.0+1.01.9.1.+

Deploy cluster

Run the following command (inem0o/redis-trib will automatically pull without pull)

Note: add-it, otherwise the follow-up confirmation cannot continue

Docker run-- rm-it inem0o/redis-trib create-- replicas 1 192.168.30.70 Vol 7001 192.168.30.70 it inem0o/redis-trib create 7002 192.168.30.70 Vol 7003 192.168.30.70 Vol 7004 192.168.30.70 Vol 7005 192.168.30.70 Vol 7006

Will show up.

> Creating cluster > Performing hash slots allocation on 6 nodes...Using 3 masters:192.168.30.70:7001192.168.30.70:7002192.168.30.70:7003Adding replica 192.168.30.70 masters:192.168.30.70:7001192.168.30.70:7002192.168.30.70:7003Adding replica 7004 to 192.168.30.70:7001Adding replica 192.168.30.70 nodes...Using 7005 to 192.168.30.70:7002Adding replica 192.168.30.70 Creating cluster 7006 to 192.168.30.70 nodes...Using 7003 M: 5a7bd7698b1fe55beb44faac051d66c8a03fd1b1 192.168.30.70 nodes...Using 7001 slots:0-5460 (5461 Slots) masterM: bb8fda08e1dcd39e937443f81b5458e80f52d804 192.168.30.70 slots:5461 7002 slots:5461-10922 (5462 slots) masterM: d907530ee9f6356e0e61a6c7f4d0cc1b22da1189 192.168.30.70 bb8fda08e1dcd39e937443f81b5458e80f52d804 7003 slots:10923-16383 (5461 slots) masterS: 52eee69afa751d71c84d5436d14b0e16a37536fa 192.168.30.70 52eee69afa751d71c84d5436d14b0e16a37536fa 7004 replicates 5a7bd7698b1fe55beb44faac051d66c8a03fd1b1S: 701ed2fbb3df9fc63b083818620f5c020d05e323 192.168.30.70 a3548a9dffa225f05786ea2289db65f5f1c623be 7005 replicates bb8fda08e1dcd39e937443f81b5458e80f52d804S: a3548a9dffa225f05786ea2289db65f5f1c623be 192.168.30.70 a3548a9dffa225f05786ea2289db65f5f1c623be 7006 replicates d907530ee9f6356e0e61a6c7f4d0cc1b22da1189Can I set the above configuration? (type 'yes' to accept):

Enter yes

Waiting for the cluster to join. > Performing Cluster Check (5a7bd7698b1fe55beb44faac051d66c8a03fd1b1 192.168.30.70 slots:0 7001) M: 5a7bd7698b1fe55beb44faac051d66c8a03fd1b1 192.168.30.70 slots:0-5460 (5461 slots) master 1 additional replica (s) M: d907530ee9f6356e0e61a6c7f4d0cc1b22da1189 192.168.30.70 master 7003 "17003 slots:10923-16383 (5461 slots) master 1 additional replica (s) S: a3548a9dffa225f05786ea2289db65f5f1c623be 192.168.30.70 master 7006" 17006 slots: (0 slots) slave replicates d907530ee9f6356e0e61a6c7f4d0cc1b22da1189S: 701ed2fbb3df9fc63b083818620f5c020d05e323 192.168.30.70: 7005-17005 slots: (0 slots) slave replicates bb8fda08e1dcd39e937443f81b5458e80f52d804S: 52eee69afa751d71c84d5436d14b0e16a37536fa 192.168.30.70 slave replicates bb8fda08e1dcd39e937443f81b5458e80f52d804S 7004-17004 slots: (0 slots) slave replicates 5a7bd7698b1fe55beb44faac051d66c8a03fd1b1M: bb8fda08e1dcd39e937443f81b5458e80f52d804 192.168.30.70 additional replica 7002 slots:5461-10922 (5462 slots) master 1 additional replica (s) [OK] All nodes agree about slots configuration. > Check for open slots... > > Check slots coverage... [OK] All 16384slots covered.

Done.

Problems encountered

When creating a cluster, you will encounter Waiting for the cluster to join. Has never been successful.

A: the network mode is changed to host,docker run plus-- net host,docker-compose plus network_mode: host.

I was originally a port mapping 7001VR 7000mm 17001VR 17000, but I can't do it. I don't know why.

The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.

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