You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CentOS 7配置SonarQube9.1开机自启报Elasticsearch文件描述符不足错误

问题原因

SonarQube内置的Elasticsearch要求进程最大文件描述符至少为65535。你手动用opencm用户执行sonar.sh start可以正常启动,是因为opencm用户的系统资源阈值已经配置到位,但systemd管理的服务默认不会读取/etc/security/limits.conf的配置,使用systemd默认的4096阈值,因此触发启动报错。

解决步骤

步骤1:修改sonar.service配置文件

编辑/etc/systemd/system/sonar.service,在[Service]配置段新增资源限制参数,修改后的完整[Service]段如下:

[Service]
Type=forking
ExecStart=/home/opencm/sonarqube-9.1.0.47736/bin/linux-x86-64/sonar.sh start
ExecReload=/home/opencm/sonarqube-9.1.0.47736/bin/linux-x86-64/sonar.sh restart
ExecStop=/home/opencm/sonarqube-9.1.0.47736/bin/linux-x86-64/sonar.sh stop

Restart=on-failure
RestartSec=10

User=opencm
Group=opencm

# 新增Elasticsearch要求的资源限制配置
LimitNOFILE=65535
LimitNPROC=4096

步骤2:重载systemd配置

执行命令重新加载systemd单元配置,让修改的服务参数生效:

systemctl daemon-reload

步骤3:重启服务验证

执行命令重启SonarQube服务:

systemctl restart sonar.service

步骤4:确认配置生效

执行以下命令查看进程的文件描述符限制,确认参数已生效:

cat /proc/$(pgrep -f sonarqube)/limits | grep 'Max open files'

如果返回结果中软限制和硬限制都为65535,说明配置生效,后续服务器重启后SonarQube即可正常自启。

可选补充配置(保障手动启动正常)

如果需要保证opencm用户手动执行sonar.sh启动服务也正常,可编辑/etc/security/limits.conf新增以下配置:

opencm soft nofile 65535
opencm hard nofile 65535
opencm soft nproc 4096
opencm hard nproc 4096

保存退出后重新登录opencm用户即可生效。

内容的提问来源于stack exchange,提问作者Alexei

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 04:15:03