码迷,mamicode.com
首页 > 其他好文 > 详细

docker下安装redis集群

时间:2019-09-28 18:11:03      阅读:93      评论:0      收藏:0      [点我收藏+]

标签:command   技术   nod   tin   ati   cal   password   cat   style   

技术图片

docker-compose.yml

master:
  image: redis:4
  container_name: redis-cluster_master
  command: redis-server --port 6379
  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
  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
  ports:
    - "6381"
  net: "host"
sentinel_1:
  build: sentinel
  container_name: redis-cluster_sentinel_1
  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
  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
  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集群

标签:command   技术   nod   tin   ati   cal   password   cat   style   

原文地址:https://www.cnblogs.com/DurantSimpson/p/11603758.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!