【SpringCloud分布式框架搭建】docker-compose安装redis5 集群。并集成到springCloud中

准备工作:
编写 redis.conf文件。直接贴出
 


bind 0.0.0.0

protected-mode no


# 监听端口

port 6305

tcp-backlog 511

timeout 0

tcp-keepalive 300

daemonize no

supervised no

pidfile /var/run/redis_6305.pid

# 日志级别
loglevel notice


logfile ""

databases 16

always-show-logo yes

save 900 1
save 300 10
save 60 10000

stop-writes-on-bgsave-error yes

rdbcompression yes

rdbchecksum yes

# rdb文件的存储文件名
dbfilename dump.rdb

# 注意,这个参数必须是一个目录,不能是一个文件
dir /data/

# masterauth 
masterauth Keda123456

slave-serve-stale-data yes

# 设置从节点为  只读。
slave-read-only yes

repl-diskless-sync no

repl-diskless-sync-delay 5

repl-disable-tcp-nodelay no

slave-priority 100

requirepass Keda123456

lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no

appendonly yes

# The name of the append only file (default: "appendonly.aof")

appendfilename "appendonly.aof"

appendfsync everysec
from the point of view of durability.

no-appendfsync-on-rewrite no

auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb

aof-load-truncated yes

aof-use-rdb-preamble no

lua-time-limit 5000

cluster-enabled yes

cluster-config-file nodes-6305.conf

cluster-node-timeout 15000

slowlog-log-slower-than 10000

slowlog-max-len 128

latency-monitor-threshold 0

notify-keyspace-events ""

list-max-ziplist-size -2

list-compress-depth 0

zset-max-ziplist-entries 128
zset-max-ziplist-value 64

hll-sparse-max-bytes 3000

activerehashing yes

client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60

hz 10

 

特别备注:(这几个配置,6个reids的conf 都要改。根据端口号6300-6305,这是我自己设置的6个端口号)

# 监听端口
port 6305
pidfile /var/run/redis_6305.pid
cluster-config-file nodes-6305.conf

我这里设置了密码访问,所以,需要配置以下
masterauth Keda123456
requirepass Keda123456

然后,直接贴出我写的docker-compose文件

version: '3'
services:
  #1.Redis
  redis_6305:
    image: redis:5.0.5
    privileged: true
    restart: always
    container_name: redis_6305
    environment:
      - TZ=Asia/Shanghai
      - LANG=en_US.UTF-8
    # v3 版本以上, 指定与部署和运行服务相关的配置, deploy 部分是 docker stack 使用的, docker stack 依赖 docker swarm 
    volumes:
      - "/usr/docker/redis-cluster/6305/data/:/data"
      - "/usr/docker/redis-cluster/6305/conf/redis.conf:/usr/local/etc/redis/redis.conf"
      - "/usr/docker/redis-cluster/6305/etc/rc.local:/etc/rc.local"
      - "/etc/localtime:/etc/localtime"
    network_mode: host
    command: [ "redis-server", "/usr/local/etc/redis/redis.conf" ]
  #1.Redis
  redis_6304:
    image: redis:5.0.5  
    privileged: true
    restart: always
    container_name: redis_6304
    environment:
      - TZ=Asia/Shanghai
      - LANG=en_US.UTF-8
    # v3 版本以上, 指定与部署和运行服务相关的配置, deploy 部分是 docker stack 使用的, docker stack 依赖 docker swarm 
    volumes:
      - "/usr/docker/redis-cluster/6304/data/:/data"
      - "/usr/docker/redis-cluster/6304/conf/redis.conf:/usr/local/etc/redis/redis.conf"
      - "/usr/docker/redis-cluster/6304/etc/rc.local:/etc/rc.local"
      - "/etc/localtime:/etc/localtime"
    network_mode: host
    command: [ "redis-server", "/usr/local/etc/redis/redis.conf" ]
  redis_6303:
    image: redis:5.0.5  
    privileged: true
    restart: always
    container_name: redis_6303
    environment:
      - TZ=Asia/Shanghai
      - LANG=en_US.UTF-8
    # v3 版本以上, 指定与部署和运行服务相关的配置, deploy 部分是 docker stack 使用的, docker stack 依赖 docker swarm 
    volumes:
      - "/usr/docker/redis-cluster/6303/data/:/data"
      - "/usr/docker/redis-cluster/6303/conf/redis.conf:/usr/local/etc/redis/redis.conf"
      - "/usr/docker/redis-cluster/6303/etc/rc.local:/etc/rc.local"
      - "/etc/localtime:/etc/localtime"
    network_mode: host
    command: [ "redis-server", "/usr/local/etc/redis/redis.conf" ]
  redis_6302:
    image: redis:5.0.5  
    privileged: true
    restart: always
    container_name: redis_6302
    environment:
      - TZ=Asia/Shanghai
      - LANG=en_US.UTF-8
    # v3 版本以上, 指定与部署和运行服务相关的配置, deploy 部分是 docker stack 使用的, docker stack 依赖 docker swarm 
    volumes:
      - "/usr/docker/redis-cluster/6302/data/:/data"
      - "/usr/docker/redis-cluster/6302/conf/redis.conf:/usr/local/etc/redis/redis.conf"
      - "/usr/docker/redis-cluster/6302/etc/rc.local:/etc/rc.local"
      - "/etc/localtime:/etc/localtime"
    network_mode: host
    command: [ "redis-server", "/usr/local/etc/redis/redis.conf" ]
  redis_6301:
    image: redis:5.0.5
    privileged: true
    restart: always
    container_name: redis_6301
    environment:
      - TZ=Asia/Shanghai
      - LANG=en_US.UTF-8
    # v3 版本以上, 指定与部署和运行服务相关的配置, deploy 部分是 docker stack 使用的, docker stack 依赖 docker swarm 
    volumes:
      - "/usr/docker/redis-cluster/6301/data/:/data"
      - "/usr/docker/redis-cluster/6301/conf/redis.conf:/usr/local/etc/redis/redis.conf"
      - "/usr/docker/redis-cluster/6301/etc/rc.local:/etc/rc.local"
      - "/etc/localtime:/etc/localtime"
    network_mode: host 
    command: [ "redis-server", "/usr/local/etc/redis/redis.conf" ]    
  redis_6300:
    image: redis:5.0.5  
    privileged: true
    restart: always
    container_name: redis_6300
    environment:
      - TZ=Asia/Shanghai
      - LANG=en_US.UTF-8
    # v3 版本以上, 指定与部署和运行服务相关的配置, deploy 部分是 docker stack 使用的, docker stack 依赖 docker swarm 
    volumes:
      - "/usr/docker/redis-cluster/6300/data/:/data"
      - "/usr/docker/redis-cluster/6300/conf/redis.conf:/usr/local/etc/redis/redis.conf"
      - "/usr/docker/redis-cluster/6300/etc/rc.local:/etc/rc.local"
      - "/etc/localtime:/etc/localtime"
    network_mode: host 
    command: [ "redis-server", "/usr/local/etc/redis/redis.conf" ]

进入 docker-compose.yml 文件所有的目录,输入:

docker-compose up

执行完后。 需要配置redis 插槽
 

redis-cli -a Keda123456 \
--cluster create \
--cluster-replicas 1 \
101.132.34.170:6300 101.132.34.170:6301 101.132.34.170:6302 \
101.132.34.170:6303 101.132.34.170:6304 101.132.34.170:6305

注:
Keda123456  是配置的访问密码
101.132.34.170 是宿主机的 Ip地址。  (一定要是别人能访问的地址)


springCloud的配置段
 

spring:  
 redis:
    cluster:
      nodes:
        - 101.132.34.170:6300
        - 101.132.34.170:6301
        - 101.132.34.170:6302
        - 101.132.34.170:6303
        - 101.132.34.170:6304
        - 101.132.34.170:6305
      max-redirects: 6    # 获取失败 最大重定向次数

    # Redis服务器连接密码(默认为空)
    password: Keda123456
#    # 连接超时时间(毫秒)
    timeout: 50000ms
    lettuce:
      pool:
        # 连接池最大连接数(使用负值表示没有限制)
        max-active: 8
        # 连接池中的最大空闲连接
        max-idle: 8
        # 连接池中的最小空闲连接
        min-idle: 0
        # 连接池最大阻塞等待时间(使用负值表示没有限制)
        max-wait: -1ms
      # 关闭超时时间
     # shutdown-timeout: 5000ms

 

你可能感兴趣的:(docker,redis,java)