rabbitmq.rst 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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://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. $ rabbitmqctl add_user myuser mypassword
  34. .. code-block:: bash
  35. $ rabbitmqctl add_vhost myvhost
  36. .. code-block:: bash
  37. $ rabbitmqctl set_permissions -p myvhost myuser ".*" ".*" ".*"
  38. See the RabbitMQ `Admin Guide`_ for more information about `access control`_.
  39. .. _`Admin Guide`: http://www.rabbitmq.com/admin-guide.html
  40. .. _`access control`: http://www.rabbitmq.com/admin-guide.html#access-control
  41. .. _rabbitmq-osx-installation:
  42. Installing RabbitMQ on OS X
  43. ---------------------------
  44. The easiest way to install RabbitMQ on Snow Leopard is using `Homebrew`_; the new
  45. and shiny package management system for OS X.
  46. In this example we'll install Homebrew into :file:`/lol`, but you can
  47. choose whichever destination, even in your home directory if you want, as one of
  48. the strengths of Homebrew is that it's relocatable.
  49. Homebrew is actually a `git`_ repository, so to install Homebrew, you first need to
  50. install git. Download and install from the disk image at
  51. http://code.google.com/p/git-osx-installer/downloads/list?can=3
  52. When git is installed you can finally clone the repository, storing it at the
  53. :file:`/lol` location:
  54. .. code-block:: bash
  55. $ git clone git://github.com/mxcl/homebrew /lol
  56. Brew comes with a simple utility called :program:`brew`, used to install, remove and
  57. query packages. To use it you first have to add it to :envvar:`PATH`, by
  58. adding the following line to the end of your :file:`~/.profile`:
  59. .. code-block:: bash
  60. export PATH="/lol/bin:/lol/sbin:$PATH"
  61. Save your profile and reload it:
  62. .. code-block:: bash
  63. $ source ~/.profile
  64. Finally, we can install rabbitmq using :program:`brew`:
  65. .. code-block:: bash
  66. $ brew install rabbitmq
  67. .. _`Homebrew`: http://github.com/mxcl/homebrew/
  68. .. _`git`: http://git-scm.org
  69. .. _rabbitmq-osx-system-hostname:
  70. Configuring the system host name
  71. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  72. If you're using a DHCP server that is giving you a random host name, you need
  73. to permanently configure the host name. This is because RabbitMQ uses the host name
  74. to communicate with nodes.
  75. Use the :program:`scutil` command to permanently set your host name:
  76. .. code-block:: bash
  77. $ sudo scutil --set HostName myhost.local
  78. Then add that host name to :file:`/etc/hosts` so it's possible to resolve it
  79. back into an IP address::
  80. 127.0.0.1 localhost myhost myhost.local
  81. If you start the rabbitmq server, your rabbit node should now be `rabbit@myhost`,
  82. as verified by :program:`rabbitmqctl`:
  83. .. code-block:: bash
  84. $ sudo rabbitmqctl status
  85. Status of node rabbit@myhost ...
  86. [{running_applications,[{rabbit,"RabbitMQ","1.7.1"},
  87. {mnesia,"MNESIA CXC 138 12","4.4.12"},
  88. {os_mon,"CPO CXC 138 46","2.2.4"},
  89. {sasl,"SASL CXC 138 11","2.1.8"},
  90. {stdlib,"ERTS CXC 138 10","1.16.4"},
  91. {kernel,"ERTS CXC 138 10","2.13.4"}]},
  92. {nodes,[rabbit@myhost]},
  93. {running_nodes,[rabbit@myhost]}]
  94. ...done.
  95. This is especially important if your DHCP server gives you a host name
  96. starting with an IP address, (e.g. `23.10.112.31.comcast.net`), because
  97. then RabbitMQ will try to use `rabbit@23`, which is an illegal host name.
  98. .. _rabbitmq-osx-start-stop:
  99. Starting/Stopping the RabbitMQ server
  100. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  101. To start the server:
  102. .. code-block:: bash
  103. $ sudo rabbitmq-server
  104. you can also run it in the background by adding the :option:`-detached` option
  105. (note: only one dash):
  106. .. code-block:: bash
  107. $ sudo rabbitmq-server -detached
  108. Never use :program:`kill` to stop the RabbitMQ server, but rather use the
  109. :program:`rabbitmqctl` command:
  110. .. code-block:: bash
  111. $ sudo rabbitmqctl stop
  112. When the server is running, you can continue reading `Setting up RabbitMQ`_.