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