无法从本地计算机上的java应用程序连接到sentinel

68bkxrlz  于 2021-06-10  发布在  Redis
关注(0)|答案(0)|浏览(326)

尝试为本地开发准备docker compose文件,这将尽可能类似于prod设置。
这是我的 docker-compose.yml :

version: '3'

services:
  redis-master:
    image: redis:6.0.5
  redis-slave:
    image: redis:6.0.5
    depends_on:
      - redis-master
    command: redis-server --slaveof redis-master 6379
  redis-sentinel:
    build: redis-sentinel
    ports:
      - "26379:26379"
    environment:
      - SENTINEL_DOWN_AFTER=5000
      - SENTINEL_FAILOVER=5000
    depends_on:
      - redis-master
      - redis-slave

用于构建redis sentinel的文件: Dockerfile :

FROM redis:6.0.5

ADD sentinel.conf /etc/redis/sentinel.conf
RUN chown redis:redis /etc/redis/sentinel.conf
ENV SENTINEL_QUORUM 2
ENV SENTINEL_DOWN_AFTER 5000
ENV SENTINEL_FAILOVER 10000
ENV SENTINEL_PORT 26379
ADD entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 26379
``` `entrypoint.sh` ```

# !/bin/sh

sed -i "s/\$SENTINEL_PORT/$SENTINEL_PORT/g" /etc/redis/sentinel.conf
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

exec docker-entrypoint.sh redis-server /etc/redis/sentinel.conf --sentinel
``` `sentinel.conf` :

protected-mode no
port 26379
dir /tmp
sentinel monitor mymaster redis-master 6379 $SENTINEL_QUORUM
sentinel down-after-milliseconds mymaster $SENTINEL_DOWN_AFTER
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster $SENTINEL_FAILOVER

打电话后 `docker-compose up` 我正在尝试启动无法连接到的应用程序 `localhost:26379` 堆栈跟踪:

Caused by: io.lettuce.core.RedisConnectionException: Unable to connect to RedisURI [sentinels=[RedisURI [host='localhost', port=26379]], sentinelMasterId=mymaster]
at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:78)
at io.lettuce.core.masterslave.MasterSlave.getConnection(MasterSlave.java:266)
at io.lettuce.core.masterslave.MasterSlave.connect(MasterSlave.java:120)
at org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.masterReplicaConnection(StandaloneConnectionProvider.java:160)
at org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.lambda$getConnection$0(StandaloneConnectionProvider.java:114)
at java.base/java.util.Optional.map(Optional.java:265)
at org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.getConnection(StandaloneConnectionProvider.java:114)
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getNativeConnection(LettuceConnectionFactory.java:1197)
... 64 common frames omitted
Caused by: io.lettuce.core.RedisException: Cannot determine topology from RedisURI [sentinels=[RedisURI [host='localhost', port=26379]], sentinelMasterId=mymaster]
at io.lettuce.core.masterslave.SentinelConnector.lambda$connectAsync$0(SentinelConnector.java:69)
at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:118)
at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1712)
...

如果我将我的应用程序添加到docker compose文件,上面描述的一切都会像一个魔咒一样工作,所有这些都会发生在Windows10上,如果有关系的话
有人能给我一个提示我的设置有什么问题吗?我准备提供任何额外的信息

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题