赞
踩
由于rabbitMq需要erlang语言的支持,在安装rabbitMq之前需要安装erlang
apt-get install erlang-nox
apt-get install rabbitmq-server
安装完,RabbitMQ 自动已经运行。
(1)添加账号:admin,密码:admin
sudo rabbitmqctl add_user admin admin
(2)赋予权限
sudo rabbitmqctl set_user_tags admin administrator
(3)赋予virtual host中所有资源的配置、写、读权限以便管理其中的资源
sudo rabbitmqctl set_permissions -p / admin '.*' '.*' '.*'
其中 /
可自定义。
(4)删除账号
virtual_host: rabbitmqctl delete_vhost xxx
(5)查看账号
rabbitmqctl list_users
rabbitmq默认是所有IP都可以连接,如果只想让特定IP连接,修改文件 /etc/rabbitmq/rabbitmq-env.conf
去掉 NODE_IP_ADDRESS=127.0.0.1
,将其改为NODE_IP_ADDRESS=x.x.x.x
,下图以0.0.0.0(允许所有IP)为例。
安装了Rabbitmq后,默认也安装了该管理工具,先定位到RabbitMQ的安装目录,一般是在 /etc/rabbitmq
,然后执行命令:
sudo rabbitmq-plugins enable rabbitmq_management
访问 http://192.168.xxx.xxx:15672/
输入刚才设置的账号和密码登陆即可
sudo service rabbitmq-server start #启动
sudo service rabbitmq-server stop #停止
sudo service rabbitmq-server restart #重启
sudo service rabbitmqctl status #状态
spring.rabbitmq.host=127.0.0.1
spring.rabbitmq.port=5672
spring.rabbitmq.username=admin
spring.rabbitmq.password=admin
spring.rabbitmq.virtual-host=/
此处要注意端口是5672
,而不是浏览器访问的 15672
。同时,若没有给账号授予权限(授予权限参考第三步)都会出现如下报错:
2020-01-19 13:18:15.384 ERROR 8916 --- [5.120.126:15672] c.r.c.impl.ForgivingExceptionHandler : An unexpected connection driver error occured
java.net.SocketException: Socket Closed
at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.8.0_181]
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) ~[na:1.8.0_181]
at java.net.SocketInputStream.read(SocketInputStream.java:171) ~[na:1.8.0_181]
at java.net.SocketInputStream.read(SocketInputStream.java:141) ~[na:1.8.0_181]
at java.io.BufferedInputStream.fill(BufferedInputStream.java:246) ~[na:1.8.0_181]
at java.io.BufferedInputStream.read(BufferedInputStream.java:265) ~[na:1.8.0_181]
at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:288) ~[na:1.8.0_181]
at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:91) ~[amqp-client-5.4.3.jar:5.4.3]
at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:164) ~[amqp-client-5.4.3.jar:5.4.3]
at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:596) ~[amqp-client-5.4.3.jar:5.4.3]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_181]
spring.rabbitmq.virtual-host
参数的值对应下边的值,也就是第三步的第三小步的命令 sudo rabbitmqctl set_permissions -p / admin '.*' '.*' '.*'
中 -p
后紧跟的参数 /
,此参数自定义。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。