RabbitMQ 安装部署与配置总结
实践环境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版本。
安装软件包
# rpm -ivh erlang-23.3.4.11-1.el7.x86_64.rpm
# 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
# systemctl enable rabbitmq-server
Created symlink from /etc/systemd/system/multi-user.target.wants/rabbitmq-server.service to /usr/lib/systemd/system/rabbitmq-server.service.停、启服务器
# 启动服务
# systemctl start rabbitmq-server
# 查看服务状态
# systemctl statusrabbitmq-server
● rabbitmq-server.service - RabbitMQ broker
Loaded: loaded (/usr/lib/systemd/system/rabbitmq-server.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2024-07-13 04:02:54 EDT; 12s ago
Main PID: 1237 (beam.smp)
CGroup: /system.slice/rabbitmq-server.service
├─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 -...
├─1252 erl_child_setup 32768
├─1275 /usr/lib64/erlang/erts-11.2.2.10/bin/epmd -daemon
├─1296 inet_gethost 4
└─1297 inet_gethost 4
Jul 13 04:02:49 localhost.localdomain rabbitmq-server: Doc guides:https://rabbitmq.com/documentation.html
Jul 13 04:02:49 localhost.localdomain rabbitmq-server: Support: https://rabbitmq.com/contact.html
Jul 13 04:02:49 localhost.localdomain rabbitmq-server: Tutorials: https://rabbitmq.com/getstarted.html
Jul 13 04:02:49 localhost.localdomain rabbitmq-server: Monitoring:https://rabbitmq.com/monitoring.html
Jul 13 04:02:49 localhost.localdomain rabbitmq-server: Logs: /var/log/rabbitmq/rabbit@localhost.log
Jul 13 04:02:49 localhost.localdomain rabbitmq-server: /var/log/rabbitmq/rabbit@localhost_upgrade.log
Jul 13 04:02:49 localhost.localdomain rabbitmq-server: <stdout>
Jul 13 04:02:49 localhost.localdomain rabbitmq-server: Config file(s): (none)
Jul 13 04:02:54 localhost.localdomain rabbitmq-server: Starting broker... completed with 0 plugins.
Jul 13 04:02:54 localhost.localdomain systemd: Started RabbitMQ broker.
# 停止服务
# systemctl stop rabbitmq-server参考链接:https://www.rabbitmq.com/docs/install-rpm#running-rpm
启用管理插件
# rabbitmq-plugins enable rabbitmq_management
Enabling plugins on node rabbit@localhost:
rabbitmq_management
The following plugins have been configured:
rabbitmq_management
rabbitmq_management_agent
rabbitmq_web_dispatch
Applying plugin configuration to rabbit@localhost...
Plugin configuration unchanged.备注:开启插件后不需要重启服务器
开启后,浏览器访问管理界面(默认地址:http://node-hostname:15672/.),如下,其中 192.167.206.101为RabbitMQ服务器地址
参考连接:https://www.rabbitmq.com/docs/management#getting-started
配置文件管理
查找配置文件
# rabbitmq-diagnostics status
......
Config files
Log file(s)
* /var/log/rabbitmq/rabbit@localhost.log
* /var/log/rabbitmq/rabbit@localhost_upgrade.log
* <stdout>
......如上,配置文件位于 Log file(s)上方,这里笔者实践时命令输出中没看到配置文件路径信息,按官方文档描述,应该Config files下应该会包含配置文件路径信息,类似如下
Config files
* /etc/rabbitmq/advanced.config
* /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
# vi /etc/rabbitmq/rabbitmq.conf
loopback_users = none
# systemctl restart rabbitmq-server参考连接:
https://www.rabbitmq.com/docs/install-rpm#default-user-access
https://www.rabbitmq.com/docs/access-control#user-management
添加用户
# rabbitmqctl add_user "testacc"
Adding user "testacc" ...
Password:
test1234
Done. Don't forget to grant the user permissions to some virtual hosts! See 'rabbitmqctl help set_permissions' to learn more.获取当前用户列表
# rabbitmqctl list_users
Listing users ...
user tags
testacc []
guest
# rabbitmqctl list_users --formatter=json
[
{"user":"testacc","tags":[]}
,{"user":"guest","tags":["administrator"]}
]删除用户
# rabbitmqctl delete_user 'username'用户授权
使用rabbitmqctl set_permissions要向虚拟主机中的用户授予权限:
# rabbitmqctl set_permissions -p "custom-vhost" "username" ".*" ".*" ".*"说明:
第一个 ".*" 表示配置每个实体上的权限(First ".*" for configure permission on every entity)
第二个 ".*" 表示每个实体的写权限(Second ".*" for write permission on every entity)
第二个 ".*" 表示每个实体的读权限(Third ".*" for read permission on every entity)# rabbitmqctl set_permissions -p "/" "testacc" ".*" ".*" ".*"
Setting permissions for user "testacc" in vhost "/" ...移除授权
使用rabbitmqctl clear_permissions移除授予给虚拟主机中的用户权限:
# Revokes permissions in a virtual host
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
设置用户标签
# rabbitmqctl set_user_tags testacc administrator
Setting tags for user "testacc" to ...说明:如果不设置标签,以 testacc 用户登录管理界面时,会提示Not management user
参考连接:
https://www.rabbitmq.com/docs/man/rabbitmqctl.8#set_user_tags
https://www.rabbitmq.com/docs/management#permissions
登录管理界面
开启mqtt相关插件
# rabbitmq-plugins enable rabbitmq_mqtt
Enabling plugins on node rabbit@localhost:
rabbitmq_mqtt
The following plugins have been configured:
rabbitmq_management
rabbitmq_management_agent
rabbitmq_mqtt
rabbitmq_web_dispatch
Applying plugin configuration to rabbit@localhost...
The following plugins have been enabled:
rabbitmq_mqtt参考链接:
https://www.rabbitmq.com/docs/mqtt#enabling-plugin
# rabbitmq-plugins enable rabbitmq_web_mqtt
Enabling plugins on node rabbit@localhost:
rabbitmq_web_mqtt
The following plugins have been configured:
rabbitmq_management
rabbitmq_management_agent
rabbitmq_mqtt
rabbitmq_web_dispatch
rabbitmq_web_mqtt
Applying plugin configuration to rabbit@localhost...
The following plugins have been enabled:
rabbitmq_web_mqtt
started 1 plugins.参考链接:https://www.rabbitmq.com/docs/web-mqtt#enabling
# rabbitmq-plugins enable rabbitmq_web_mqtt_examples
Enabling plugins on node rabbit@localhost:
rabbitmq_web_mqtt_examples
The following plugins have been configured:
rabbitmq_management
rabbitmq_management_agent
rabbitmq_mqtt
rabbitmq_web_dispatch
rabbitmq_web_mqtt
rabbitmq_web_mqtt_examples
Applying plugin configuration to rabbit@localhost...
The following plugins have been enabled:
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】 我们会及时删除侵权内容,谢谢合作!
页:
[1]