大佬们,开源版emqx老是自动重启

环境

  • EMQX 版本:5.7.2
  • 操作系统版本:ubuntu 20
    2026-03-08T17:53:43.513235+08:00 [error] Process: <0.45048.0> on node ‘emqx@127.0.0.1’, Context: maximum heap size reached, Max Heap Size: 6291456, Total Heap Size: 21182868, Kill: true, Error Logger: true, Message Queue Len: 5, GC Info: [{old_heap_block_size,2586},{heap_block_size,10695961},{mbuf_size,10484367},{recent_size,86},{stack_size,18},{old_heap_size,944},{heap_size,564},{bin_vheap_size,326},{bin_vheap_block_size,79467343},{bin_old_vheap_size,0},{bin_old_vheap_block_size,79467343}]

重现此问题的步骤

  1. xxx
  2. xxx
  3. xxx

预期行为

实际行为

这是进程堆内存超限被强制杀掉,不是随机重启。日志里的 Context: maximum heap size reached + Kill: true 就是这个信号。
先确认到底是“进程被杀”还是“整个节点重启”:

grep -Ei "maximum heap size reached|proc_heap_too_large|connection_shutdown|BOOT|stopped|SIGTERM" data/log/emqx.log* | tail -n 200
emqx ctl broker

如果 uptime 没重置,通常是某个连接/规则相关进程反复超限被杀。
你这个日志里 Max Heap Size: 6291456(约 6MB),先把 force_shutdown 和 zone 覆盖配置查出来:

emqx ctl conf show force_shutdown
emqx ctl conf show zones

重点看 max_heap_sizemax_mailbox_size
另外把系统层面的 OOM 也排除掉:

dmesg -T | grep -Ei "oom|out of memory|killed process" | tail -n 100

如果是 Docker/K8s:

docker inspect <emqx_container> --format '{{.State.RestartCount}} {{.State.OOMKilled}}'

配置了最大内存不生效erlang.system_flags.max_heap_size = 268435456 # 256MB,单位字节

你这个配置项写错路径了。Context: maximum heap size reached 走的是 force_shutdown.max_heap_size,不是 erlang.system_flags.max_heap_size
你日志里 Max Heap Size: 6291456(6MB)也说明当前生效阈值仍然很小。
先把当前生效值查出来:

emqx ctl conf show force_shutdown
emqx ctl conf show zones
emqx ctl conf show listeners

重点看监听器绑定的 zone(通常是 external)里有没有覆盖:zones.<zone>.force_shutdown.max_heap_size
修配置用这两条(单位用 "256MB" 这种 Bytesize 字符串):

force_shutdown.max_heap_size = "256MB"
zones.external.force_shutdown.max_heap_size = "256MB"

改完重启 EMQX,再确认:

emqx ctl conf show force_shutdown
emqx ctl conf show zones | grep -n "max_heap_size"

emqx ctl conf show force_shutdown 这个命令是在bin目录下面执行吗?我执行了这个emqx ctl conf validate也报错

conf validate 报错是正常的,5.7.2 没有这个子命令;校验配置文件用 emqx check_config
emqx ctl conf show force_shutdown 要在“运行中的 EMQX 节点环境”里执行,不是必须在 bin/ 目录,但命令路径要对。

  • tar/zip 安装:./bin/emqx ctl conf show force_shutdown
  • DEB/RPM 安装:emqx ctl conf show force_shutdown
  • Docker:docker exec -it <容器名> emqx ctl conf show force_shutdown
    再把这几个输出贴一下,先确认生效值和是否有 zone 覆盖:
emqx ctl conf show force_shutdown
emqx ctl conf show zones
emqx ctl conf show listeners
,

erlang.system_flags.max_heap_size = 268435456 # 256MB,单位字节
erlang.system_flags.kill = false # 内存超限不杀进程
这两个配置是什么意思?

max_heap_size设置什么值是最好的,64MB,128MB,还是256MB,设置这个值要根据什么因素来考虑

Process Max Heap Size 已设置了较大值,但没有生效的原因是什么呢? - EMQX - EMQ 问答社区

emqx单节点连接了大概200多台设备,每秒有近10000条数据要及时处理,force_shutdown.max_message_queue_len = 1000会不会太少了,最佳配置是多少呢?包括max_heap_size,今天服务器更新了配置,不知道是否可行默认32MB改成了256,但我么的message_queue_len设置的值太少了,有可能造成数据丢失。

erlang.system_flags.max_heap_size = 268435456
erlang.system_flags.kill = true

zones.external.force_shutdown.max_heap_size = “256MB”

force_shutdown {
enable = true
max_heap_size = “256MB”
max_message_queue_len = 1000
}

node {
process_limit = 2097152
max_ports = 1048576
}
这是今天更新的配置,请帮忙看下

保持默认就好了。你这个流量如果是持续的,这个值改得再大,迟早都会挂 。
改用共享订阅吧: