如何在群集模式下运行docker redis?

时间:2018-03-30 23:08:47

标签: java docker redis redis-cluster

我用:

启动了我的redis docker容器
docker run --privileged=true -p 6379:6379 --name TestRedis -d redis

当我尝试在群集模式下使用Spring Redis时,我收到错误:

Caused by: redis.clients.jedis.exceptions.JedisDataException: ERR This instance has cluster support disabled
at redis.clients.jedis.Protocol.processError(Protocol.java:127)
at redis.clients.jedis.Protocol.process(Protocol.java:161)
at redis.clients.jedis.Protocol.read(Protocol.java:215)
at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:340)
at redis.clients.jedis.Connection.getRawObjectMultiBulkReply(Connection.java:285)
at redis.clients.jedis.Connection.getObjectMultiBulkReply(Connection.java:291)
at redis.clients.jedis.Jedis.clusterSlots(Jedis.java:3376)
at redis.clients.jedis.JedisClusterInfoCache.discoverClusterNodesAndSlots(JedisClusterInfoCache.java:54)
at redis.clients.jedis.JedisClusterConnectionHandler.initializeSlotsCache(JedisClusterConnectionHandler.java:39)
at redis.clients.jedis.JedisClusterConnectionHandler.<init>(JedisClusterConnectionHandler.java:17)
at redis.clients.jedis.JedisSlotBasedConnectionHandler.<init>(JedisSlotBasedConnectionHandler.java:20)
at redis.clients.jedis.JedisSlotBasedConnectionHandler.<init>(JedisSlotBasedConnectionHandler.java:15)
at redis.clients.jedis.BinaryJedisCluster.<init>(BinaryJedisCluster.java:41)
at redis.clients.jedis.JedisCluster.<init>(JedisCluster.java:83)
at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.createCluster(JedisConnectionFactory.java:306)
at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.createCluster(JedisConnectionFactory.java:280)
at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.afterPropertiesSet(JedisConnectionFactory.java:241)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
... 110 common frames omitted

我需要做什么才能让它以群集形式运行?

3 个答案:

答案 0 :(得分:3)

当您刚刚运行redis Docker镜像时,它会根据其Dockerfile和内置配置启动,该配置没有打开群集。 Chris Tanner指向您的存储库使用相同的基本映像,但添加了配置以激活群集。但是,您需要克隆该存储库并构建映像,然后才能运行它。尽管docker run由于某种原因遗漏了映像名称,但是自述文件库在自述文件中有关于如何构建和运行它的良好说明。克隆回购,cd进去,然后执行此操作:

docker build -t testredis/redis-cluster .
docker run -i -t -p 7000:7000 -p 7001:7001 -p 7002:7002 -p 7003:7003 -p 7004:7004 -p 7005:7005 -p 7006:7006 -p 7007:7007 testredis/redis-cluster

这将使群集运行,您可以在7000端口将客户端指向它。

答案 1 :(得分:2)

我认为您可以在dockerfile中添加启动脚本(shell脚本)并在CMD命令上调用它,该命令将使用一些redis.conf文件启动redis。 在这个redis.conf中,你可以提到自定义配置如下

  

端口7000

     

群集启用是

     

cluster-config-file nodes.conf

     

cluster-node-timeout 5000

     

附带是

这将启动带有上述配置的redis实例

答案 2 :(得分:0)

将此包含在 docker-compose 文件中以运行 redis 集群并连接到服务 docker 组件中的 redis-cluster:7000

  #########################################
  ## redis
  #########################################
  redis-cluster:
    image: grokzen/redis-cluster:3.0.6
    ports:
      - "7000:7000"
      - "7001:7001"
      - "7002:7002"
      - "7003:7003"
      - "7004:7004"
      - "7005:7005"
      - "7006:7006"
      - "7007:7007"