RabbitMQ 启用 rabbitmq-auth-backend-http鉴权

查看运行中的容器

# docker ps 

进入容器

# docker exec -it <RabbitMq容器ID> /bin/bash 

启用插件
输入以下命令查看所有插件:

# sudo rabbitmq-plugins list
# 输出部分日志
 Configured: E = explicitly enabled; e = implicitly enabled
 | Status: * = running on rabbit@redissvr
 |/
[  ] rabbitmq_amqp1_0                  3.7.9
[  ] rabbitmq_auth_backend_cache       3.7.9
[  ] rabbitmq_auth_backend_http        3.7.9
[  ] rabbitmq_auth_backend_ldap        3.7.9
[  ] rabbitmq_auth_mechanism_ssl       3.7.9
[  ] rabbitmq_consistent_hash_exchange 3.7.9
[  ] rabbitmq_event_exchange           3.7.9
[  ] rabbitmq_federation               3.7.9
[  ] rabbitmq_federation_management    3.7.9
...

通过下面命令分别启用这两个插件:

# sudo rabbitmq-plugins enable rabbitmq_auth_backend_http

# 和

# sudo rabbitmq-plugins enable rabbitmq_auth_backend_cache

通过 sudo rabbitmqctl environment 查看系统默认设置,和这两个插件相关的部分配置如下:

 ......
 {stdout_formatter,[]},
 {syntax_tools,[]},
 {syslog,
     [{app_name,"rabbitmq-server"},{logger,[]},{syslog_error_logger,false}]},
 {sysmon_handler,
     [{busy_dist_port,true},
      {busy_port,false},
      {gc_ms_limit,0},
      {heap_word_limit,0},
      {port_limit,100},
      {process_limit,100},
      {schedule_ms_limit,0}]},
 {systemd,
     [{auto_formatter,true},
      {logger,
          [{handler,systemd_journal,systemd_journal_h,
               #{formatter => {logger_formatter,#{template => [msg]}}}}]},
      {unset_env,true},
      {watchdog_scale,2}]},
 {tools,[{file_util_search_methods,[{[],[]},{"ebin","esrc"},{"ebin","src"}]}]},
 {xmerl,[]}]

添加配置
不同操作系统中配置文件默认的位置分别如下:

  • Generic UNIX - $RABBITMQ_HOME/etc/rabbitmq/
  • Debian - /etc/rabbitmq/
  • RPM - /etc/rabbitmq/
  • Mac OSX (Homebrew) - ${install_prefix}/etc/rabbitmq/, the Homebrew prefix is usually /usr/local
  • Windows - %APPDATA%RabbitMQ

默认情况下 RabbitMQ 使用的默认配置,在该目录下面并没有配置文件,需要自己手动创建。

# vim /etc/rabbitmq/rabbitmq.conf

如果docker不支持vim
查看是否支持apt-get

# apt-get update


# agt-get install vim

在配置目录新增 rabbitmq.conf 配置文件,添加如下配置:

auth_backends.1 = cache
# 启用 cache 后,不需要直接指定 http 方式
# auth_backends.1 = http
auth_backends.2 = internal
# 缓存后端指定为 http
auth_cache.cached_backend = http
# 认证请求类型
auth_http.http_method   = post
# 认证和授权地址,官方提供了 Spring Boot 示例
# 根据需要配置下面地址
auth_http.user_path = http://localhost:3000/auth/user
auth_http.vhost_path = http://localhost:3000/auth/vhost
auth_http.resource_path = http://localhost:3000/auth/resource
auth_http.topic_path = http://localhost:3000/auth/topic
# 缓存时间,单位毫秒
auth_cache.cache_ttl = 60000

配置好后,重启 RabbitMQ 服务:

#  service rabbitmq-server restart

重启后,查看配置是否成功。

# docker ps 
# docker exec -it <RabbitMq容器ID> /bin/bash
# rabbitmqctl environment 

输出:

......

{rabbitmq_auth_backend_http,
     [{http_method,post},
      {resource_path,"http://localhost:3000/auth/resource"},
      {topic_path,"http://localhost:3000/auth/topic"},
      {user_path,"http://localhost:3000/auth/user"},
      {vhost_path,"http://localhost:3000/auth/vhost"}]},
      
......      

启动插件

rabbitmq-plugins enable rabbitmq_auth_backend_http

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值