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

Ubuntu14下SonarQube6.7.1服务正常但WebUI无法启动求助

SonarQube WebUI无法访问(localhost解析失败)问题排查与解决

环境信息

  • Ubuntu 14
  • SonarQube 6.7.1
  • PostgreSQL 9.5
  • Java(TM) SE Runtime Environment (build 1.8.0_144-b01)

问题现象

SonarQube服务显示处于活跃状态,但WebUI无法正常访问;核心报错为 java.net.UnknownHostException: localhost,说明Sonar进程无法解析localhost,进而无法连接后端PostgreSQL数据库。

关键日志详情

web.log 错误片段

ERROR web[][o.postgresql.Driver] 连接错误:org.postgresql.util.PSQLException: 连接尝试失败。
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:275)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:194)
at org.postgresql.Driver.makeConnection(Driver.java:450)
at org.postgresql.Driver.connect(Driver.java:252)
at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
at org.apache.commons.pool.impl.GenericObjectPool.addObject(GenericObjectPool.java:1617)
at org.apache.commons.pool.impl.GenericObjectPool.ensureMinIdle(GenericObjectPool.java:1575)
at org.apache.commons.pool.impl.GenericObjectPool.access$700(GenericObjectPool.java:190)
at org.apache.commons.pool.impl.GenericObjectPool$Evictor.run(GenericObjectPool.java:1709)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
Caused by: java.net.UnknownHostException: localhost
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at org.postgresql.core.PGStream.<init>(PGStream.java:68)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:144)

sonar.log 关键片段

2018.01.31 16:37:21 INFO app[][o.s.a.AppFileSystem] 清理或创建临时目录 /opt/sonarqube-6.7.1/temp
2018.01.31 16:37:21 INFO app[][o.s.a.es.EsSettings] Elasticsearch 监听地址 /127.0.0.1:9001
2018.01.31 16:37:21 INFO app[][o.s.a.p.ProcessLauncherImpl] 从[/opt/sonarqube-6.7.1/elasticsearch]启动进程[[key='es', ipcIndex=1, logFilenamePrefix=es]]:/opt/sonarqube-6.7.1/elasticsearch/bin/elasticsearch -Epath.conf=/opt/sonarqube-6.7.1/temp/conf/es
2018.01.31 16:37:21 INFO app[][o.s.a.SchedulerImpl] 等待Elasticsearch启动并运行
2018.01.31 16:37:21 INFO app[][o.e.p.PluginsService] 未加载任何模块
2018.01.31 16:37:21 INFO app[][o.e.p.PluginsService] 已加载插件[org.elasticsearch.transport.Netty4Plugin]
2018.01.31 16:37:35 INFO app[][o.s.a.SchedulerImpl] 进程[es]已启动
2018.01.31 16:37:35 INFO app[][o.s.a.p.ProcessLauncherImpl] 从[/opt/sonarqube-6.7.1]启动进程[[key='web', ipcIndex=2, logFilenamePrefix=web]]:/usr/lib/jvm/jdk1.8.0_144/jre/bin/java -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djava.io.tmpdir=/opt/sonarqube-6.7.1/temp -Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError -Dhttp.proxyHost= -Dhttp.proxyPort= -Dhttp.auth.ntlm.domain= -DsocksProxyHost= -DsocksProxyPort= -Dhttps.proxyHost= -Dhttps.proxyPort= -cp ./lib/common/*:./lib/server/*:/opt/sonarqube-6.7.1/lib/jdbc/postgresql/postgresql-42.1.4.jar org.sonar.server.app.WebServer /opt/sonarqube-6.7.1/temp/sq-process3048603911980736431properties
2018.01.31 16:40:27 INFO app[][o.s.a.SchedulerImpl] 进程[web]已停止
2018.01.31 16:40:27 INFO app[][o.s.a.SchedulerImpl] 进程[es]已停止
2018.01.31 16:40:27 INFO app[][o.s.a.SchedulerImpl] SonarQube已停止
2018.01.31 16:40:27 WARN app[][o.s.a.p.AbstractProcessMonitor] 进程退出,退出值[es]:143

Sonar.properties 核心配置

sonar.jdbc.username=sonarqube
sonar.jdbc.password=sonarqube
sonar.jdbc.url=jdbc:postgresql://localhost/sonar
sonar.web.host=0.0.0.0
sonar.web.port=9000

解决方案

1. 修复localhost的DNS解析

这个问题的根源是系统无法将localhost解析到回环地址127.0.0.1,需要修正/etc/hosts文件:

  • 打开hosts文件:
    sudo nano /etc/hosts
    
  • 确保文件中包含以下两行(如果没有就添加):
    127.0.0.1   localhost
    ::1         localhost ip6-localhost ip6-loopback
    
  • 保存退出后,测试解析是否正常:
    ping localhost
    
    确认能收到来自127.0.0.1的响应。

2. 验证PostgreSQL连接可用性

确认数据库本身能通过localhost正常访问:

  • 使用Sonar配置的账号连接PostgreSQL:
    psql -U sonarqube -d sonar -h localhost
    
    如果能成功进入数据库命令行,说明数据库服务正常且允许localhost连接;如果连接失败,需要检查PostgreSQL的pg_hba.conf文件,确保允许sonarqube用户从localhost访问,同时确认PostgreSQL服务处于运行状态。

3. 重启SonarQube服务

修复解析问题后,重启Sonar服务:

sudo service sonarqube restart

等待2-3分钟后,尝试访问WebUI(http://你的服务器IP:9000),同时可以实时查看日志确认是否解决了连接问题:

tail -f /opt/sonarqube-6.7.1/logs/web.log

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 06:41:51