当前位置:   article > 正文

RabbitMQ-远程访问及管理页面配置笔记_rabbitmq 如何查询是否开通了远程访问?

rabbitmq 如何查询是否开通了远程访问?

1.开启后台管理页面

查看Rabbitmq当前是否为运行状态,如果不是运行状态,需要先启动

# /sbin/rabbitmqctl status
# /sbin/service rabbitmq-server start
  • 1
  • 2

启动成功后查看插件列表

[root@localhost rabbitmq]# rabbitmq-plugins list
 Configured: E = explicitly enabled; e = implicitly enabled
 | Status: * = running on rabbit@localhost
 |/
...
[  ] rabbitmq_management               3.7.8
[  ] rabbitmq_management_agent         3.7.8
...
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

开启

[root@localhost rabbitmq]# rabbitmq-plugins enable rabbitmq_management
The following plugins have been configured:
  rabbitmq_management
  rabbitmq_management_agent
  rabbitmq_web_dispatch
Applying plugin configuration to rabbit@localhost...
The following plugins have been enabled:
  rabbitmq_management
  rabbitmq_management_agent
  rabbitmq_web_dispatch

started 3 plugins.
[root@localhost rabbitmq]#
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

2.创建用户及授权

Rabbitmq从3.3.0开始默认用户(guest/guest)只能通过除localhost的访问,我们自己创建登录用户并授权管理员登录

创建用户admin(用户名/密码:admin/admin),命令行输入命令 rabbitmqctl 可查看语法

//语法 rabbitmqctl add_user <username> <password>
[root@localhost rabbitmq]# rabbitmqctl add_user admin admin
Adding user "admin" ...
  • 1
  • 2
  • 3

给用户admin授管理员(administrator)角色

//语法  rabbitmqctl set_user_tags <username> <tag> [...] 
[root@localhost rabbitmq]# rabbitmqctl set_user_tags admin administrator
Setting tags for user "admin" to [administrator] ...
[root@localhost rabbitmq]# rabbitmqctl list_users
Listing users ...
admin	[administrator]
guest	[administrator]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

给用户admin设置权限(开启远程访问)(如果需要远程连接,例如java项目中需要调用mq,则一定要配置,否则无法连接到mq);

设置用户admin具有/vhost1这个virtual host中所有资源的配置、写、读权限以便管理其中的资源

//给用户admin权限

[root@localhost rabbitmq]# rabbitmqctl set_permissions -p "/" admin ".*" ".*" ".*"
Setting permissions for user "admin" in vhost "/" ...
  • 1
  • 2

//查看权限

[root@localhost rabbitmq]# rabbitmqctl list_permissions -p /
Listing permissions for vhost "/" ...
admin	.*	.*	.*
guest	.*	.*	.*
  • 1
  • 2
  • 3
  • 4

此时,还不能通过远程IP:port访问,因为防火墙的原因。

3.开启防火墙端口

//查看已开放的端口(默认不开放任何端口)

firewall-cmd --list-ports
  • 1

//开启15672端口

firewall-cmd --zone=public --add-port=15672/tcp --permanent
  • 1

//重启防火墙

firewall-cmd --reload
  • 1

//再查看端口是否开通,如下说明端口开启了

[root@localhost rabbitmq]# firewall-cmd --list-ports
15672/tcp
  • 1
  • 2
//其他防火墙操作命令
//停止防火墙
systemctl stop firewalld.service
//禁止防火墙开机启动
systemctl disable firewalld.service
//删除(关闭端口)
firewall-cmd --zone= public --remove-port=15672/tcp --permanent
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

此时浏览器输入地址: http://IP:15672 ,然后可使用用户(admin/admin)登录。

4.客户端远程连接配置

[root@localhost rabbitmq]# whereis rabbitmq.config
rabbitmq: /usr/lib/rabbitmq /etc/rabbitmq
  • 1
  • 2

默认情况下/etc/rabbitmq是没有rabbitmq.config文件的,我们需要从安装目录拷贝一份到该路径下

[root@localhost rabbitmq]# cd /etc/rabbitmq
//拷贝文件
[root@localhost rabbitmq]# cp /usr/share/doc/rabbitmq-server-3.7.8/rabbitmq.config.example /etc/rabbitmq/
//重命名
[root@localhost rabbitmq]# mv rabbitmq.config.example rabbitmq.config
  • 1
  • 2
  • 3
  • 4
  • 5

修改rabbitmq.config,加入配置**[{rabbit, [{tcp_listeners, [5672]}, {loopback_users, [“admin”]}]}]**

[root@localhost rabbitmq]# vi rabbitmq.config 

%% -*- mode: erlang -*-
%% ----------------------------------------------------------------------------
%% RabbitMQ Sample Configuration File.
%%
%% Related doc guide: http://www.rabbitmq.com/configure.html. See
%% http://rabbitmq.com/documentation.html for documentation ToC.
%% ----------------------------------------------------------------------------

[
 {rabbit,
  [%%
   %% Networking
   %% ====================
   %%
   %% Related doc guide: http://www.rabbitmq.com/networking.html.

   %% By default, RabbitMQ will listen on all interfaces, using
   %% the standard (reserved) AMQP port.
   %%
   %% {tcp_listeners, [5672]},
%% 下面这行是加入的,其他的不用修改 
{tcp_listeners, [5672]},{loopback_users, ["admin"]}

   %% To listen on a specific interface, provide a tuple of {IpAddress, Port}.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

保存退出,重启Rabbitmq

# /sbin/service rabbitmq-server restart
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/爱喝兽奶帝天荒/article/detail/734619
推荐阅读
相关标签
  

闽ICP备14008679号