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

RabbitMQ 启用 rabbitmq-auth-backend-http鉴权,第1张

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

查看运行中的容器

# docker ps 

进入容器

# docker exec -it  /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  /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

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5676432.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存