rabbitmq.rst 4.9 KB

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