rabbitmq安裝
rabbitmq的安裝依賴erlang,首先應該先安裝erlang,然后安裝rabbitmq;
Step1:安裝erlang
erlang-rpm安裝教程
選擇在Centos7 上安裝:
To use Erlang 20.x on CentOS 7:
# In /etc/yum.repos.d/rabbitmq-erlang.repo
[rabbitmq-erlang]
name=rabbitmq-erlang
baseurl=https://dl.bintray.com/rabbitmq/rpm/erlang/20/el/7
gpgcheck=1
gpgkey=https://www.rabbitmq.com/rabbitmq-release-signing-key.asc
repo_gpgcheck=0
enabled=1
然后執行:
yum install erlang
Step2: 安裝rabbitmq
下載rpm
wget https://github.com/rabbitmq/rabbitmq-server/releases/download/rabbitmq_v3_6_12/rabbitmq-server-3.6.12-1.el7.noarch.rpm
安裝rpm
rpm --import https://www.rabbitmq.com/rabbitmq-release-signing-key.asc
yum install rabbitmq-server-3.6.12-1.el7.noarch.rpm
Step3: 設置開機自啟動+開啟服務
chkconfig rabbitmq-server on
/sbin/service rabbitmq-server stop/start/
Step4: Rabbit管理(非必須)
開啟Web管理插件
rabbitmq-plugins enable rabbitmq_management
output:
The following plugins have been enabled:
mochiweb
webmachine
rabbitmq_web_dispatch
amqp_client
rabbitmq_management_agent
rabbitmq_management
Applying plugin configuration to rabbit@PC-201602152056... started 6 plugins.
瀏覽器訪問:
http://localhost:15672
,
默認用戶名和密碼: guest/guest;
需要注意的是:guest用戶僅僅提供localhost作為ip登錄;
如果遠程登錄,如:http://192.168.35.129:15672/
, 則會提示錯誤,登錄不了:
# 如下是日志輸出
=WARNING REPORT==== 21-Oct-2017::23:31:33 ===
HTTP access denied: user 'guest' - User can only log in via localhost
訪問控制可參考:
Access Control (Authentication, Authorisation) in RabbitMQ
為了讓guest可遠程訪問,需要修改rabbitmq.config
中的loopback_users
參數,設置為
[{rabbit, [{loopback_users, []}]}].
官網文檔描述如下,可參考官方文檔:RabbitMQ Configuration:
loopback_users參數:
List of users which are only permitted to connect to the broker via a loopback interface (i.e. localhost).
If you wish to allow the default guest user to connect remotely, you need to change this to [].
Default: [<<"guest">>]
默認安裝時,rabbitmq.config
配置文件可能不存在,有兩種方式可以設置配置文件;
- 方式1: 配置文件默認路徑: /etc/rabbitmq/rabbitmq.config
- 方式2: 使用環境變量
RABBITMQ_CONFIG_FILE
指定rabbitmq.config
文件位置;
說明如下:
If rabbitmq.config doesn't exist, it can be created manually. Set the RABBITMQ_CONFIG_FILE environment variable if you change the location. The Erlang runtime automatically appends the .config extension to the value of this variable.
修改完配置文件后,重啟,就可以使用guest用戶遠程訪問了;