docker-compose_redis_cluster
redis cluster docker-compose
centos
yum -y install docker-ce docker-compose
debian/ubuntu
apt -y install docker-ce docker-compose
部署流程
mkdir /opt/redis
cd /opt/redis
mkdir -p ./data/node-{0..5}
chown -R 1001:1001 ./data
chmod -R 770 ./data
#编写docker-compose.yaml
vim docker-compose.yaml
version: '3'
services:
redis-node-0:
image: bitnami/redis-cluster:6.0
volumes:
- ./data/node-0:/bitnami/redis/data
ports:
- 16379:6379
environment:
- REDIS_CLUSTER_ENABLED=yes
- REDIS_CLUSTER_REPLICAS=1
- REDIS_PASSWORD=123456
- REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5
redis-node-1:
image: bitnami/redis-cluster:6.0
volumes:
- ./data/node-1:/bitnami/redis/data
ports:
- 16380:6379
environment:
- REDIS_CLUSTER_ENABLED=yes
- REDIS_CLUSTER_REPLICAS=1
- REDIS_PASSWORD=123456
- REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5
redis-node-2:
image: bitnami/redis-cluster:6.0
volumes:
- ./data/node-2:/bitnami/redis/data
ports:
- 16381:6379
environment:
- REDIS_CLUSTER_ENABLED=yes
- REDIS_CLUSTER_REPLICAS=1
- REDIS_PASSWORD=123456
- REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5
redis-node-3:
image: bitnami/redis-cluster:6.0
volumes:
- ./data/node-3:/bitnami/redis/data
ports:
- 16382:6379
environment:
- REDIS_CLUSTER_ENABLED=yes
- REDIS_CLUSTER_REPLICAS=1
- REDIS_PASSWORD=123456
- REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5
redis-node-4:
image: bitnami/redis-cluster:6.0
volumes:
- ./data/node-4:/bitnami/redis/data
ports:
- 16383:6379
environment:
- REDIS_CLUSTER_ENABLED=yes
- REDIS_CLUSTER_REPLICAS=1
- REDIS_PASSWORD=123456
- REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5
redis-node-5:
image: bitnami/redis-cluster:6.0
volumes:
- ./data/node-5:/bitnami/redis/data
ports:
- 16384:6379
environment:
- REDIS_CLUSTER_ENABLED=yes
- REDIS_CLUSTER_REPLICAS=1
- REDIS_PASSWORD=123456
- REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5
启动/停止
#启动
docker-compose up -d
cat data/node-0/nodes.sh
declare -A host_2_ip_array=([redis-node-0]=“172.19.0.3” [redis-node-1]=“172.19.0.6” [redis-node-2]=“172.19.0.4” [redis-node-3]=“172.19.0.5” [redis-node-4]=“172.19.0.7” [redis-node-5]=“172.19.0.2” )
docker exec -it {node-0} bash
redis-cli -a 123456 --cluster create --cluster-replicas 1 172.19.0.2:6379 172.19.0.3:6379 172.19.0.4:6379 172.19.0.5:6379 172.19.0.6:6379 172.19.0.7:6379
yes
# 确认集群状态
cat data/node-0/nodes.conf
0b83dfc5deb21c0bd871a7be0ebc519e3a8c8080 172.19.0.5:6379@16379 slave bd720d3026f80362ede875ee25fd2c5e77a9d6f0 0 1703041782000 3 connected
09299274738a850637dc5c39e9645494f98c8a9c 172.19.0.2:6379@16379 master - 0 1703041781000 1 connected 0-5460
bd720d3026f80362ede875ee25fd2c5e77a9d6f0 172.19.0.4:6379@16379 master - 0 1703041782242 3 connected 10923-16383
679e4b2e4a0ffd928b74566b49c163adf5264416 172.19.0.6:6379@16379 slave 09299274738a850637dc5c39e9645494f98c8a9c 0 1703041781239 1 connected
d0ad459690ec05a45e0ab808a5b3d0613d95072f 172.19.0.3:6379@16379 myself,master - 0 1703041782000 2 connected 5461-10922
519353213ad27a32760fea087a54b31d1e9630b7 172.19.0.7:6379@16379 slave d0ad459690ec05a45e0ab808a5b3d0613d95072f 0 1703041783244 2 connected
vars currentEpoch 6 lastVoteEpoch 0
#停止
docker-compose down
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!