翼度科技»论坛 云主机 LINUX 查看内容

RabbitMQ 安装部署与配置总结

6

主题

6

帖子

18

积分

新手上路

Rank: 1

积分
18
实践环境

CentOS-7-x86_64-DVD-2009.iso
rabbitmq-server-3.9.16-1.el7.noarch.rpm
https://github.com/rabbitmq/rabbitmq-server/releases/tag/v3.9.16
https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.9.16/rabbitmq-server-3.9.16-1.el7.noarch.rpm
备注:rabbitmq-server最后一个支持CentOS7的版本
erlang-23.3.4.11-1.el7.x86_64.rpm
https://github.com/rabbitmq/erlang-rpm/releases
https://github.com/rabbitmq/erlang-rpm/releases/download/v23.3.4.11/erlang-23.3.4.11-1.el7.x86_64.rpm
备注:Erlang最后一个支持Centos7的版本
实践操作

下载RabbitMQ及Erlang软件包

RabbitMQ是采用 Erlang语言开发的,所以系统环境必须提供 Erlang环境,需要是安装 Erlang。Erlang版本要和需要安装的RabbitMQ版本匹配,可通过网址https://www.rabbitmq.com/docs/which-erlang 不同Erlang支持的RabbitMQ版本。
安装软件包
  1. # rpm -ivh erlang-23.3.4.11-1.el7.x86_64.rpm
  2. # rpm -ivh rabbitmq-server-3.9.16-1.el7.noarch.rpm
复制代码
说明:参照官方文档,https://www.rabbitmq.com/docs/install-rpm#package-dependencies 还需要安装依赖包:socat,logrotate,但是笔者实践时未安装这两个依赖包。
运行RabbitMQ

RabbitMQ服务器包安装完成后,默认情况下服务器不会作为守护进程启动。运行以下命令,设置当系统启动时,默认以管理员身份,以守护进程的方式启动RabbitMQ
  1. # systemctl enable rabbitmq-server
  2. Created symlink from /etc/systemd/system/multi-user.target.wants/rabbitmq-server.service to /usr/lib/systemd/system/rabbitmq-server.service.
复制代码
停、启服务器
  1. # 启动服务
  2. # systemctl start rabbitmq-server
  3. # 查看服务状态
  4. # systemctl status  rabbitmq-server
  5. ● rabbitmq-server.service - RabbitMQ broker
  6.    Loaded: loaded (/usr/lib/systemd/system/rabbitmq-server.service; enabled; vendor preset: disabled)
  7.    Active: active (running) since Sat 2024-07-13 04:02:54 EDT; 12s ago
  8. Main PID: 1237 (beam.smp)
  9.    CGroup: /system.slice/rabbitmq-server.service
  10.            ├─1237 /usr/lib64/erlang/erts-11.2.2.10/bin/beam.smp -W w -MBas ageffcbf -MHas ageffcbf -MBlmbcs 512 -MHlmbcs 512 -MMmcs 30 -P 1048576 -t 5000000 -stbt db -zdbbl 128000 -sbwt none -sbwtdcpu none -sbwtdio none -...
  11.            ├─1252 erl_child_setup 32768
  12.            ├─1275 /usr/lib64/erlang/erts-11.2.2.10/bin/epmd -daemon
  13.            ├─1296 inet_gethost 4
  14.            └─1297 inet_gethost 4
  15. Jul 13 04:02:49 localhost.localdomain rabbitmq-server[1237]: Doc guides:  https://rabbitmq.com/documentation.html
  16. Jul 13 04:02:49 localhost.localdomain rabbitmq-server[1237]: Support:     https://rabbitmq.com/contact.html
  17. Jul 13 04:02:49 localhost.localdomain rabbitmq-server[1237]: Tutorials:   https://rabbitmq.com/getstarted.html
  18. Jul 13 04:02:49 localhost.localdomain rabbitmq-server[1237]: Monitoring:  https://rabbitmq.com/monitoring.html
  19. Jul 13 04:02:49 localhost.localdomain rabbitmq-server[1237]: Logs: /var/log/rabbitmq/rabbit@localhost.log
  20. Jul 13 04:02:49 localhost.localdomain rabbitmq-server[1237]: /var/log/rabbitmq/rabbit@localhost_upgrade.log
  21. Jul 13 04:02:49 localhost.localdomain rabbitmq-server[1237]: <stdout>
  22. Jul 13 04:02:49 localhost.localdomain rabbitmq-server[1237]: Config file(s): (none)
  23. Jul 13 04:02:54 localhost.localdomain rabbitmq-server[1237]: Starting broker... completed with 0 plugins.
  24. Jul 13 04:02:54 localhost.localdomain systemd[1]: Started RabbitMQ broker.
  25. # 停止服务
  26. # systemctl stop rabbitmq-server
复制代码
参考链接:https://www.rabbitmq.com/docs/install-rpm#running-rpm
启用管理插件
  1. # rabbitmq-plugins enable rabbitmq_management
  2. Enabling plugins on node rabbit@localhost:
  3. rabbitmq_management
  4. The following plugins have been configured:
  5.   rabbitmq_management
  6.   rabbitmq_management_agent
  7.   rabbitmq_web_dispatch
  8. Applying plugin configuration to rabbit@localhost...
  9. Plugin configuration unchanged.
复制代码
备注:开启插件后不需要重启服务器
开启后,浏览器访问管理界面(默认地址:http://node-hostname:15672/.),如下,其中 192.167.206.101为RabbitMQ服务器地址

参考连接:https://www.rabbitmq.com/docs/management#getting-started
配置文件管理

查找配置文件
  1. # rabbitmq-diagnostics status
  2. ......
  3. Config files
  4. Log file(s)
  5. * /var/log/rabbitmq/rabbit@localhost.log
  6. * /var/log/rabbitmq/rabbit@localhost_upgrade.log
  7. * <stdout>
  8. ......
复制代码
如上,配置文件位于 Log file(s)上方,这里笔者实践时命令输出中没看到配置文件路径信息,按官方文档描述,应该Config files下应该会包含配置文件路径信息,类似如下
  1. Config files
  2. * /etc/rabbitmq/advanced.config
  3. * /etc/rabbitmq/rabbitmq.conf
复制代码
参考连接:
https://www.rabbitmq.com/docs/configure#configuration-files
https://www.rabbitmq.com/docs/configure#verify-configuration-config-file-location
用户管理

默认用户访问

broker默认创建了一个用户名和密码都为guest的用户。默认情况下,该用户只能在以访问localhost的方式连接到broker,即不能远程访问。尝试远程访问服务器时会提示User can only log in via localhost。如果希望guest也可以远程登录,需要修改rabbitmq.conf 配置文件,文件末尾添加loopback_users = none
  1. # vi /etc/rabbitmq/rabbitmq.conf
  2. loopback_users = none
  3. # systemctl restart rabbitmq-server
复制代码
参考连接:
https://www.rabbitmq.com/docs/install-rpm#default-user-access
https://www.rabbitmq.com/docs/access-control#user-management
添加用户
  1. # rabbitmqctl add_user "testacc"
  2. Adding user "testacc" ...
  3. Password:
  4. test1234
  5. Done. Don't forget to grant the user permissions to some virtual hosts! See 'rabbitmqctl help set_permissions' to learn more.
复制代码
获取当前用户列表
  1. # rabbitmqctl list_users
  2. Listing users ...
  3. user        tags
  4. testacc        []
  5. guest        [administrator]
  6. # rabbitmqctl list_users --formatter=json
  7. [
  8. {"user":"testacc","tags":[]}
  9. ,{"user":"guest","tags":["administrator"]}
  10. ]
复制代码
删除用户
  1. # rabbitmqctl delete_user 'username'
复制代码
用户授权

使用rabbitmqctl set_permissions要向虚拟主机中的用户授予权限:
  1. # rabbitmqctl set_permissions -p "custom-vhost" "username" ".*" ".*" ".*"
复制代码
说明:
  1. 第一个 ".*" 表示配置每个实体上的权限(First ".*" for configure permission on every entity)
  2. 第二个 ".*" 表示每个实体的写权限(Second ".*" for write permission on every entity)
  3. 第二个 ".*" 表示每个实体的读权限(Third ".*" for read permission on every entity)
复制代码
  1. # rabbitmqctl set_permissions -p "/" "testacc" ".*" ".*" ".*"
  2. Setting permissions for user "testacc" in vhost "/" ...
复制代码
移除授权

使用rabbitmqctl clear_permissions移除授予给虚拟主机中的用户权限:
  1. # Revokes permissions in a virtual host
  2. rabbitmqctl.bat clear_permissions -p 'custom-vhost' 'username'
复制代码
参考连接:https://www.rabbitmq.com/docs/access-control#user-management
https://www.rabbitmq.com/docs/access-control#override-default-user-credentials
设置用户标签
  1. # rabbitmqctl set_user_tags testacc administrator
  2. Setting tags for user "testacc" to [administrator] ...
复制代码
说明:如果不设置标签,以 testacc 用户登录管理界面时,会提示Not management user
参考连接:
https://www.rabbitmq.com/docs/man/rabbitmqctl.8#set_user_tags
https://www.rabbitmq.com/docs/management#permissions
登录管理界面


开启mqtt相关插件
  1. # rabbitmq-plugins enable rabbitmq_mqtt
  2. Enabling plugins on node rabbit@localhost:
  3. rabbitmq_mqtt
  4. The following plugins have been configured:
  5.   rabbitmq_management
  6.   rabbitmq_management_agent
  7.   rabbitmq_mqtt
  8.   rabbitmq_web_dispatch
  9. Applying plugin configuration to rabbit@localhost...
  10. The following plugins have been enabled:
  11.   rabbitmq_mqtt
复制代码
参考链接:
https://www.rabbitmq.com/docs/mqtt#enabling-plugin
  1. # rabbitmq-plugins enable rabbitmq_web_mqtt
  2. Enabling plugins on node rabbit@localhost:
  3. rabbitmq_web_mqtt
  4. The following plugins have been configured:
  5.   rabbitmq_management
  6.   rabbitmq_management_agent
  7.   rabbitmq_mqtt
  8.   rabbitmq_web_dispatch
  9.   rabbitmq_web_mqtt
  10. Applying plugin configuration to rabbit@localhost...
  11. The following plugins have been enabled:
  12.   rabbitmq_web_mqtt
  13. started 1 plugins.
复制代码
参考链接:https://www.rabbitmq.com/docs/web-mqtt#enabling
  1. # rabbitmq-plugins enable rabbitmq_web_mqtt_examples
  2. Enabling plugins on node rabbit@localhost:
  3. rabbitmq_web_mqtt_examples
  4. The following plugins have been configured:
  5.   rabbitmq_management
  6.   rabbitmq_management_agent
  7.   rabbitmq_mqtt
  8.   rabbitmq_web_dispatch
  9.   rabbitmq_web_mqtt
  10.   rabbitmq_web_mqtt_examples
  11. Applying plugin configuration to rabbit@localhost...
  12. The following plugins have been enabled:
  13.   rabbitmq_web_mqtt_examples
复制代码
参考链接:https://www.rabbitmq.com/docs/web-mqtt#examples
安装后示例插件后,访问 http://主机IP地址:15670,出现类似如下页面


来源:https://www.cnblogs.com/shouke/p/18366520
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x

举报 回复 使用道具