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 build redis Cluster in docker

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

Share

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

This article shows you how to build a redis cluster in docker. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

1. Create a virtual network card

Docker network create redis-net

3. Check the network card information

Docker network ls

4. View the redis-net virtual network card gateway ip

Docker network inspect redis-net | grep "Gateway" | grep-- color=auto-P'(\ d {1Magne 3}.) {3}\ d {1Magne 3}'- o

5. Create directories and files to be mounted

# create cluster mount directory mkdir-p / docker/redis# create cluster configuration file template touch / docker/redis/redis-cluster.conf# edit configuration file template content port ${PORT} cluster-enabled yescluster-config-file nodes.confcluster-node-timeout 5000cluster-announce-ip 192.168.100.101cluster-announce-port ${PORT} cluster-announce-bus-port 1 ${PORT} appendonly yes

6. Create a sh script file in the / docker/redis directory

Touch create_conf.sh

Edit the script as follows:

#! / bin/bashfor port in `seq 6001 6006`; domkdir-p. / ${port} / conf & & PORT=$ {port} envsubst

< ./redis-cluster.conf >

. / ${port} / conf/redis.conf & & mkdir-p. / ${port} / data;done

Authorized executable chmod-R 777 create_conf.sh

7. Execute the script to create the mount directory and configuration file

. / create_conf.sh

8. Edit the startup container script (start 6 containers)

Touch create_redis_docker.sh

Edit the content as

#! / bin/bashfor port in `seq 6001 6006` Dodocker run-d-ti-p ${port}: ${port}-p 1 ${port}: 1 ${port}-v / docker/redis/$ {port} / conf/redis.conf:/usr/local/etc/redis/redis.conf-v / docker/redis/$ {port} / data:/data-restart always-- name redis-$ {port}-net redis-net-- sysctl net.core.somaxconn=1024 redis redis-server / usr/local/etc/redis/redis.conf;done

Authorize chmod-R 777 create_redis_docker.sh

9. Execute the script to create the container

. / create_redis_docker.sh

10. View the ip of the created container

Docker inspect redis-6001 redis-6002 redis-6003 redis-6004 redis-6005 redis-6006 | grep IPAddress

11. Enter the 6001 port container

Docker exec-it redis-6001 bash

12. Execute cluster commands in the container

/ usr/local/bin/redis-cli-- cluster create 172.18.0.2 cluster-replicas 6001 172.18.0.3 VR 6002 172.18.0.4 VR 6003 172.18.0.5 cluster-replicas 6004 172.18.0.6 VR 6005 172.18.0.7 VR 6006--

Download redis.conf

Cd / docker/redis/wget http://download.redis.io/redis-stable/redis.conf the above is how to build a redis cluster in docker. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

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

Internet Technology

Wechat

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

12
Report