RabbitMQ系列(一)启动及网页、外网访问配置

RabbitMQ 启动及网页、外网访问配置

1.安装

安装过程就不重复了,直接pip install或者 brew install都可以,简单,安装完毕后进入文件夹 /usr/local/opt/rabbitmq/sbin 命令文件夹可以看到有一下命令:

iazijie sbin $ pwd
/usr/local/opt/rabbitmq/sbin
jiazijie sbin $ ll
total 1096
-r-xr-xr-x  1 jiazijie  admin  468026  7  5  2018 cuttlefish
-r-xr-xr-x  1 jiazijie  admin    2145  8 30  2018 rabbitmq-defaults
-r-xr-xr-x  1 jiazijie  admin    1244  7  5  2018 rabbitmq-diagnostics
-r-xr-xr-x  1 jiazijie  admin   14811  8 30  2018 rabbitmq-env
-r-xr-xr-x  1 jiazijie  admin    1263  7  5  2018 rabbitmq-plugins
-r-xr-xr-x  1 jiazijie  admin   14087  7  5  2018 rabbitmq-server
-r-xr-xr-x  1 jiazijie  admin   38861  7  5  2018 rabbitmqadmin
-r-xr-xr-x  1 jiazijie  admin    1235  7  5  2018 rabbitmqctl

2.命令

rabbitmq-server start # 启动服务
rabbitmq-server status # 查看服务状态
rabbitmq-server stop # 停止服务

rabbitmqctl list_users #查看当前所有用户
rabbitmqctl list_user_permissions guest #查看用户 guest权限
rabbitmqctl add_user username password #添加用户
rabbitmqctl set_user_tags username administrator #设置用户tag
rabbitmqctl set_permissions -p / username “." ".” “.*” #设置用户权限
rabbitmqctl list_user_permissions username #查看用户 username权限

rabbitmq-plugins enable rabbitmq_management #RabbitMQ自带了web管理界面,只需要启动插件便可以使用,默认端口 15672,访问 127.0.0.1:15672,输入账号密码,登陆

jiazijie sbin $ rabbitmqctl list_user_permissions guest
Listing permissions for user "guest" ...
/	.*	.*	.*
jiazijie sbin $
jiazijie sbin $ rabbitmqctl list_user_permissions admin
Listing permissions for user "admin" ...
/	.*	.*	.*
jiazijie sbin $
jiazijie sbin $ rabbitmqctl add_user jzj jzj
Adding user "jzj" ...
jiazijie sbin $ rabbitmqctl list_user_permissions jzj
Listing permissions for user "jzj" ...

jiazijie sbin $
jiazijie sbin $ rabbitmqctl set_user_tags jzj administrator
Setting tags for user "jzj" to [administrator] ...
jiazijie sbin $
jiazijie sbin $ rabbitmqctl set_permissions -p / jzj ".*" ".*" ".*"
Setting permissions for user "jzj" in vhost "/" ...
jiazijie sbin $
jiazijie sbin $ rabbitmqctl list_user_permissions jzj
Listing permissions for user "jzj" ...
/	.*	.*	.*
jiazijie sbin $ rabbitmq-plugins enable rabbitmq_management
The following plugins have been configured:
  rabbitmq_amqp1_0
  rabbitmq_management
  rabbitmq_management_agent
  rabbitmq_mqtt
  rabbitmq_stomp
  rabbitmq_web_dispatch
Applying plugin configuration to rabbit@localhost...
Plugin configuration unchanged.

3.配置

配置RabbitMQ

关于RabbitMQ的配置,可以下载RabbitMQ的配置文件模板到/etc/rabbitmq/rabbitmq.config, 然后按照需求更改即可。
关于每个配置项的具体作用,可以参考官方文档 https://www.rabbitmq.com/configure.html。
更新配置后,别忘了重启服务哦!

开启用户远程访问

默认情况下,RabbitMQ的默认的guest用户只允许本机访问, 如果想让guest用户能够远程访问的话,只需要将配置文件中的loopback_users列表置为空即可,如下:

{loopback_users, []}

另外关于新添加的用户,直接就可以从远程访问的,如果想让新添加的用户只能本地访问,可以将用户名添加到上面的列表, 如只允许admin用户本机访问。

{loopback_users, ["admin"]}

更新配置后,别忘了重启服务哦!

你可能感兴趣的:(MQ中间件)