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

Azure虚拟机中无法通过localhost或公网IP访问ThingsBoard CE UI

ThingsBoard CE 3.6.2 访问超时问题解决思路

环境信息

  • 运行环境:Azure Ubuntu 20.04 虚拟机
  • 实例规格:Standard B2s(2核4GiB内存)
  • 公网IP:静态分配
  • 数据库:Azure PostgreSQL

问题现象

按照官方Ubuntu安装指南完成ThingsBoard CE 3.6.2安装后,通过浏览器访问http://[公网IP]:8080/或http://[公网IP]/均出现连接超时;本地执行curl localhost、curl http://[公网IP]:8080/也无响应。已配置Azure入站规则,开放TCP 22/80/443/1883、UDP 5683端口。

核心问题定位(从日志与配置提取)

安装日志(install.log)

安装流程最后提示Failed to start ThingsBoard application service!,根源是本地PostgreSQL连接被拒绝:

org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.

服务日志(thingsboard.log)

启动时持续抛出数据源初始化失败异常,核心原因仍是本地数据库连接失败:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/thingsboard/server/service/dao/JpaDaoConfiguration.class]: Unsatisfied dependency expressed through method 'entityManagerFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/thingsboard/server/service/dao/JpaDaoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.postgresql.util.PSQLException: Connection to localhost:5432 refused.

配置文件错误

  • thingsboard.conf:已设置DATABASE_TYPE=postgres,但连接参数仍为本地默认值,未指向Azure PostgreSQL:
    export SPRING_DATASOURCE_URL=jdbc:postgresql://localhost:5432/thingsboard
    export SPRING_DATASOURCE_USERNAME=postgres
    export SPRING_DATASOURCE_PASSWORD=postgres
    
  • thingsboard.yml:数据源配置同样未更新为Azure PostgreSQL的真实信息:
    spring:
      datasource:
        url: jdbc:postgresql://localhost:5432/thingsboard
        username: postgres
        password: postgres
    

解决步骤

  1. 修正数据库连接配置

    • 编辑/usr/share/thingsboard/conf/thingsboard.conf,替换为Azure PostgreSQL的真实连接信息:
      export SPRING_DATASOURCE_URL=jdbc:postgresql://<你的Azure Postgres主机名>:5432/thingsboard?sslmode=require
      export SPRING_DATASOURCE_USERNAME=<Azure Postgres管理员用户名>
      export SPRING_DATASOURCE_PASSWORD=<Azure Postgres管理员密码>
      
    • 同步编辑/usr/share/thingsboard/conf/thingsboard.yml的对应配置项:
      spring:
        datasource:
          url: jdbc:postgresql://<你的Azure Postgres主机名>:5432/thingsboard?sslmode=require
          username: <Azure Postgres管理员用户名>
          password: <Azure Postgres管理员密码>
      

    注意:Azure PostgreSQL默认要求SSL连接,需在URL后追加?sslmode=require

  2. 验证数据库连通性

    • 在虚拟机上执行以下命令,确认能正常连接Azure PostgreSQL:
      psql -h <你的Azure Postgres主机名> -U <管理员用户名> -d thingsboard
      
    • 若连接失败,检查Azure PostgreSQL的防火墙规则,确保已添加虚拟机的私网IP到允许列表。
  3. 重启服务并检查状态

    • 重启ThingsBoard服务:
      sudo systemctl restart thingsboard
      
    • 查看服务状态确认启动成功:
      sudo systemctl status thingsboard
      
    • 再次检查/var/log/thingsboard/thingsboard.log,确认无数据库连接错误。
  4. 确认端口监听

    • 执行命令检查8080端口是否被正常监听:
      netstat -tulpn | grep 8080
      
    • 若看到thingsboard进程监听0.0.0.0:8080或:::8080,说明服务已正常启动,此时再尝试通过公网IP访问UI。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.02 13:53:26