二、RabbitMQ——添加新用户并设置远程访问

作者: 小疯子 分类: RabbitMQ 发布时间: 2019-03-28 20:36

1. 添加用户feng以及设置密码123456

rabbitmqctl add_user feng 123456

更改用户密码

rabbitmqctl change_password Username Newpassword

2.  设置其为administrator标签

rabbitmqctl set_user_tags feng administrator

3. 创建虚拟vhost,然后赋予用户操作此虚拟机的各种权限

[root@feng ~]# rabbitmqctl add_vhost feng-vhost
Adding vhost "feng-vhost" ...
[root@feng ~]# rabbitmqctl set_permissions -p feng-vhost feng ".*" ".*" ".*"
Setting permissions for user "feng" in vhost "feng-vhost" ...

 [-p vhostuser conf write read
目前能力先暂时将feng-vhost改成默认的“/”吧,要不然每次重新启动我还需要再新加这个虚拟vhost

4. 查看vhost允许哪些用户访问

[root@feng ~]# rabbitmqctl list_permissions -p feng-vhost
Listing permissions for vhost "feng-vhost" ...
user configure write read
feng .* .* .*

feng-vhost改成/

5. 设置远程用户访问

可以通过 find / -name rabbitmq-defaults 查找rabbitmq-defaults文件,查看config文件的存储路径
这里就直接放上此文件(注意配置文件重命名为rabbitmq.conf)
链接:https://pan.baidu.com/s/1UIZGKv1BeOdWXUidliWCPQ
提取码:zk6t
编写内容如下,打开以下注释或修改
listeners.tcp.default = 5672
loopback_users.feng = false
management.tcp.port = 15672
management.tcp.ip = 0.0.0.0
[                                                                                                                                  
{rabbit, [{tcp_listeners, [5672]}, {loopback_users, ["feng"]}]}
].
注意loopback_users后的用户不能用原有guest外框<<>>,要改成[]来包含
将此文件存放到/etc/rabbitmq/rabbitmq.conf;
http://主机ip:15672/可以访问到management的页面

6. 重新启动

[root@localhost rabbitmq]# service rabbitmq-server stop

[root@localhost rabbitmq]# service rabbitmq-server start

[root@localhost rabbitmq]# service rabbitmq-server status

7.  注意:记得要开放5672和15672端口

/sbin/iptables -I INPUT -p tcp --dport 5672 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 15672 -j ACCEPT

其他:

参考链接:https://blog.csdn.net/andrewniu/article/details/80255829

官网命令:https://www.rabbitmq.com/rabbitmqctl.8.html

官网配置:https://www.rabbitmq.com/configure.html#config-file

0