rabbitmq.rst 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. $ sudo rabbitmqctl add_user myuser mypassword
  34. .. code-block:: bash
  35. $ sudo rabbitmqctl add_vhost myvhost
  36. .. code-block:: bash
  37. $ sudo 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 OS X is using `Homebrew`_ the new and
  45. shiny package management system for OS X.
  46. First, install homebrew using the one-line command provided by the `Homebrew
  47. documentation`_:
  48. .. code-block:: bash
  49. ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
  50. Finally, we can install rabbitmq using :program:`brew`:
  51. .. code-block:: bash
  52. $ brew install rabbitmq
  53. .. _`Homebrew`: http://github.com/mxcl/homebrew/
  54. .. _`Homebrew documentation`: https://github.com/Homebrew/homebrew/wiki/Installation
  55. .. _rabbitmq-osx-system-hostname:
  56. Configuring the system host name
  57. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  58. If you're using a DHCP server that is giving you a random host name, you need
  59. to permanently configure the host name. This is because RabbitMQ uses the host name
  60. to communicate with nodes.
  61. Use the :program:`scutil` command to permanently set your host name:
  62. .. code-block:: bash
  63. $ sudo scutil --set HostName myhost.local
  64. Then add that host name to :file:`/etc/hosts` so it's possible to resolve it
  65. back into an IP address::
  66. 127.0.0.1 localhost myhost myhost.local
  67. If you start the rabbitmq server, your rabbit node should now be `rabbit@myhost`,
  68. as verified by :program:`rabbitmqctl`:
  69. .. code-block:: bash
  70. $ sudo rabbitmqctl status
  71. Status of node rabbit@myhost ...
  72. [{running_applications,[{rabbit,"RabbitMQ","1.7.1"},
  73. {mnesia,"MNESIA CXC 138 12","4.4.12"},
  74. {os_mon,"CPO CXC 138 46","2.2.4"},
  75. {sasl,"SASL CXC 138 11","2.1.8"},
  76. {stdlib,"ERTS CXC 138 10","1.16.4"},
  77. {kernel,"ERTS CXC 138 10","2.13.4"}]},
  78. {nodes,[rabbit@myhost]},
  79. {running_nodes,[rabbit@myhost]}]
  80. ...done.
  81. This is especially important if your DHCP server gives you a host name
  82. starting with an IP address, (e.g. `23.10.112.31.comcast.net`), because
  83. then RabbitMQ will try to use `rabbit@23`, which is an illegal host name.
  84. .. _rabbitmq-osx-start-stop:
  85. Starting/Stopping the RabbitMQ server
  86. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  87. To start the server:
  88. .. code-block:: bash
  89. $ sudo rabbitmq-server
  90. you can also run it in the background by adding the :option:`-detached` option
  91. (note: only one dash):
  92. .. code-block:: bash
  93. $ sudo rabbitmq-server -detached
  94. Never use :program:`kill` to stop the RabbitMQ server, but rather use the
  95. :program:`rabbitmqctl` command:
  96. .. code-block:: bash
  97. $ sudo rabbitmqctl stop
  98. When the server is running, you can continue reading `Setting up RabbitMQ`_.