RabbitMQ 安装部署与配置总结
授客 2024-08-19 08:15:00 阅读 53
实践环境
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版本。
安装软件包
<code># 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 status rabbitmq-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[1237]: Doc guides: https://rabbitmq.com/documentation.html
Jul 13 04:02:49 localhost.localdomain rabbitmq-server[1237]: Support: https://rabbitmq.com/contact.html
Jul 13 04:02:49 localhost.localdomain rabbitmq-server[1237]: Tutorials: https://rabbitmq.com/getstarted.html
Jul 13 04:02:49 localhost.localdomain rabbitmq-server[1237]: Monitoring: https://rabbitmq.com/monitoring.html
Jul 13 04:02:49 localhost.localdomain rabbitmq-server[1237]: Logs: /var/log/rabbitmq/rabbit@localhost.log
Jul 13 04:02:49 localhost.localdomain rabbitmq-server[1237]: /var/log/rabbitmq/rabbit@localhost_upgrade.log
Jul 13 04:02:49 localhost.localdomain rabbitmq-server[1237]: <stdout>
Jul 13 04:02:49 localhost.localdomain rabbitmq-server[1237]: Config file(s): (none)
Jul 13 04:02:54 localhost.localdomain rabbitmq-server[1237]: Starting broker... completed with 0 plugins.
Jul 13 04:02:54 localhost.localdomain systemd[1]: 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
配置文件管理
查找配置文件
<code># 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 ...
usertags
testacc[]
guest[administrator]
# 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 [administrator] ...
说明:如果不设置标签,以 testacc 用户登录管理界面时,会提示Not management user
参考连接:
https://www.rabbitmq.com/docs/man/rabbitmqctl.8#set_user_tags
https://www.rabbitmq.com/docs/management#permissions
登录管理界面
开启mqtt相关插件
<code># 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
,出现类似如下页面
声明
本文内容仅代表作者观点,或转载于其他网站,本站不以此文作为商业用途
如有涉及侵权,请联系本站进行删除
转载本站原创文章,请注明来源及作者。