如何使用Docker Compose设置Redis、Sentinel和Django+Celery?

huangapple go评论58阅读模式
英文:

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

问题

我在使用Docker上的Sentinel设置时遇到了问题。我找到的所有信息都似乎都已经过时,而且在尝试运行时出现了问题。

我正在使用类似以下代码的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 的Sentinel部分。这部分似乎正常运行,但是Celery(在Django中使用)找不到它。

我尝试更改了传输选项,但始终在使用docker-compose启动Django时出现No master found for None错误。

有没有关于我可能犯的错误或者在Django中使用Docker的Sentinel的好建议?

Django版本:2.2.8
Celery版本:4.3.0

英文:

I'm having trouble with the setup of sentinel on docker. Everything I've found looks old and deprecated and having issues when I'm trying to run.

I'm using docker-compose with code like this :

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

And sentinel from https://github.com/mustafaileri/redis-cluster-with-sentinel/tree/master/sentinel

This part seems to run correctly but Celery (onboarded in Django) doesn't found it.

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

and I tried to change the transport options, but always have No master found for None error when starting django with docker-compose.

CELERY_BROKER_TRANSPORT_OPTIONS={"my_master":"redis-master", "master_name":"redis-master"}

Any idea about a mistake I made, or good tips to use sentinel on django with docker ?

Django 2.2.8
Celery 4.3.0

答案1

得分: 0

I've finally found the error. I used the sentinel for CELERY_RESULT_BACKEND and no option in the hidden CELERY_RESULT_BACKEND_TRANSPORT_OPTIONS parameter was set.

In my case, here is the code in django to use celery and 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"}
英文:

I've finally found the error. I used the sentinel for CELERY_RESULT_BACKEND and no option in the hidden CELERY_RESULT_BACKEND_TRANSPORT_OPTIONS parameter was set.

In my case, here is the code in django to use celery and 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"}

huangapple
  • 本文由 发表于 2020年1月3日 23:05:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/59580876.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定