带你走进远程访问及管理页面配置---Rabbitmq-2
本帖最后由 草帽路飞UU 于 2022-9-14 15:59 编辑1.开启后台管理页面
查看Rabbitmq当前是否为运行状态,如果不是运行状态,需要先启动。
# /sbin/rabbitmqctl status
# /sbin/service rabbitmq-server start
启动成功后查看插件列表:
# 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
...
开启:
# 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.
#
2.创建用户及授权
Rabbitmq从3.3.0开始默认用户(guest/guest)只能通过除localhost的访问,我们自己创建登录用户并授权管理员登录。
创建用户admin(用户名/密码:admin/admin),命令行输入命令 rabbitmqctl 可查看语法。
//语法 rabbitmqctl add_user <username> <password>
# rabbitmqctl add_user admin admin
Adding user "admin" ...
给用户admin授管理员(administrator)角色:
//语法rabbitmqctl set_user_tags <username> <tag> [...]
# rabbitmqctl set_user_tags admin administrator
Setting tags for user "admin" to ...
# rabbitmqctl list_users
Listing users ...
admin
guest
给用户admin设置权限(开启远程访问)(如果需要远程连接,例如java项目中需要调用mq,则一定要配置,否则无法连接到mq);
设置用户admin具有/vhost1这个virtual host中所有资源的配置、写、读权限以便管理其中的资源。
//给用户admin权限
# rabbitmqctl set_permissions -p "/" admin ".*" ".*" ".*"
Setting permissions for user "admin" in vhost "/" ...
//查看权限
# rabbitmqctl list_permissions -p /
Listing permissions for vhost "/" ...
admin.*.*.*
guest.*.*.*
此时,还不能通过远程IP:port访问,因为防火墙的原因。
3.开启防火墙端口
//查看已开放的端口(默认不开放任何端口)
firewall-cmd --list-ports
//开启15672端口
firewall-cmd --zone=public --add-port=15672/tcp --permanent
//重启防火墙
firewall-cmd --reload
//再查看端口是否开通,如下说明端口开启了
# firewall-cmd --list-ports
15672/tcp
//其他防火墙操作命令
//停止防火墙
systemctl stop firewalld.service
//禁止防火墙开机启动
systemctl disable firewalld.service
//删除(关闭端口)
firewall-cmd --zone= public --remove-port=15672/tcp --permanent
此时浏览器输入地址: http://IP:15672,然后可使用用户(admin/admin)登录。
4.客户端远程连接配置
# whereis rabbitmq.config
rabbitmq: /usr/lib/rabbitmq /etc/rabbitmq
默认情况下/etc/rabbitmq是没有rabbitmq.config文件的,我们需要从安装目录拷贝一份到该路径下:
# cd /etc/rabbitmq
//拷贝文件
# cp /usr/share/doc/rabbitmq-server-3.7.8/rabbitmq.config.example /etc/rabbitmq/
//重命名
# mv rabbitmq.config.example rabbitmq.config
修改rabbitmq.config,加入配置[{rabbit, [{tcp_listeners, }, {loopback_users, ["admin"]}]}]
# 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, },
%% 下面这行是加入的,其他的不用修改
{tcp_listeners, },{loopback_users, ["admin"]}
%% To listen on a specific interface, provide a tuple of {IpAddress, Port}.
保存退出,重启Rabbitmq。
# /sbin/service rabbitmq-server restart
页:
[1]