我有一个主(6379),一个从(6380)和3个哨兵(26379,26380,26381)运行在码头集装箱主和奴隶是连接的,甚至哨兵提供正确的信息,主从。
当我对主和从进行查询时,它运行得很好,我可以(通过公开的端口)看到两者中的相同数据(主和从之间的同步很好)。
当我暂停主程序时,哨兵会执行任务,并使主从成为新的主程序,但这一次,当我试图通过代码访问redis时,它无法连接,因此抛出了Redis命令超时嵌套异常io.lettuce.core.RedisCommandTimeoutException。
停靠-合成文件
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文件是
spring.redis.sentinel.master=mymaster
spring.redis.sentinel.nodes=sentinel:26379,sentinel1:26380,sentinel2:26381请帮我处理这个。
发布于 2020-05-23 20:00:13
links在码头折旧。将所有依赖的容器保存在depends_on:中。例如:
替换
links:
- master
- slave在这方面:
depends_on:
- master
- slave它做的正是你想要的。
https://stackoverflow.com/questions/61966395
复制相似问题