SonarQube 10.5启动后意外停止,Elasticsearch异常退出求助
环境配置
- SonarQube 10.5(ZIP包部署,非Docker)
- Java 17(已确认符合版本要求)
- PostgreSQL 15(已创建数据库、schema及对应用户,
sonar.properties中已配置数据库连接信息)
问题现象
SonarQube启动后莫名停止,已尝试查阅官方文档、YouTube教程及AI工具,问题仍未解决。
相关日志信息
WARNING: A terminally deprecated method in java.lang.System has been called
WARNING: System::setSecurityManager has been called by org.sonar.process.PluginSecurityManager (file:/D:/Kodingan/sonarqube-10.5.0.89998/lib/sonar-application-10.5.0.89998.jar)
WARNING: Please consider reporting this to the maintainers of org.sonar.process.PluginSecurityManager
WARNING: System::setSecurityManager will be removed in a future release
ERROR: Elasticsearch did not exit normally - check the logs at D:\Kodingan\sonarqube-10.5.0.89998\logs\sonarqube.log
ERROR: Elasticsearch exited unexpectedly, with exit code 1
2024.05.07 22:04:46 WARN app[][o.s.a.p.AbstractManagedProcess] Process exited with exit value [ElasticSearch]: 1
2024.05.07 22:04:46 INFO app[][o.s.a.SchedulerImpl] Process[ElasticSearch] is stopped
2024.05.07 22:04:48 INFO app[][o.s.a.SchedulerImpl] Process[Web Server] is stopped
2024.05.07 22:04:48 INFO app[][o.s.a.SchedulerImpl] SonarQube is stopped
排查与解决方案
从日志核心报错来看,问题根源是Elasticsearch异常退出(exit code 1),以下是针对性排查步骤:
1. 查看Elasticsearch详细日志
优先检查D:\Kodingan\sonarqube-10.5.0.89998\logs\sonarqube.log中Elasticsearch启动阶段的具体报错,常见触发原因包括:
- 内存分配不足:修改
conf\sonar.properties中的sonar.search.javaOpts参数,例如调整为-Xms2g -Xmx2g(根据服务器内存调整,建议至少分配2GB) - 文件权限缺失:确保SonarQube运行用户对
data、logs目录拥有读写权限 - 端口冲突:Elasticsearch默认占用9001端口,可通过
netstat -ano | findstr :9001(Windows)或lsof -i :9001(Linux)检查端口是否被占用
2. 禁用SecurityManager
日志中的SecurityManager警告虽为deprecated方法调用,但部分Java 17环境可能对该调用敏感,可尝试在conf\sonar.properties中添加配置:
sonar.securitymanager.disable=true
添加后重启SonarQube,观察是否解决问题
3. 验证PostgreSQL连接配置
再次确认sonar.properties中的数据库配置准确性:
sonar.jdbc.username=你的数据库用户 sonar.jdbc.password=你的数据库密码 sonar.jdbc.url=jdbc:postgresql://localhost:5432/sonarqube?currentSchema=你的schema名称
同时确保PostgreSQL服务正常运行,且该数据库用户拥有对应schema的读写权限,可通过psql工具直接测试连接
4. 确认Java环境兼容性
确保使用的Java 17是官方支持的标准发行版(如OpenJDK),执行java -version验证版本信息,避免使用非标准Java发行版
5. 清理Elasticsearch缓存
删除data\es7目录下的缓存文件,然后重新启动SonarQube,避免旧缓存导致启动异常
内容的提问来源于stack exchange,提问作者Shidqi

