剛剛安裝的RabbitMQ-Server-3.3.5,而且也已經開啓了Web管理功能,可是如今存在一個問題:html
出於安全的考慮,guest這個默認的用戶只能經過http://localhost:15672 來登陸,不能使用IP地址登陸,也就是不能遠程訪問,這對於服務器上沒有安裝桌面的狀況是沒法管理維護的。java
要解決這個問題須要配置遠程登陸權限,這裏經過配置文件來實現遠程訪問。web
這裏主要介紹Unix和Windows的配置文件修改。瀏覽器
1、Windows安全
Windows環境下默認配置文件爲目錄/%RabbitMQ Server%/rabbitmq_server-3.3.5/etc下的rabbitmq.config.example文件,咱們能夠直接在這個文件中修改(能夠不用去設置環境變量了),也能夠本身再新建一個rabbitmq.config文件,而後把這個文件路徑配置到環境變量中,這裏介紹就直接修改rabbitmq.config.example文件。服務器
注意:修改以前,須要先中止RabbitMQ服務!!否則是不能保存的!!!app
配置以前須要先添加用戶,用於外網的訪問,可使用命令行來實現添加用戶,須要在RabbitMQ的安裝目錄sbin目錄下執行:async
root@master:/opt/rabbitmq_server-3.3.5/sbin$ rabbitmqctl add_user admin admin
也能夠經過web管理頁面來添加用戶和密碼,使用guest登陸web管理頁面http://localhost:15672,進入「admin」標籤頁,而後點擊「Add a user 」,輸入對用的賬號密碼,而後選擇用戶角色(必定要選擇):tcp
爲了受權該用戶對VirtualHost"/" 的訪問,用戶添加以後,須要對該用戶進行受權,否則運行會出現錯誤:oop
Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; reason: {#method<channel.close>(reply-code=403, reply-text=ACCESS_REFUSED - access to queue 'hello' in vhost '/' refused for user 'admin', class-id=50, method-id=10), null, ""}
詳細錯誤日誌爲:
java.io.IOException at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:106) at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:102) at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:124) at com.rabbitmq.client.impl.ChannelN.queueDeclare(ChannelN.java:766) at com.rabbitmq.client.impl.ChannelN.queueDeclare(ChannelN.java:61) at com.asiainfo.mq.rabbitmq.rabbitmqtest.SendTest.main(SendTest.java:29) Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; reason: {#method<channel.close>(reply-code=403, reply-text=ACCESS_REFUSED - access to queue 'hello' in vhost '/' refused for user 'admin', class-id=50, method-id=10), null, ""} at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:67) at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:33) at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:343) at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:216) at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:118) ... 3 more Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; reason: {#method<channel.close>(reply-code=403, reply-text=ACCESS_REFUSED - access to queue 'hello' in vhost '/' refused for user 'admin', class-id=50, method-id=10), null, ""} at com.rabbitmq.client.impl.ChannelN.asyncShutdown(ChannelN.java:473) at com.rabbitmq.client.impl.ChannelN.processAsync(ChannelN.java:313) at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:144) at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:91) at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:533)
操做過程爲:在Admin標籤頁下點擊新增的用戶"admin",進入受權頁面,默認直接點擊"set permission"便可:
用戶以及受權添加完成以後,在rabbitmq.config.example文件中,添加如下內容,保存後重啓RabbitMQ服務:
…… [ {rabbit, [%% %% Network Connectivity %% ==================== %% %% By default, RabbitMQ will listen on all interfaces, using %% the standard (reserved) AMQP port. %% {tcp_listeners, [5672]}, {loopback_users, ["admin"]}, …… ]} ].
在瀏覽器中輸入http://192.168.0.124:15672實現經過IP地址訪問,成功登陸:
測試用例見博文「RabbitMQ遠程調用測試用例」
2、Unix
unix環境下,配置文件在%/rabbitmq_server-3.3.5%/etc/rabbitmq/rabbitmq.config.example
root@master:/opt/rabbitmq_server-3.3.5/etc/rabbitmq# vi rabbitmq.config.example
%% -*- mode: erlang -*- %% ---------------------------------------------------------------------------- %% RabbitMQ Sample Configuration File. %% %% See http://www.rabbitmq.com/configure.html for details. %% ---------------------------------------------------------------------------- [ {rabbit, [%% %% Network Connectivity %% ==================== %% %% By default, RabbitMQ will listen on all interfaces, using %% the standard (reserved) AMQP port. %% {tcp_listeners, [5672]}, {loopback_users, ["admin"]}, …… ]} ].
參考地址:
http://blog.haohtml.com/archives/15249