在 Raspberry Pi OS Lite 220922 上安装 RabbitMQ
☁分布式应用,必然少不了开源的消息队列 RabbitMQ,所以也是要尝试在树莓派上安装体验一番的。
安装
从软件仓库安装:
sudo apt-get install rabbitmq-server
等待安装完成后,查看其状态:
sudo systemctl status rabbitmq-server
发现其已经启动运行了,并且也加入Systemd中开机自启动了。
但实际上,我们往往需要自定义配置如日志存储目录、数据存储位置,以及必要的用户创建、插件启用等等。
配置
自定义配置
首先创建好必要的目录:
sudo mkdir -p /data/rabbitmq/db
sudo mkdir -p /data/rabbitmq/log
sudo chown -R rabbitmq:rabbitmq /data/rabbitmq
然后编辑 /etc/rabbitmq/rabbitmq-env.conf(如不存在则创建):
# 数据目录
MNESIA_BASE=/data/rabbitmq/db
# 日志目录
LOG_BASE=/data/rabbitmq/log
💡小心:以上的键值对等号两边不能有空格!否则不生效!
最后重启服务:
sudo systemctl restart rabbitmq-server
创建用户
默认创建的用户 guest 只能从本地访问服务,故先创建可远程访问服务的新用户:
pi@raspberrypi:~ $ sudo rabbitmqctl add_user root
Adding user "root" ...
Password:
123456
然后设置 Tags 和权限:
pi@raspberrypi:~ $ sudo rabbitmqctl set_user_tags root administrator
Setting tags for user "root" to [administrator] ...
pi@raspberrypi:~ $ sudo rabbitmqctl list_users
Listing users ...
user tags
guest [administrator]
root [administrator]
pi@raspberrypi:~ $ sudo rabbitmqctl set_permissions root '.*' '.*' '.*'
Setting permissions for user "root" in vhost "/" ...
pi@raspberrypi:~ $ sudo rabbitmqctl list_user_permissions root
Listing permissions for user "root" ...
vhost configure write read
/ .* .* .*
最后删除默认的 guest 用户:
pi@raspberrypi:~ $ sudo rabbitmqctl delete_user guest
Deleting user "guest" ...
pi@raspberrypi:~ $ sudo rabbitmqctl list_users
Listing users ...
user tags
root [administrator]
启用插件
一般来说,为了操作方便,都会启用管理界面(management)插件(端口号 15672
),我还用到了 Web Stomp 插件(端口号 15674
):
pi@raspberrypi:~ $ sudo rabbitmq-plugins enable rabbitmq_management rabbitmq_web_stomp
Enabling plugins on node rabbit@raspberrypi:
rabbitmq_management
rabbitmq_web_stomp
The following plugins have been configured:
rabbitmq_management
rabbitmq_management_agent
rabbitmq_stomp
rabbitmq_web_dispatch
rabbitmq_web_stomp
Applying plugin configuration to rabbit@raspberrypi...
Plugin configuration unchanged.
pi@raspberrypi:~ $ sudo rabbitmq-plugins list
Listing plugins with pattern ".*" ...
Configured: E = explicitly enabled; e = implicitly enabled
| Status: * = running on rabbit@raspberrypi
|/
[ ] rabbitmq_amqp1_0 3.8.9
[ ] rabbitmq_auth_backend_cache 3.8.9
[ ] rabbitmq_auth_backend_http 3.8.9
[ ] rabbitmq_auth_backend_ldap 3.8.9
[ ] rabbitmq_auth_backend_oauth2 3.8.9
[ ] rabbitmq_auth_mechanism_ssl 3.8.9
[ ] rabbitmq_consistent_hash_exchange 3.8.9
[ ] rabbitmq_event_exchange 3.8.9
[ ] rabbitmq_federation 3.8.9
[ ] rabbitmq_federation_management 3.8.9
[ ] rabbitmq_jms_topic_exchange 3.8.9
[E*] rabbitmq_management 3.8.9
[e*] rabbitmq_management_agent 3.8.9
[ ] rabbitmq_mqtt 3.8.9
[ ] rabbitmq_peer_discovery_aws 3.8.9
[ ] rabbitmq_peer_discovery_common 3.8.9
[ ] rabbitmq_peer_discovery_consul 3.8.9
[ ] rabbitmq_peer_discovery_etcd 3.8.9
[ ] rabbitmq_peer_discovery_k8s 3.8.9
[ ] rabbitmq_prometheus 3.8.9
[ ] rabbitmq_random_exchange 3.8.9
[ ] rabbitmq_recent_history_exchange 3.8.9
[ ] rabbitmq_sharding 3.8.9
[ ] rabbitmq_shovel 3.8.9
[ ] rabbitmq_shovel_management 3.8.9
[e*] rabbitmq_stomp 3.8.9
[ ] rabbitmq_top 3.8.9
[ ] rabbitmq_tracing 3.8.9
[ ] rabbitmq_trust_store 3.8.9
[e*] rabbitmq_web_dispatch 3.8.9
[ ] rabbitmq_web_mqtt 3.8.9
[ ] rabbitmq_web_mqtt_examples 3.8.9
[E*] rabbitmq_web_stomp 3.8.9
[ ] rabbitmq_web_stomp_examples 3.8.9