rabbitmq.rst 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 macOS
  21. see `Installing RabbitMQ on macOS`_.
  22. .. _`Installing RabbitMQ`: http://www.rabbitmq.com/install.html
  23. .. note::
  24. If you're getting `nodedown` errors after installing and using
  25. :command:`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-macOS-installation:
  45. Installing RabbitMQ on macOS
  46. ----------------------------
  47. The easiest way to install RabbitMQ on macOS is using `Homebrew`_ the new and
  48. shiny package management system for macOS.
  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 :command:`brew`:
  54. .. code-block:: console
  55. $ brew install rabbitmq
  56. .. _`Homebrew`: https://github.com/mxcl/homebrew/
  57. .. _`Homebrew documentation`: https://github.com/Homebrew/homebrew/wiki/Installation
  58. .. _rabbitmq-macOS-system-hostname:
  59. After you've installed RabbitMQ with :command:`brew` you need to add the following to
  60. your path to be able to start and stop the broker: add it to the start-up file for your
  61. shell (e.g. :file:`.bash_profile` or :file:`.profile`).
  62. .. code-block:: bash
  63. PATH=$PATH:/usr/local/sbin
  64. Configuring the system host name
  65. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  66. If you're using a DHCP server that is giving you a random host name, you need
  67. to permanently configure the host name. This is because RabbitMQ uses the host name
  68. to communicate with nodes.
  69. Use the :command:`scutil` command to permanently set your host name:
  70. .. code-block:: console
  71. $ sudo scutil --set HostName myhost.local
  72. Then add that host name to :file:`/etc/hosts` so it's possible to resolve it
  73. back into an IP address::
  74. 127.0.0.1 localhost myhost myhost.local
  75. If you start the :command:`rabbitmq-server`, your rabbit node should now
  76. be `rabbit@myhost`, as verified by :command:`rabbitmqctl`:
  77. .. code-block:: console
  78. $ sudo rabbitmqctl status
  79. Status of node rabbit@myhost ...
  80. [{running_applications,[{rabbit,"RabbitMQ","1.7.1"},
  81. {mnesia,"MNESIA CXC 138 12","4.4.12"},
  82. {os_mon,"CPO CXC 138 46","2.2.4"},
  83. {sasl,"SASL CXC 138 11","2.1.8"},
  84. {stdlib,"ERTS CXC 138 10","1.16.4"},
  85. {kernel,"ERTS CXC 138 10","2.13.4"}]},
  86. {nodes,[rabbit@myhost]},
  87. {running_nodes,[rabbit@myhost]}]
  88. ...done.
  89. This is especially important if your DHCP server gives you a host name
  90. starting with an IP address, (e.g. `23.10.112.31.comcast.net`), because
  91. then RabbitMQ will try to use `rabbit@23`, which is an illegal host name.
  92. .. _rabbitmq-macOS-start-stop:
  93. Starting/Stopping the RabbitMQ server
  94. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  95. To start the server:
  96. .. code-block:: console
  97. $ sudo rabbitmq-server
  98. you can also run it in the background by adding the ``-detached`` option
  99. (note: only one dash):
  100. .. code-block:: console
  101. $ sudo rabbitmq-server -detached
  102. Never use :command:`kill` (:manpage:`kill(1)`) to stop the RabbitMQ server,
  103. but rather use the :command:`rabbitmqctl` command:
  104. .. code-block:: console
  105. $ sudo rabbitmqctl stop
  106. When the server is running, you can continue reading `Setting up RabbitMQ`_.