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

CentOS 7上SonarQube服务运行正常但浏览器无法访问求助

CentOS 7 下 SonarQube 服务运行正常但浏览器无法访问的解决思路

问题描述

在CentOS 7系统上运行SonarQube,终端执行systemctl status sonarqube显示服务已正常启动,但浏览器访问http://localhost:9000或http://localhost:9001时无法连接。

服务状态输出:

[root@192 logs]# systemctl status sonarqube
● sonarqube.service - SonarQube service
   Loaded: loaded (/etc/systemd/system/sonarqube.service; enabled; vendor preset: disabled)
   Active: active (running) since ven 2022-10-07 12:48:37 CEST; 3s ago
  Process: 23246 ExecStop=/opt/sonarqube/bin/linux-x86-64/sonar.sh stop (code=exited, status=0/SUCCESS)
  Process: 23275 ExecStart=/opt/sonarqube/bin/linux-x86-64/sonar.sh start (code=exited, status=0/SUCCESS)
 Main PID: 23298 (java)
    Tasks: 43
   CGroup: /system.slice/sonarqube.service
           ├─23298 java -Xms8m -Xmx32m --add-exports=java.base/jdk.internal.ref=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens...
           └─23321 /usr/lib/jvm/java-11-openjdk-11.0.16.1.1-1.el7_9.x86_64/bin/java -XX:+UseG1GC -Djava.io.tmpdir=/opt/sonarqube/temp -XX:ErrorFile...

ott 07 12:48:37 192.168.1.24 systemd[1]: Starting SonarQube service...
ott 07 12:48:37 192.168.1.24 sonar.sh[23275]: /usr/bin/java
ott 07 12:48:37 192.168.1.24 sonar.sh[23275]: Starting SonarQube...
ott 07 12:48:37 192.168.1.24 systemd[1]: Started SonarQube service.

附无法连接截图:显示“无法连接localhost”的页面


排查与解决步骤

  • 确认SonarQube监听端口
    执行ss -tulpn | grep java或netstat -tulpn | grep java,查看SonarQube是否实际绑定了9000/9001端口。服务显示running不代表端口已完成监听,可能还在初始化阶段。
  • 检查SonarQube日志
    进入/opt/sonarqube/logs目录,查看web.log、es.log文件,里面会记录启动过程中的错误,比如Elasticsearch启动失败、端口被占用、文件权限不足等问题。
  • 配置防火墙规则
    CentOS7默认启用firewalld,执行firewall-cmd --list-all检查9000端口是否开放。未开放则执行:
    firewall-cmd --add-port=9000/tcp --permanent
    firewall-cmd --reload
    
  • 调整SELinux设置
    执行getenforce查看SELinux状态,若为Enforcing模式,临时执行setenforce 0测试是否能访问。若恢复正常,需配置SELinux规则或修改SonarQube文件的SELinux上下文,避免后续重启失效。
  • 验证Java版本兼容性
    确认Java版本符合SonarQube要求(8.x及以上版本推荐Java11),执行java -version核对版本信息。
  • 本地测试访问
    在服务器本地执行curl http://localhost:9000,若本地能返回响应但远程浏览器不行,说明是网络或防火墙问题;若本地也无响应,重点排查SonarQube启动日志。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.17 16:35:25