Install RabbitMQ On Ubuntu

Alvaro Videla & Jason J.W. Williams 著の”RabbitMQ In Action” を購入したついでに、久しぶりに Erlang でかかれた AMQP(Advanced Message Queuing Protoco) である RabbitMQ をインストールする必要があったので、そのメモ。

RabbitMQ のインストール

サーバは 64 bit の Ubuntu 11.10 を利用。
公式ドキュメント通りに apt-get でインストールする。

apt-get のソースを追加
/etc/apt/sources.list に次の行を追加

deb http://www.rabbitmq.com/debian/ testing main

追加したサーバのシグネチャを追加

$ wget http://www.rabbitmq.com/rabbitmq-signing-key-public.asc
$ sudo apt-key add rabbitmq-signing-key-public.asc

apt-get でインストール

$ apt-cache showpkg rabbitmq-server
Package: rabbitmq-server
Versions:
2.8.1-1 (/var/lib/apt/lists/www.rabbitmq.com_debian_dists_testing_main_binary-amd64_Packages) (/var/lib/dpkg/status)
 Description Language:
                 File: /var/lib/apt/lists/www.rabbitmq.com_debian_dists_testing_main_binary-amd64_Packages
                  MD5: 84b4ba9b1e860e3e631ab2c47dc87650

2.5.0-1ubuntu2 (/var/lib/apt/lists/jp.archive.ubuntu.com_ubuntu_dists_oneiric_main_binary-amd64_Packages)
 Description Language: en
                 File: /var/lib/apt/lists/jp.archive.ubuntu.com_ubuntu_dists_oneiric_main_i18n_Translation-en
                  MD5: 84b4ba9b1e860e3e631ab2c47dc87650
 Description Language:
                 File: /var/lib/apt/lists/jp.archive.ubuntu.com_ubuntu_dists_oneiric_main_binary-amd64_Packages
                  MD5: 84b4ba9b1e860e3e631ab2c47dc87650

Reverse Depends:
  mcollective-middleware,rabbitmq-server
  rabbitmq-stomp,rabbitmq-server 2.5.0
  rabbitmq-plugins-common,rabbitmq-server 2.5.0
  rabbitmq-erlang-client,rabbitmq-server 2.5.0
  mcollective-middleware,rabbitmq-server
Dependencies:
2.8.1-1 - erlang-nox (2 1:12.b.3) adduser (0 (null)) logrotate (0 (null))
2.5.0-1ubuntu2 - erlang-nox (2 1:12.b.3) adduser (0 (null)) logrotate (0 (null))
Provides:
2.8.1-1 -
2.5.0-1ubuntu2 -
Reverse Provides:
$ sudo apt-get install rabbitmq-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  erlang-asn1 erlang-base erlang-corba erlang-crypto erlang-dev erlang-docbuilder erlang-edoc erlang-erl-docgen erlang-eunit erlang-ic
  erlang-inets erlang-inviso erlang-mnesia erlang-nox erlang-odbc erlang-os-mon erlang-parsetools erlang-percept erlang-public-key
  erlang-runtime-tools erlang-snmp erlang-ssh erlang-ssl erlang-syntax-tools erlang-tools erlang-webtool erlang-xmerl libsctp1 lksctp-tools
  odbcinst odbcinst1debian2 unixodbc
Suggested packages:
  erlang erlang-manpages erlang-doc fop erlang-ic-java erlang-observer libmyodbc odbc-postgresql tdsodbc unixodbc-bin
The following NEW packages will be installed:
  erlang-asn1 erlang-base erlang-corba erlang-crypto erlang-dev erlang-docbuilder erlang-edoc erlang-erl-docgen erlang-eunit erlang-ic
  erlang-inets erlang-inviso erlang-mnesia erlang-nox erlang-odbc erlang-os-mon erlang-parsetools erlang-percept erlang-public-key
  erlang-runtime-tools erlang-snmp erlang-ssh erlang-ssl erlang-syntax-tools erlang-tools erlang-webtool erlang-xmerl libsctp1 lksctp-tools
  odbcinst odbcinst1debian2 rabbitmq-server unixodbc
0 upgraded, 33 newly installed, 0 to remove and 3 not upgraded.
Need to get 23.2 MB of archives.
After this operation, 43.9 MB of additional disk space will be used.
Do you want to continue [Y/n]? y
...
Setting up rabbitmq-server (2.8.1-1) ...
Adding group `rabbitmq' (GID 115) ...
Done.
Adding system user `rabbitmq' (UID 107) ...
Adding new user `rabbitmq' (UID 107) with group `rabbitmq' ...
Not creating home directory `/var/lib/rabbitmq'.
Starting rabbitmq-server: SUCCESS
rabbitmq-server.
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place

RabbitMQ の起動
start/status/stop を実行すると、以下の様になる。rabbitmq ユーザ権限で実行される。

$ sudo /etc/init.d/rabbitmq-server start
Starting rabbitmq-server: SUCCESS
rabbitmq-server.
$ sudo /etc/init.d/rabbitmq-server status
Status of node rabbit@hostname ...
[{pid,3245},
 {running_applications,[{rabbit,"RabbitMQ","2.8.1"},
                        {os_mon,"CPO  CXC 138 46","2.2.5"},
                        {sasl,"SASL  CXC 138 11","2.1.9.3"},
                        {mnesia,"MNESIA  CXC 138 12","4.4.17"},
                        {stdlib,"ERTS  CXC 138 10","1.17.3"},
                        {kernel,"ERTS  CXC 138 10","2.14.3"}]},
 {os,{unix,linux}},
 {erlang_version,"Erlang R14B02 (erts-5.8.3)  [64-bit] [rq:1] [async-threads:30] [kernel-poll:true]\n"},
 {memory,[{total,24263288},
          {processes,9705480},
          {processes_used,9699672},
          {system,14557808},
          {atom,1135049},
          {atom_used,1131732},
          {binary,129568},
          {code,11291579},
          {ets,715640}]},
 {vm_memory_high_watermark,0.3999999992357081},
 {vm_memory_limit,418688204},
 {file_descriptors,[{total_limit,924},
                    {total_used,3},
                    {sockets_limit,829},
                    {sockets_used,1}]},
 {processes,[{limit,1048576},{used,114}]},
 {run_queue,0},
 {uptime,4}]
...done.

$ sudo /etc/init.d/rabbitmq-server stop
Stopping rabbitmq-server: rabbitmq-server.

RabbitMQ のログファイル

/var/log/rabbitmq/ 以下にある。

$ ls -1 /var/log/rabbitmq/
rabbit@hostname.log
rabbit@hostname-sasl.log
shutdown_err
shutdown_log
startup_err
startup_log

Python クライアント pika のインストール
Python クライアントは pika とか puka とかあるみたいだけど、本家のチュートリアルでは pika がつかわれていたので pika をインストール。ちなみに、 puka は pika のイケテナイところを改善すべく作成されたライブラリらしい

$ pip search rabbit
rod.recipe.rabbitmq       - ZC Buildout recipe for setting up RabbitMQ.
pylibrabbitmq             - Python bindings to librabbitmq-c
puka                      - Puka - the opinionated RabbitMQ client
pyrabbit                  - A Pythonic interface to the RabbitMQ Management HTTP API
bunnyq                    - A command shell and CLI app for testing/administering RabbitMQ using its RESTful HTTP Management API.
pyrabbit.interim          - pyrabbit.interim - Project templates for paster --create
bouncy                    - You are a hungry rabbit. Eat food to complete the level.
rabbitfixture             - Magic.
rejected.py               - rejected.py is a multi-threaded consumer daemon and framework for RabbitMQ

$ pip install pika
Downloading/unpacking pika
  Downloading pika-0.9.5.tar.gz
  Running setup.py egg_info for package pika

Installing collected packages: pika
  Running setup.py install for pika

Successfully installed pika
Cleaning up...

RabbitMQ との通信

公式ドキュメントの hello world を実行

send.py

#!/usr/bin/env python
import pika

connection = pika.BlockingConnection(pika.ConnectionParameters(
        host='localhost'))
channel = connection.channel()

channel.queue_declare(queue='hello')

channel.basic_publish(exchange='',
                      routing_key='hello',
                      body='Hello World!')
print " [x] Sent 'Hello World!'"
connection.close()

プログラムの実行

$ python send.py
 [x] Sent 'Hello World!'

receive.py

#!/usr/bin/env python
import pika

connection = pika.BlockingConnection(pika.ConnectionParameters(
        host='localhost'))
channel = connection.channel()

channel.queue_declare(queue='hello')

print ' [*] Waiting for messages. To exit press CTRL+C'

def callback(ch, method, properties, body):
    print " [x] Received %r" % (body,)

channel.basic_consume(callback,
                      queue='hello',
                      no_ack=True)

channel.start_consuming()

プログラムの実行

$ python receive.py
 [*] Waiting for messages. To exit press CTRL+C
 [x] Received 'Hello World!'

管理ツール のインストール

RabbitMQ には Webインターフェース(rabbitmq_management)やコマンドラインインターフェース(rabbitmqadmin) を介した管理機能もあるので、これらもインストール。

$ apt-cache showpkg rabbitmq-plugins-common
Package: rabbitmq-plugins-common
Versions:
0.0.1-0ubuntu4 (/var/lib/apt/lists/jp.archive.ubuntu.com_ubuntu_dists_oneiric_universe_binary-amd64_Packages)
 Description Language: en
                 File: /var/lib/apt/lists/jp.archive.ubuntu.com_ubuntu_dists_oneiric_universe_i18n_Translation-en
                  MD5: 837cfd782c768ae3a87740a059e8b909
 Description Language:
                 File: /var/lib/apt/lists/jp.archive.ubuntu.com_ubuntu_dists_oneiric_universe_binary-amd64_Packages
                  MD5: 837cfd782c768ae3a87740a059e8b909

Reverse Depends:
  rabbitmq-stomp,rabbitmq-plugins-common
Dependencies:
0.0.1-0ubuntu4 - rabbitmq-server (2 2.5.0)
Provides:
0.0.1-0ubuntu4 -
Reverse Provides:

$ sudo apt-get install rabbitmq-plugins-common
...
[snip]
...
$ sudo rabbitmq-plugins list
[ ] amqp_client                       2.8.6
[ ] eldap                             2.8.6-gite309de4
[ ] erlando                           2.8.6
[ ] mochiweb                          2.3.1-rmq2.8.6-gitd541e9a
[ ] rabbitmq_auth_backend_ldap        2.8.6
[ ] rabbitmq_auth_mechanism_ssl       2.8.6
[ ] rabbitmq_consistent_hash_exchange 2.8.6
[ ] rabbitmq_federation               2.8.6
[ ] rabbitmq_federation_management    2.8.6
[ ] rabbitmq_jsonrpc                  2.8.6
[ ] rabbitmq_jsonrpc_channel          2.8.6
[ ] rabbitmq_jsonrpc_channel_examples 2.8.6
[ ] rabbitmq_management               2.8.6
[ ] rabbitmq_management_agent         2.8.6
[ ] rabbitmq_management_visualiser    2.8.6
[ ] rabbitmq_mochiweb                 2.8.6
[ ] rabbitmq_shovel                   2.8.6
[ ] rabbitmq_shovel_management        2.8.6
[ ] rabbitmq_stomp                    2.8.6
[ ] rabbitmq_tracing                  2.8.6
[ ] rfc4627_jsonrpc                   2.8.6-gita5e7ad7
[ ] webmachine                        1.9.1-rmq2.8.6-git52e62bc

$ sudo rabbitmq-plugins enable rabbitmq_management
The following plugins have been enabled:
  mochiweb
  webmachine
  rabbitmq_mochiweb
  amqp_client
  rabbitmq_management_agent
  rabbitmq_management
Plugin configuration has changed. Restart RabbitMQ for changes to take effect.

$ sudo rabbitmq-plugins list
[e] amqp_client                       2.8.6
[ ] eldap                             2.8.6-gite309de4
[ ] erlando                           2.8.6
[e] mochiweb                          2.3.1-rmq2.8.6-gitd541e9a
[ ] rabbitmq_auth_backend_ldap        2.8.6
[ ] rabbitmq_auth_mechanism_ssl       2.8.6
[ ] rabbitmq_consistent_hash_exchange 2.8.6
[ ] rabbitmq_federation               2.8.6
[ ] rabbitmq_federation_management    2.8.6
[ ] rabbitmq_jsonrpc                  2.8.6
[ ] rabbitmq_jsonrpc_channel          2.8.6
[ ] rabbitmq_jsonrpc_channel_examples 2.8.6
[E] rabbitmq_management               2.8.6
[e] rabbitmq_management_agent         2.8.6
[ ] rabbitmq_management_visualiser    2.8.6
[e] rabbitmq_mochiweb                 2.8.6
[ ] rabbitmq_shovel                   2.8.6
[ ] rabbitmq_shovel_management        2.8.6
[ ] rabbitmq_stomp                    2.8.6
[ ] rabbitmq_tracing                  2.8.6
[ ] rfc4627_jsonrpc                   2.8.6-gita5e7ad7
[e] webmachine                        1.9.1-rmq2.8.6-git52e62bc

$ sudo /etc/init.d/rabbitmq-server  restart
 * Restarting message broker rabbitmq-server
   ...done.

$ rabbitmq-plugins list の表示結果において

  • [E] は explicitly enabled
  • [e] は implicitly enabled

を表す。

WEB インターフェースの確認
以下のアドレスにアクセス

http://HOST:55672/

サイトはベーシック認証がかかっている。ログイン用の ID/PASSWORDguest/guest

WEB API の確認

RabbitMQ には HTTP の API も用意されている。

RabbitMQ Management HTTP API
http://hg.rabbitmq.com/rabbitmq-management/raw-file/rabbitmq_v2_8_6/priv/www/api/index.html

$ curl -i -u guest:guest http://localhost:55672/api/vhosts
HTTP/1.1 200 OK
Server: MochiWeb/1.1 WebMachine/1.9.0 (someone had painted it blue)
Date: Sat, 22 Sep 2012 16:05:58 GMT
Content-Type: application/json
Content-Length: 30
Cache-Control: no-cache

[{"name":"/","tracing":false}]

コマンドラインツールのインストール

コマンドラインツールの “rabbitmqadmin” は WEB 管理画面からダウンロードする。
RabbitMQ のサイト(レポジトリ)からダウンロードすることも可能。
http://hg.rabbitmq.com/rabbitmq-management/raw-file/rabbitmq_v2_8_6/bin/rabbitmqadmin

$ wget --user=guest --password=guest http://localhost:55672/cli/rabbitmqadmin
--2012-09-23 00:14:39--  http://localhost:55672/cli/rabbitmqadmin
Resolving localhost... 127.0.0.1
Connecting to localhost|127.0.0.1|:55672... connected.
HTTP request sent, awaiting response... 401 Unauthorized
Connecting to localhost|127.0.0.1|:55672... connected.
HTTP request sent, awaiting response... 200 OK
Length: 28216 (28K) [text/plain]
Saving to: `rabbitmqadmin'

100%[========================================================================================================>] 28,216      --.-K/s   in 0.001s

2012-09-23 00:14:39 (25.4 MB/s) - `rabbitmqadmin' saved [28216/28216]
$ chmod +x rabbitmqadmin
$ sudo cp rabbitmqadmin /usr/local/bin/
# Bash のコマンド補完も登録
$ sudo sh -c 'rabbitmqadmin --bash-completion > /etc/bash_completion.d/rabbitmqadmin'
$ sudo rabbitmqadmin list queues
...

ということで1時間目はトラブルがなに一つなく無事終了。

Tagged with: , , ,
Posted in middleware
One comment on “Install RabbitMQ On Ubuntu

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Archives
  • RT @__apf__: How to write a research paper: a guide for software engineers & practitioners. docs.google.com/presentation/d… /cc @inwyrd 1 week ago
  • RT @HayatoChiba: 昔、自然と対話しながら数学に打ち込んだら何かを悟れるのではと思いたち、専門書1つだけ持ってパワースポットで名高い奈良の山奥に1週間籠ったことがある。しかし泊まった民宿にドカベンが全巻揃っていたため、水島新司と対話しただけで1週間過ぎた。 それ… 3 weeks ago
  • RT @googlecloud: Ever wonder what underwater fiber optic internet cables look like? Look no further than this deep dive w/ @NatAndLo: https… 3 weeks ago
  • @ijin UTC+01:00 な時間帯で生活しています、、、 6 months ago
  • RT @mattcutts: Google's world-class Site Reliability Engineering team wrote a new book: amazon.com/Site-Reliabili… It's about managing produc… 9 months ago
%d bloggers like this: