“连接拒绝”与芹菜 [英] 'connection refused' with Celery

查看:164
本文介绍了“连接拒绝”与芹菜的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Ubuntu EC2节点上有一个Django项目,我一直在使用 Celery 来设置异步。

I have a Django project on an Ubuntu EC2 node, which I have been using to set up an asynchronous using Celery.

我正在追踪如何在芹菜中列出排队的物品?以及文档,在命令行中尝试芹菜。

I am following How to list the queued items in celery? along with the docs, to experiment with celery at the command line.

我已经能够在命令行中使用以下功能获得基本任务:

I've been able to get a basic task working at the command line, using:

(env1)ubuntu@ip-172-31-22-65:~/projects/tp$ celery --app=myproject.celery:app worker --loglevel=INFO

但是,如果我运行其他芹菜命令如下,我得到以下内容:

However, if I run other celery commands like below I'm getting the following:

(env1)ubuntu@ip-172-31-22-65:~/projects/tp$ celery inspect ping
Traceback (most recent call last):
  File "/home/ubuntu/.virtualenvs/env1/bin/celery", line 11, in <module>
    sys.exit(main())
  File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/celery/__main__.py", line 30, in main
    main()
  File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/celery/bin/celery.py", line 81, in main
    cmd.execute_from_commandline(argv)
  File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/celery/bin/celery.py", line 769, in execute_from_commandline
    super(CeleryCommand, self).execute_from_commandline(argv)))
  File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/celery/bin/base.py", line 307, in execute_from_commandline
    return self.handle_argv(self.prog_name, argv[1:])
  File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/celery/bin/celery.py", line 761, in handle_argv
    return self.execute(command, argv)
  File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/celery/bin/celery.py", line 693, in execute
    ).run_from_argv(self.prog_name, argv[1:], command=argv[0])
  File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/celery/bin/base.py", line 311, in run_from_argv
    sys.argv if argv is None else argv, command)
  File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/celery/bin/base.py", line 373, in handle_argv
    return self(*args, **options)
  File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/celery/bin/base.py", line 270, in __call__
    ret = self.run(*args, **kwargs)
  File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/celery/bin/celery.py", line 324, in run
    return self.do_call_method(args, **kwargs)
  File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/celery/bin/celery.py", line 346, in do_call_method
    callback=self.say_remote_command_reply)
  File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/celery/bin/celery.py", line 385, in call
    return getattr(i, method)(*args)
  File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/celery/app/control.py", line 100, in ping
    return self._request('ping')
  File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/celery/app/control.py", line 71, in _request
    timeout=self.timeout, reply=True,
  File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/celery/app/control.py", line 307, in broadcast
    limit, callback, channel=channel,
  File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/kombu/pidbox.py", line 283, in _broadcast
    chan = channel or self.connection.default_channel
  File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/kombu/connection.py", line 756, in default_channel
    self.connection
  File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/kombu/connection.py", line 741, in connection
    self._connection = self._establish_connection()
  File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/kombu/connection.py", line 696, in _establish_connection
    conn = self.transport.establish_connection()
  File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/kombu/transport/pyamqp.py", line 112, in establish_connection
    conn = self.Connection(**opts)
  File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/amqp/connection.py", line 165, in __init__
    self.transport = self.Transport(host, connect_timeout, ssl)
  File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/amqp/connection.py", line 186, in Transport
    return create_transport(host, connect_timeout, ssl)
  File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/amqp/transport.py", line 299, in create_transport
    return TCPTransport(host, connect_timeout)
  File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/amqp/transport.py", line 95, in __init__
    raise socket.error(last_err)
OSError: [Errno 111] Connection refused

安装的python包:

The installed python packages:

(env1)ubuntu@ip-172-31-22-65:~/projects/tp$ pip freeze
amqp==1.4.6
anyjson==0.3.3
billiard==3.3.0.19
celery==3.1.17
Django==1.7.7
django-redis-cache==0.13.0
kombu==3.0.24
pytz==2015.2
redis==2.10.3
requests==2.6.0
uWSGI==2.0.10

/ projects / tp /tp/celery.py

/projects/tp/tp/celery.py

from __future__ import absolute_import

import os
import django
from celery import Celery
from django.conf import settings

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tp.settings')
django.setup()

app = Celery('hello_django')

# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)

还有,在redis.conf中:

also , in redis.conf:

# Specify the path for the unix socket that will be used to listen for
# incoming connections. There is no default, so Redis will not listen
# on a unix socket when not specified.
#
  unixsocket /var/run/redis/redis.sock
  unixsocketperm 777

tp.settings.py:

tp.settings.py:

# CELERY SETTINGS
BROKER_URL = 'redis://localhost:6379/0'
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'

CACHES = {
    'default': {
        'BACKEND': 'redis_cache.RedisCache',
        'LOCATION': '/var/run/redis/redis.sock',
    },
}

编辑2:

ubuntu@ip-172-31-22-65:~$ redis-cli ping
PONG
ubuntu@ip-172-31-22-65:~$ service redis-server status
redis-server is not running

编辑3:

(env1)ubuntu@ip-172-31-22-65:~/projects/tp$ redis-cli ping
PONG
(env1)ubuntu@ip-172-31-22-65:~/projects/tp$ sudo service redis-server start
Starting redis-server: failed
(env1)ubuntu@ip-172-31-22-65:~/projects/tp$ service redis-server status
redis-server is not running

我做错了什么?

推荐答案

我想你正在使用 rabbitmq 作为queue.So检查

I think you are using rabbitmq as queue.So check

sudo service rabbitmq-server status

如果停止,

sudo service rabbitmq-server start

这篇关于“连接拒绝”与芹菜的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆