docker下安装redis集群
Posted DurantSimpson
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了docker下安装redis集群相关的知识,希望对你有一定的参考价值。
docker-compose.yml
master:
image: redis:4
container_name: redis-cluster_master
command: redis-server --port 6379
restart: always
ports:
- "6379"
net: "host"
slave_1:
image: redis:4
container_name: redis-cluster_slave_1
command: redis-server --port 6380 --slaveof 192.168.80.19 6379
restart: always
ports:
- "6380"
net: "host"
slave_2:
image: redis:4
container_name: redis-cluster_slave_2
command: redis-server --port 6381 --slaveof 192.168.80.19 6379
restart: always
ports:
- "6381"
net: "host"
sentinel_1:
build: sentinel
container_name: redis-cluster_sentinel_1
restart: always
environment:
- SENTINEL_PORT=26379
- SENTINEL_DOWN_AFTER=5000
- SENTINEL_FAILOVER=5000
ports:
- "26379"
net: "host"
sentinel_2:
build: sentinel
container_name: redis-cluster_sentinel_2
restart: always
environment:
- SENTINEL_PORT=26380
- SENTINEL_DOWN_AFTER=5000
- SENTINEL_FAILOVER=5000
ports:
- "26380"
net: "host"
sentinel_3:
build: sentinel
container_name: redis-cluster_sentinel_3
restart: always
environment:
- SENTINEL_PORT=26381
- SENTINEL_DOWN_AFTER=5000
- SENTINEL_FAILOVER=5000
ports:
- "26381"
net: "host"
Dockerfile
FROM redis:4
ADD sentinel.conf /etc/redis/sentinel.conf
RUN chown redis:redis /etc/redis/sentinel.conf
ENV SENTINEL_QUORUM 2
ENV SENTINEL_DOWN_AFTER 30000
ENV SENTINEL_FAILOVER 180000
COPY sentinel-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/sentinel-entrypoint.sh
ENTRYPOINT ["sentinel-entrypoint.sh"]
sentinel.conf
# Example sentinel.conf can be downloaded from http://download.redis.io/redis-stable/sentinel.conf
port $SENTINEL_PORT
dir /tmp
sentinel monitor mymaster 192.168.80.19 6379 $SENTINEL_QUORUM
sentinel down-after-milliseconds mymaster $SENTINEL_DOWN_AFTER
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster $SENTINEL_FAILOVER
sentinel-entrypoint.sh
#!/bin/sh
sed -i "s/\\$SENTINEL_QUORUM/$SENTINEL_QUORUM/g" /etc/redis/sentinel.conf
sed -i "s/\\$SENTINEL_DOWN_AFTER/$SENTINEL_DOWN_AFTER/g" /etc/redis/sentinel.conf
sed -i "s/\\$SENTINEL_FAILOVER/$SENTINEL_FAILOVER/g" /etc/redis/sentinel.conf
sed -i "s/\\$SENTINEL_PORT/$SENTINEL_PORT/g" /etc/redis/sentinel.conf
exec docker-entrypoint.sh redis-server /etc/redis/sentinel.conf --sentinel
只要在redis-cluster目录下,依次执行以下命令即可
注意:192.168.80.19为本机ip
docker-compose build
docker-compose up -d
附上springboot的配置
application.yml
#Spring配置
spring
redis:
#host: 192.168.80.19
#port: 6379
password:
database: 0
sentinel:
master: mymaster
nodes: 192.168.80.19:26379,192.168.80.19:26380,192.168.80.19:26381
以上是关于docker下安装redis集群的主要内容,如果未能解决你的问题,请参考以下文章
2Docker下安装Redis集群:cluster(集群)模式-docker版,哈希槽分区进行亿级数据存储
docker-compose安装redis-sentinel集群(1主+2副+2哨兵)
ubuntu18 下docker 安装clouderaCDH集群[单机多节点]