docker-compose配置redis集群
2022/7/10 2:20:04
本文主要是介绍docker-compose配置redis集群,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
创建文件夹
在 /usr/local/docker/下创建,方便管理
cd /usr/local/docker mkdir reids-cluster # 创建redis-1~redis-6文件夹 mkdir redis-cluster/redis-1 \ redis-cluster/redis-2 \ redis-cluster/redis-3 \ redis-cluster/redis-4 \ redis-cluster/redis-5 \ redis-cluster/redis-6
新建配置文件
cd redis-cluster cat > redis-1/redis.conf << EOF cluster-enabled yes # 开启集群 cluster-config-file nodes.conf # 集群配置文件 cluster-node-timeout 5000 # 集群节点多少时间未响应视为该节点丢失 appendonly yes port 6379 # redis监听端口 EOF cat > redis-2/redis.conf << EOF cluster-enabled yes # 开启集群 cluster-config-file nodes.conf # 集群配置文件 cluster-node-timeout 5000 # 集群节点多少时间未响应视为该节点丢失 appendonly yes port 6380 # redis监听端口 EOF cat > redis-3/redis.conf << EOF cluster-enabled yes # 开启集群 cluster-config-file nodes.conf # 集群配置文件 cluster-node-timeout 5000 # 集群节点多少时间未响应视为该节点丢失 appendonly yes port 6381 # redis监听端口 EOF cat > redis-4/redis.conf << EOF cluster-enabled yes # 开启集群 cluster-config-file nodes.conf # 集群配置文件 cluster-node-timeout 5000 # 集群节点多少时间未响应视为该节点丢失 appendonly yes port 6382 # redis监听端口 EOF cat > redis-5/redis.conf << EOF cluster-enabled yes # 开启集群 cluster-config-file nodes.conf # 集群配置文件 cluster-node-timeout 5000 # 集群节点多少时间未响应视为该节点丢失 appendonly yes port 6383 # redis监听端口 EOF cat > redis-6/redis.conf << EOF cluster-enabled yes # 开启集群 cluster-config-file nodes.conf # 集群配置文件 cluster-node-timeout 5000 # 集群节点多少时间未响应视为该节点丢失 appendonly yes port 6384 # redis监听端口 EOF
docker-compose.yaml文件配置 (复制有问题可以用 cat > docker-compose.yaml << EOF)
version: '3' services: # redis1配置 redis1: image: redis:6.0.16 container_name: redis-1 restart: always network_mode: "host" volumes: - ./redis-1/redis.conf:/usr/local/etc/redis/redis.conf command: ["redis-server", "/usr/local/etc/redis/redis.conf"] # redis2配置 redis2: image: redis:6.0.16 container_name: redis-2 restart: always network_mode: "host" volumes: - ./redis-2/redis.conf:/usr/local/etc/redis/redis.conf command: ["redis-server", "/usr/local/etc/redis/redis.conf"] # redis3配置 redis3: image: redis:6.0.16 container_name: redis-3 restart: always network_mode: "host" volumes: - ./redis-3/redis.conf:/usr/local/etc/redis/redis.conf command: ["redis-server", "/usr/local/etc/redis/redis.conf"] # redis4配置 redis4: image: redis:6.0.16 container_name: redis-4 restart: always network_mode: "host" volumes: - ./redis-4/redis.conf:/usr/local/etc/redis/redis.conf command: ["redis-server", "/usr/local/etc/redis/redis.conf"] # redis5配置 redis5: image: redis:6.0.16 container_name: redis-5 restart: always network_mode: "host" volumes: - ./redis-5/redis.conf:/usr/local/etc/redis/redis.conf command: ["redis-server", "/usr/local/etc/redis/redis.conf"] # redis6配置 redis6: image: redis:6.0.16 container_name: redis-6 restart: always network_mode: "host" volumes: - ./redis-6/redis.conf:/usr/local/etc/redis/redis.conf command: ["redis-server", "/usr/local/etc/redis/redis.conf"]
启动容器
docker-compose up -d
这篇关于docker-compose配置redis集群的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-18Redis安装入门:新手必读指南
- 2024-11-08阿里云Redis项目实战入门教程
- 2024-11-08阿里云Redis资料:新手入门与初级使用指南
- 2024-11-08阿里云Redis教程:新手入门及实用指南
- 2024-11-07阿里云Redis学习入门:新手必读指南
- 2024-11-07阿里云Redis学习入门:从零开始的操作指南
- 2024-11-07阿里云Redis学习:初学者指南
- 2024-11-06阿里云Redis入门教程:轻松搭建与使用指南
- 2024-11-02Redis项目实战:新手入门教程
- 2024-10-22Redis入门教程:轻松掌握数据存储与操作