RabbitMQ環境搭建
erlang和RabbitMQ版本對應關系:https://www.rabbitmq.com/which-erlang.html
erlang環境安裝
yum方式安裝
- yum源配置
[root@iyeed RabbitMQ]# curl -s https://packagecloud.io/install/repositories/rabbitmq/erlang/script.rpm.sh | sudo bash
- yum安裝erlang
[root@iyeed RabbitMQ]# yum install erlang
- 校驗erlang安裝是否成功
-
- 執行erl命令
[root@iyeed ~]# erl
Erlang/OTP 23 [erts-11.1.8] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]
Eshell V11.1.8 (abort with ^G)
1>
上面是輸入erl命令后顯示的信息。
erlErlang/OPT 23:代表的是erlang版本信息,對應的erlang和RabbitMQ對照表中,查找對應的RabbitMQ安裝即可
-
- erlang輸出消息
1> io:format("hello, world!~n").
hello, world!
ok
2>
-
- 退出erl命令行
2> halt().
完整操作過程如下:
[root@iyeed ~]# erl
Erlang/OTP 23 [erts-11.1.8] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]
?
Eshell V11.1.8 (abort with ^G)
1> io:format("hello, world!~n").
hello, world!
ok
2> halt().
RabbitMQ安裝
導入key
[root@iyeed RabbitMQ]# rpm --import https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey
[root@iyeed RabbitMQ]# rpm --import https://packagecloud.io/gpg.key
以上執行后,沒有任何消息反饋,表明導入key成功
安裝RabbitMQ的前置配置
[root@iyeed RabbitMQ]# curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.rpm.sh | sudo bash
下載RabbitMQ
[root@iyeed RabbitMQ]# wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.8.14/rabbitmq-server-3.8.14-1.el7.noarch.rpm
安裝RabbitMQ
[root@iyeed RabbitMQ]# rpm -ivh rabbitmq-server-3.8.14-1.el7.noarch.rpm
warning: rabbitmq-server-3.8.14-1.el7.noarch.rpm: Header V4 RSA/SHA256 Signature, key ID 6026dfca: NOKEY
error: Failed dependencies:
socat is needed by rabbitmq-server-3.8.14-1.el7.noarch
此處安裝時產生了一些問題,原因是缺少key,只需要導入key和安裝socat即可
- 導入key
[root@iyeed RabbitMQ]# rpm --import https://www.rabbitmq.com/rabbitmq-release-signing-key.asc
如執行如下命令后,沒有任何輸出,則表明導入key成功
- 安裝socat
[root@iyeed RabbitMQ]# yum -y install epel-release
[root@iyeed RabbitMQ]# yum -y install socat
- 再次執行rabbitmq的安裝命令即可
[root@iyeed RabbitMQ]# rpm -ivh rabbitmq-server-3.8.14-1.el7.noarch.rpm
Preparing... ################################# [100%]
Updating / installing...
1:rabbitmq-server-3.8.14-1.el7 ################################# [100%]
啟動 可視化插件 方便管理 rabbitMQ
[root@iyeed RabbitMQ]# rabbitmq-plugins enable rabbitmq_management
Enabling plugins on node rabbit@iyeed:
rabbitmq_management
The following plugins have been configured:
rabbitmq_management
rabbitmq_management_agent
rabbitmq_web_dispatch
Applying plugin configuration to rabbit@iyeed...
The following plugins have been enabled:
rabbitmq_management
rabbitmq_management_agent
rabbitmq_web_dispatch
?
set 3 plugins.
Offline change; changes will take effect at broker restart.
啟動RabbitMQ
[root@iyeed RabbitMQ]# systemctl start rabbitmq-server
訪問控制臺頁面
輸入http://(服務器地址):15672(本示例:http://192.168.0.31:15672/),此時會出現如下UI畫面
如果沒有出現 請檢查防火墻 配置 確認是否開啟端口5672和15672,如果沒有開啟 則無法訪問
用戶登錄和vhost配置
賬號密碼默認是guest,此時登錄會:
RabbitMQ3.3以后,guest賬號只能在本機登錄,可以通過配置修改,但是太麻煩,此處就創建一個新的賬號:
創建admin用戶
如創建用戶名為admin,密碼為admin123的用戶
[root@iyeed ~]# rabbitmqctl add_user admin admin123
Adding user "admin" ...
Done. Don't forget to grant the user permissions to some virtual hosts! See 'rabbitmqctl help set_permissions' to learn more.
設置admin為超級管理員
[root@iyeed ~]# rabbitmqctl set_user_tags admin administrator
Setting tags for user "admin" to [administrator] ...
授權admin遠程訪問
[root@iyeed ~]# rabbitmqctl set_permissions -p / admin "." "." ".*"
Setting permissions for user "admin" in vhost "/" ...
創建完成后,重啟RabbitMQ
[root@iyeed ~]# systemctl restart rabbitmq-server
此時就完成 rabbitMQ 的安裝了 用戶的添加 和 權限的配置 也可以在 ui界面中完成