天天看點

遠端連接配接RabbitMQ失敗 "guest" user can only connect via localhost

為了避免污染宿主系統環境,于是在虛拟機中搭建了一個linux環境并且按照了<code>rabbitmq-server</code>。然後在遠端連接配接的時候一直連接配接失敗。

官網上面給的例子都是在本地使用系統預設的<code>guest</code>使用者連接配接的。沒有給出遠端連接配接的例子,于是閱讀文檔發現:

When the server first starts running, and detects that its database is uninitialised or has been deleted, it initialises a fresh database with the following resources:
a virtual host named / a user named guest with a default password of guest, granted full access to the / virtual host.

也就是剛剛安裝好<code>rabbitmq-server</code>,系統會自動建立一個名為“/”的virtual host,同時也會建立一個使用者名和密碼都是<code>guest</code>的使用者,并且應用"/ virtual host"的所有通路權限。

是以在rabbitmq安裝的機器上使用官網給出的例子:

運作是沒問題的。如果要切換到遠端機器通路的話,單純的修改

是不行的。

因為<code>guest</code>使用者隻是被容許從<code>localhost</code>通路。官網文檔描述如下:

By default, the guest user is prohibited from connecting to the broker remotely; it can only connect over a &gt; loopback interface (i.e. localhost). This applies both to AMQP and to any other protocols enabled via plugins. Any &gt; other users you create will not (by default) be restricted in this way.
This is configured via the loopback_users item in the configuration file.
If you wish to allow the guest user to connect from a remote host, you should set the loopback_users configuration item to []. A complete rabbitmq.config which does this would look like:

預設情況下,使用下面的指令:

會發現:

我這快不想使用預設的<code>guest</code>使用者,我建立立了一個使用者<code>rollen</code>,然後授予所有權限,使用下面的指令:

然後使用下面的代碼遠端通路

<a href="http://www.rabbitmq.com/access-control.html">http://www.rabbitmq.com/access-control.html</a>

==============================================================================

本文轉自被遺忘的部落格園部落格,原文連結:http://www.cnblogs.com/rollenholt/p/4098089.html,如需轉載請自行聯系原作者

繼續閱讀