Install
Install Erlang
https://www.rabbitmq.com/docs/install-rpm
erlang 首先有2个依赖包:socat 和 logrotate
rabbitmq-server 有1个依赖包:erlang
也就是说,会涉及到4个安装包:
- socat
- logrotate
- erlang
- rabbitmq-server
dnf install -y socat logrotate
erlang安装包的下载地址如下:
https://github.com/rabbitmq/erlang-rpm/releases
# dnf install erlang-26.2.5.2-1.el9.x86_64.rpm
dnf install erlang-26.2.5-1.el8.x86_64.rpm
rabbitmq-server安装包的下载地址如下:
dnf install rabbitmq-server-3.13.7-1.el8.noarch.rpm
dnf安装指定版本的socat 和 logrotate
dnf search socat
# 查询socat多个版本的安装包
dnf --showduplicates list socat
socat.x86_64 1.7.4.1-5.el9 appstream
socat.x86_64 1.7.4.1-6.el9 appstream
# 安装socat
dnf install socat-1.7.4.1-6.el9
# 查询已安装的软件包版本
[root@VM-0-13-centos yum.repos.d]# rpm -q socat
socat-1.7.4.1-6.el9.x86_64
# -----------------------------------------------------
dnf search logrotate
dnf --showduplicates list logrotate
# 安装 logrotate
dnf install logrotate-3.18.0-8.el9
Run RabbitMQ Server
Start the Server
The server is not started as a daemon by default when the RabbitMQ server package is installed. To start the daemon by default when the system boots, as an administrator run
systemctl enable rabbitmq-server
As an administrator, start and stop the server as usual, e.g. using systemctl
:
systemctl start rabbitmq-server
systemctl status rabbitmq-server
systemctl stop rabbitmq-server
相关端口
firewall-cmd --state
systemctl start firewalld.service
firewall-cmd --add-port=4369/tcp --permanent
firewall-cmd --add-port=5672/tcp --permanent
firewall-cmd --add-port=15672/tcp --permanent
firewall-cmd --add-port=25672/tcp --permanent
firewall-cmd --add-port=1883/tcp --permanent
firewall-cmd --reload
# 合起来
firewall-cmd --add-port=4369/tcp --add-port=5672/tcp --add-port=15672/tcp --add-port=25672/tcp --add-port=1883/tcp --permanent
firewall-cmd --reload
Authentication, Authorisation, Access Control
rabbitmqctl add_user user-weipeng passwd-weipeng
rabbitmqctl set_permissions -p / user-weipeng ".*" ".*" ".*"
rabbitmqctl set_user_tags user-weipeng administrator
创建Virtual host(可选)
# 创建vhost并授权给指定用户
rabbitmqctl add_vhost xuyi-dev
rabbitmqctl set_permissions -p xuyi-dev weipeng ".*" ".*" ".*"
插件
rabbitmq-plugins enable rabbitmq_management
rabbitmq-plugins enable rabbitmq_mqtt
Enable Feature Flag
在15672的management ui上,启用相关的stable feature
(可以不做,最好不做)Controlling System Limits on Linux
RabbitMQ installations running production workloads may need system limits and kernel parameters tuning in order to handle a decent number of concurrent connections and queues. The main setting that needs adjustment is the max number of open files, also known as ulimit -n
. The default value on many operating systems is too low for a messaging broker (1024
on several Linux distributions). We recommend allowing for at least 65536 file descriptors for user rabbitmq
in production environments. 4096 should be sufficient for many development workloads.
There are two limits in play: the maximum number of open files the OS kernel allows (fs.file-max
) and the per-user limit (ulimit -n
). The former must be higher than the latter.
With systemd (Recent Linux Distributions)
On distributions that use systemd, the OS limits are controlled via a configuration file at /etc/systemd/system/rabbitmq-server.service.d/limits.conf
. For example, to set the max open file handle limit (nofile
) to 64000
:
[Service]
LimitNOFILE=64000
If LimitNOFILE
is set to a value higher than 65536, the ERL_MAX_PORTS
environment variable must be updated accordingly to increase a runtime limit.
See systemd documentation to learn about the supported limits and other directives.
Verifying the Limit
RabbitMQ management UI displays the number of file descriptors available for it to use on the Overview tab.
rabbitmq-diagnostics status
includes the same value.
The following command
cat /proc/$RABBITMQ_BEAM_PROCESS_PID/limits
can be used to display effective limits of a running process. $RABBITMQ_BEAM_PROCESS_PID
is the OS PID of the Erlang VM running RabbitMQ, as returned by rabbitmq-diagnostics status
.
我们在/etc/systemd/system/multi-user.target.wants/rabbitmq-server.service
,能看到以下内容
vim /etc/systemd/system/multi-user.target.wants/rabbitmq-server.service
# To override LimitNOFILE, create the following file:
#
# /etc/systemd/system/rabbitmq-server.service.d/limits.conf
#
# with the following content:
#
# [Service]
# LimitNOFILE=65536
LimitNOFILE=32768
也就是说,当我们在执行systemctl start rabbitmq-server
时,就已经指定了LimitNOFILE为32768
Feature Flags
https://www.rabbitmq.com/docs/3.13/feature-flags
rabbitmq_rabbitmq_mqtt Feature Flags
The following feature flags are provided by plugin rabbimq_mqtt.
Required | Stable | Feature flag name | Description |
---|---|---|---|
3.13.0 | mqtt_v5 | Support MQTT 5.0 | |
3.12.0 | delete_ra_cluster_mqtt_node | Delete Ra cluster mqtt_node since MQTT client IDs are tracked locally | |
3.12.0 | rabbit_mqtt_qos0_queue | Support pseudo queue type for MQTT QoS 0 subscribers omitting a queue process |
相关配置文件
rabbitmq-env.conf
https://www.rabbitmq.com/docs/3.13/man/rabbitmq-env.conf.5
https://github.com/rabbitmq/rabbitmq-server/blob/main/deps/rabbit/docs/rabbitmq-env.conf.5
配置日志和数据存放路径
1.先创建目录,并给权限
mkdir -p /mnt/sdc/rabbitmq/mnesia
mkdir -p /mnt/sdc/rabbitmq/log
# 配置读写权限
chmod -R 777 /mnt/sdc/rabbitmq
# 更改所属用户和用户组
chown -R rabbitmq:rabbitmq /mnt/sdc/rabbitmq
创建/etc/rabbitmq/rabbitmq-env.conf
2.在配置文件/etc/rabbitmq/rabbitmq-env.conf
中,新增以下配置:
vim /etc/rabbitmq/rabbitmq-env.conf
RABBITMQ_MNESIA_BASE=/mnt/sdc/rabbitmq/mnesia
RABBITMQ_LOG_BASE=/mnt/sdc/rabbitmq/log
rabbitmq.conf
样例文件:
https://github.com/rabbitmq/rabbitmq-server/blob/main/deps/rabbit/docs/rabbitmq.conf.example
关于mqtt的相关配置:
cd /etc/rabbitmq/
vim rabbitmq.conf
配置文件如下:
# 7 days
mqtt.max_session_expiry_interval_seconds = 604800
# governing the maximum number of unacknowledged messages that will be delivered
mqtt.prefetch = 10
## use DETS (disk-based) store for retained messages
mqtt.retained_message_store = rabbit_mqtt_retained_msg_store_dets
## only used by DETS store (in milliseconds)
mqtt.retained_message_store_dets_sync_interval = 2000
重启node
rabbitmqctl shutdown
systemctl status rabbitmq-server
systemctl start rabbitmq-server
# 查看上面的配置,是否生效,执行下面2个命令
rabbitmq-diagnostics status
rabbitmq-diagnostics environment
mqtt.subscription_ttl (in milliseconds) configuration setting was replaced with mqtt.max_session_expiry_interval_seconds (in seconds).
A 3.13 RabbitMQ node will fail to boot if the old configuration setting is set.
For example, if you set mqtt.subscription_ttl = 3600000 (1 hour) prior to 3.13, replace that setting with mqtt.max_session_expiry_interval_seconds = 3600 (1 hour) in 3.13.