首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如果主程序在redis哨兵配置下无法连接从机,则全部运行在Docker容器中。

如果主程序在redis哨兵配置下无法连接从机,则全部运行在Docker容器中。
EN

Stack Overflow用户
提问于 2020-05-23 01:39:48
回答 1查看 723关注 0票数 0

我有一个主(6379),一个从(6380)和3个哨兵(26379,26380,26381)运行在码头集装箱主和奴隶是连接的,甚至哨兵提供正确的信息,主从。

当我对主和从进行查询时,它运行得很好,我可以(通过公开的端口)看到两者中的相同数据(主和从之间的同步很好)。

当我暂停主程序时,哨兵会执行任务,并使主从成为新的主程序,但这一次,当我试图通过代码访问redis时,它无法连接,因此抛出了Redis命令超时嵌套异常io.lettuce.core.RedisCommandTimeoutException。

停靠-合成文件

代码语言:javascript
复制
services:
  db:
    image: mysql:5.7
    restart: always
    environment:
      - MYSQL_DATABASE=inward
      # So you don't have to use root, but you can if you like
      #- MYSQL_USER=test
      # You can use whatever password you like
      #- MYSQL_PASSWORD=test
      # Password for root access
      - MYSQL_ROOT_PASSWORD=unroot
    ports:
      # <Port exposed> : < MySQL Port running inside container>
      - 3309:3306
  master:
    image: redis
    ports:
      - 6379:6379
  slave:
    image: redis
    command: >
      bash -c "echo 'port 6380' > slave.conf &&
      echo 'replicaof master 6379' >> slave.conf &&
      cat slave.conf &&
      redis-server slave.conf"
    links:
      - master
    ports:
      - 6380:6380
  sentinel:
    image: redis
    command: >
      bash -c "echo 'port 26379' > sentinel.conf &&
      echo 'dir /tmp' >> sentinel.conf &&
      echo 'sentinel monitor mymaster master 6379 2' >> sentinel.conf &&
      echo 'sentinel down-after-milliseconds mymaster 5000' >> sentinel.conf &&
      echo 'sentinel parallel-syncs mymaster 1' >> sentinel.conf &&
      echo 'sentinel failover-timeout mymaster 5000' >> sentinel.conf &&
      cat sentinel.conf &&
      redis-server sentinel.conf --sentinel"
    links:
      - master
      - slave
    ports:
      - 26379:26379
  sentinel1:
    image: redis
    command: >
      bash -c "echo 'port 26380' > sentinel.conf &&
      echo 'dir /tmp' >> sentinel.conf &&
      echo 'sentinel monitor mymaster master 6379 2' >> sentinel.conf &&
      echo 'sentinel down-after-milliseconds mymaster 5000' >> sentinel.conf &&
      echo 'sentinel parallel-syncs mymaster 1' >> sentinel.conf &&
      echo 'sentinel failover-timeout mymaster 5000' >> sentinel.conf &&
      cat sentinel.conf &&
      redis-server sentinel.conf --sentinel"
    links:
      - master
      - slave
    ports:
      - 26380:26380
  sentinel2:
    image: redis
    command: >
      bash -c "echo 'port 26381' > sentinel.conf &&
      echo 'dir /tmp' >> sentinel.conf &&
      echo 'sentinel monitor mymaster master 6379 2' >> sentinel.conf &&
      echo 'sentinel down-after-milliseconds mymaster 5000' >> sentinel.conf &&
      echo 'sentinel parallel-syncs mymaster 1' >> sentinel.conf &&
      echo 'sentinel failover-timeout mymaster 5000' >> sentinel.conf &&
      cat sentinel.conf &&
      redis-server sentinel.conf --sentinel"
    links:
      - master
      - slave
    ports:
      - 26381:26381
  app:
    build:
      context: ./
      dockerfile: Dockerfile
    depends_on:
      - db
    links:
      - master
      - slave
      - sentinel
      - sentinel1
      - sentinel2
    working_dir: /app
    command: [sh, -c, 'mkdir -p ~/logs/; cd /src ; mvn clean spring-boot:run -Dspring.profiles.active=local -DLOG_DIR=/root/logs/ -DLOG_FILE=hubstamper.log']
    ports:
      - 8080:8080
    volumes:
      - "${HOME}/.m2:/root/.m2"

而application.properties文件是

代码语言:javascript
复制
spring.redis.sentinel.master=mymaster
spring.redis.sentinel.nodes=sentinel:26379,sentinel1:26380,sentinel2:26381

请帮我处理这个。

EN

回答 1

Stack Overflow用户

发布于 2020-05-23 20:00:13

links在码头折旧。将所有依赖的容器保存在depends_on:中。例如:

替换

代码语言:javascript
复制
links:
      - master
      - slave

在这方面:

代码语言:javascript
复制
depends_on:
      - master
      - slave

它做的正是你想要的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61966395

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档