如何设置 docker compose with redis, sentinel and django+celery

How to setup docker compose with redis, sentinel and django+celery

我在 docker 上设置哨兵时遇到问题。当我尝试 运行.

时,我发现的所有内容看起来都过时且已弃用并且存在问题

我正在使用 docker-compose 代码如下:

redis-master
    image: redis:4.0.11-alpine
    volumes:
      - broker-data:/data
    networks:
      - db
    ports:
      - 6379:6379

  redis-slave:
    image: redis:4.0.11-alpine
    command: 
      - redis-server --slaveof redis-master 6379
    volumes:
      - broker-data:/data
    networks:
      - db
    links: 
      - redis-master

  sentinel:
    build: ./sentinel
    volumes: 
      - broker-data:/data
    networks: 
      - db
    ports:
      - 26379:26379
    links: 
      - redis-slave
      - redis-master

来自 https://github.com/mustafaileri/redis-cluster-with-sentinel/tree/master/sentinel

的哨兵

这部分似乎 运行 正确,但 Celery(在 Django 中加入)找不到它。

CELERY_BROKER_URL="sentinel://sentinel:26379/0"

我尝试更改传输选项,但在使用 docker-compose.

启动 django 时总是出现 No master found for None 错误
CELERY_BROKER_TRANSPORT_OPTIONS={"my_master":"redis-master", "master_name":"redis-master"}

关于我犯的错误的任何想法,或者在 docker 上使用 Django 上的哨兵的好技巧?

Django 2.2.8
芹菜 4.3.0

我终于找到错误了。我为 CELERY_RESULT_BACKEND 使用了哨兵,但没有设置隐藏的 CELERY_RESULT_BACKEND_TRANSPORT_OPTIONS 参数中的选项。

在我的例子中,这里是 django 中使用 celery 和 sentinel 的代码:

CELERY_BROKER_URL = "sentinel://sentinel1:26379/0;sentinel://sentinel2:26380/0"
CELERY_RESULT_BACKEND = "sentinel://sentinel1:26379/0;sentinel://sentinel2:26380/0"
CELERY_BROKER_TRANSPORT_OPTIONS = {"visibility_timeout": 3600, "master_name": "cluster1"}
CELERY_RESULT_BACKEND_TRANSPORT_OPTIONS = {"visibility_timeout": 3600, "master_name": "cluster1"}