rabbitmq.rst 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. .. _broker-rabbitmq:
  2. ================
  3. Using RabbitMQ
  4. ================
  5. .. contents::
  6. :local:
  7. Installation & Configuration
  8. ============================
  9. RabbitMQ is the default broker so it does not require any additional
  10. dependencies or initial configuration, other than the URL location of
  11. the broker instance you want to use:
  12. .. code-block:: python
  13. broker_url = 'amqp://guest:guest@localhost:5672//'
  14. For a description of broker URLs and a full list of the
  15. various broker configuration options available to Celery,
  16. see :ref:`conf-broker-settings`.
  17. .. _installing-rabbitmq:
  18. Installing the RabbitMQ Server
  19. ==============================
  20. See `Installing RabbitMQ`_ over at RabbitMQ's website. For Mac OS X
  21. see `Installing RabbitMQ on OS X`_.
  22. .. _`Installing RabbitMQ`: http://www.rabbitmq.com/install.html
  23. .. note::
  24. If you're getting `nodedown` errors after installing and using
  25. :program:`rabbitmqctl` then this blog post can help you identify
  26. the source of the problem:
  27. http://somic.org/2009/02/19/on-rabbitmqctl-and-badrpcnodedown/
  28. .. _rabbitmq-configuration:
  29. Setting up RabbitMQ
  30. -------------------
  31. To use celery we need to create a RabbitMQ user, a virtual host and
  32. allow that user access to that virtual host:
  33. .. code-block:: console
  34. $ sudo rabbitmqctl add_user myuser mypassword
  35. .. code-block:: console
  36. $ sudo rabbitmqctl add_vhost myvhost
  37. .. code-block:: console
  38. $ sudo rabbitmqctl set_user_tags myuser mytag
  39. .. code-block:: console
  40. $ sudo rabbitmqctl set_permissions -p myvhost myuser ".*" ".*" ".*"
  41. See the RabbitMQ `Admin Guide`_ for more information about `access control`_.
  42. .. _`Admin Guide`: http://www.rabbitmq.com/admin-guide.html
  43. .. _`access control`: http://www.rabbitmq.com/admin-guide.html#access-control
  44. .. _rabbitmq-osx-installation:
  45. Installing RabbitMQ on OS X
  46. ---------------------------
  47. The easiest way to install RabbitMQ on OS X is using `Homebrew`_ the new and
  48. shiny package management system for OS X.
  49. First, install homebrew using the one-line command provided by the `Homebrew
  50. documentation`_:
  51. .. code-block:: console
  52. ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
  53. Finally, we can install rabbitmq using :program:`brew`:
  54. .. code-block:: console
  55. $ brew install rabbitmq
  56. .. _`Homebrew`: http://github.com/mxcl/homebrew/
  57. .. _`Homebrew documentation`: https://github.com/Homebrew/homebrew/wiki/Installation
  58. .. _rabbitmq-osx-system-hostname:
  59. After you have installed rabbitmq with brew you need to add the following to your path to be able to start and stop the broker. Add it to your .bash_profile or .profile
  60. .. code-block:: console
  61. `PATH=$PATH:/usr/local/sbin`
  62. Configuring the system host name
  63. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  64. If you're using a DHCP server that is giving you a random host name, you need
  65. to permanently configure the host name. This is because RabbitMQ uses the host name
  66. to communicate with nodes.
  67. Use the :program:`scutil` command to permanently set your host name:
  68. .. code-block:: console
  69. $ sudo scutil --set HostName myhost.local
  70. Then add that host name to :file:`/etc/hosts` so it's possible to resolve it
  71. back into an IP address::
  72. 127.0.0.1 localhost myhost myhost.local
  73. If you start the rabbitmq server, your rabbit node should now be `rabbit@myhost`,
  74. as verified by :program:`rabbitmqctl`:
  75. .. code-block:: console
  76. $ sudo rabbitmqctl status
  77. Status of node rabbit@myhost ...
  78. [{running_applications,[{rabbit,"RabbitMQ","1.7.1"},
  79. {mnesia,"MNESIA CXC 138 12","4.4.12"},
  80. {os_mon,"CPO CXC 138 46","2.2.4"},
  81. {sasl,"SASL CXC 138 11","2.1.8"},
  82. {stdlib,"ERTS CXC 138 10","1.16.4"},
  83. {kernel,"ERTS CXC 138 10","2.13.4"}]},
  84. {nodes,[rabbit@myhost]},
  85. {running_nodes,[rabbit@myhost]}]
  86. ...done.
  87. This is especially important if your DHCP server gives you a host name
  88. starting with an IP address, (e.g. `23.10.112.31.comcast.net`), because
  89. then RabbitMQ will try to use `rabbit@23`, which is an illegal host name.
  90. .. _rabbitmq-osx-start-stop:
  91. Starting/Stopping the RabbitMQ server
  92. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  93. To start the server:
  94. .. code-block:: console
  95. $ sudo rabbitmq-server
  96. you can also run it in the background by adding the :option:`-detached` option
  97. (note: only one dash):
  98. .. code-block:: console
  99. $ sudo rabbitmq-server -detached
  100. Never use :program:`kill` to stop the RabbitMQ server, but rather use the
  101. :program:`rabbitmqctl` command:
  102. .. code-block:: console
  103. $ sudo rabbitmqctl stop
  104. When the server is running, you can continue reading `Setting up RabbitMQ`_.