当前位置:   article > 正文

docker下redis集群_dockerfile alpine:3.13包含redis吗

dockerfile alpine:3.13包含redis吗

准备

redis配置文件中不支持系统变量,所以我们自己基于alpine自己做个镜像

  • redis.conf
protected-mode no
tcp-backlog 511
timeout 0
tcp-keepalive 300
loglevel notice
save 3600 1
stop-writes-on-bgsave-error no
rdbcompression yes
rdbchecksum no
dbfilename _dump.rdb
appendonly no
bind 0.0.0.0
cluster-enabled yes
cluster-node-timeout 15000
cluster-require-full-coverage no
activerehashing yes
port REDIS_PORT
cluster-announce-port REDIS_PORT
cluster-announce-bus-port 1REDIS_PORT
maxmemory 2gb
maxmemory-policy allkeys-lru
maxclients 10000
dir /home/data
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • start.sh
#!/bin/sh
mkdir -p /home/data
sed -i "s/REDIS_PORT/${REDIS_PORT}/g" /etc/redis/redis.conf
sed -i "s/MS_PS/${MS_PS}/g" /etc/redis/redis.conf
sed -i "s/PASSWORD/${PASSWORD}/g" /etc/redis/redis.conf
/usr/bin/redis-server /etc/redis/redis.conf
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • dockerfile
FROM alpine:3.13.1
MAINTAINER xusiwang@wondertek.com.cn
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories && apk update && apk add redis
COPY redis.conf /etc/redis/redis.conf
COPY start.sh /home
RUN chmod +x /home/start.sh
ENV REDIS_PORT=6379
EXPOSE 6379
#CMD ["redis-server","/etc/redis/redis.conf"]
ENTRYPOINT /home/start.sh
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 生成redis镜像

docker build -t redis:6.0 .

docker-compose文件

  • redis_clu.yml
version: '3'
networks:
  bestv:
    driver: bridge
    ipam:
      config:
      - subnet: 172.23.0.0/16  

services:
  redis1:
    image: redis:6.0
    restart: unless-stopped
    hostname: redis1
    container_name: redis1
    ports:
      - 7001:7001
    environment:
      REDIS_PORT: 7001
    privileged: true
    volumes:
      - ./redis/7001/data:/home/data
    networks:
      bestv:
        ipv4_address: 172.23.0.2

  redis2:
    image: redis:6.0
    restart: unless-stopped
    hostname: redis2
    container_name: redis2
    ports:
      - 7002:7002
    environment:
      REDIS_PORT: 7002
    privileged: true
    volumes:
      - ./redis/7002/data:/home/data
    depends_on:
      - redis1
    networks:
      bestv:
        ipv4_address: 172.23.0.3

  redis3:
    image: redis:6.0
    restart: unless-stopped
    hostname: redis3
    container_name: redis3
    ports:
      - 7003:7003
    environment:
      REDIS_PORT: 7003
    privileged: true
    volumes:
      - ./redis/7003/data:/home/data
    depends_on:
      - redis1
      - redis2
    networks:
      bestv:
        ipv4_address: 172.23.0.4

  redis4:
    image: redis:6.0
    restart: unless-stopped
    hostname: redis4
    container_name: redis4
    ports:
      - 7004:7004
    environment:
      REDIS_PORT: 7004
    privileged: true
    volumes:
      - ./redis/7004/data:/home/data
    depends_on:
      - redis1
      - redis2
      - redis3
    networks:
      bestv:
        ipv4_address: 172.23.0.5
  redis5:
    image: redis:6.0
    restart: unless-stopped
    hostname: redis5
    container_name: redis5
    ports:
      - 7005:7005
    environment:
      REDIS_PORT: 7005
    privileged: true
    volumes:
      - ./redis/7005/data:/home/data
    depends_on:
      - redis1
      - redis2
      - redis3
      - redis4
    networks:
      bestv:
        ipv4_address: 172.23.0.6

  redis6:
    image: redis:6.0
    restart: unless-stopped
    hostname: redis6
    container_name: redis6
    ports:
      - 7006:7006
    environment:
      REDIS_PORT: 7006
    privileged: true
    volumes:
      - ./redis/7006/data:/home/data
    depends_on:
      - redis1
      - redis2
      - redis3
      - redis4
      - redis5
    networks:
      bestv:
        ipv4_address: 172.23.0.7
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 启动redis

docker-compose -f redis-clu.yml up -d

配置redis集群

redis对主机名的支持不太友好,所以我们换成ip方式

  • 随便进入一台redis容器

docker exec -it redis-1 sh

  • 生成集群

redis-cli --cluster create 172.23.0.2:7001 172.23.0.3:7002 172.23.0.4:7003 172.23.0.5:7004 172.23.0.6:7005 172.23.0.7:7006 --cluster-replicas 1

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/1007034
推荐阅读
相关标签
  

闽ICP备14008679号