Azure虚拟机中ThingsBoard未监听指定端口求助
问题:Azure Ubuntu 20.04虚拟机中ThingsBoard无法访问,端口8081未监听
我在Azure云的Ubuntu 20.04虚拟机上安装并运行ThingsBoard服务器,按照官方教程操作后,服务看似启动正常,但无法访问。为避免端口冲突,我把端口改成了8081,但问题依旧。
执行curl http://localhost:8081/时收到以下错误:
ahontanb@vm-tfg:~$ curl http://localhost:8081/ curl: (7) Failed to connect to localhost port 8081: Connection refused
查看虚拟机监听端口(执行sudo netstat -a)的输出如下:
ahontanb@vm-tfg:~$ sudo netstat -a Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 localhost:postgresql 0.0.0.0:* LISTEN tcp 0 0 localhost:6010 0.0.0.0:* LISTEN tcp 0 0 localhost:domain 0.0.0.0:* LISTEN tcp 0 0 localhost:postgresql localhost:35046 ESTABLISHED tcp 0 0 localhost:postgresql localhost:35032 ESTABLISHED tcp 0 0 localhost:postgresql localhost:35026 ESTABLISHED tcp 0 0 localhost:postgresql localhost:54638 ESTABLISHED tcp 0 0 localhost:postgresql localhost:55832 ESTABLISHED tcp 0 0 localhost:postgresql localhost:42512 ESTABLISHED tcp 0 0 localhost:postgresql localhost:35052 ESTABLISHED tcp 0 0 localhost:postgresql localhost:55424 ESTABLISHED tcp 0 0 localhost:postgresql localhost:40720 ESTABLISHED tcp6 0 0 ip6-localhost:6010 [::]:* LISTEN tcp6 0 0 [::]:7070 [::]:* LISTEN tcp6 0 0 [::]:1883 [::]:* LISTEN tcp6 0 0 127.0.0.1:35026 127.0.0.1:postgresql ESTABLISHED tcp6 0 0 127.0.0.1:55832 127.0.0.1:postgresql ESTABLISHED tcp6 0 0 127.0.0.1:35032 127.0.0.1:postgresql ESTABLISHED tcp6 0 0 127.0.0.1:35046 127.0.0.1:postgresql ESTABLISHED tcp6 0 0 127.0.0.1:35052 127.0.0.1:postgresql ESTABLISHED tcp6 0 0 127.0.0.1:55424 127.0.0.1:postgresql ESTABLISHED tcp6 0 0 127.0.0.1:40720 127.0.0.1:postgresql ESTABLISHED tcp6 0 0 127.0.0.1:54638 127.0.0.1:postgresql ESTABLISHED tcp6 0 0 127.0.0.1:42512 127.0.0.1:postgresql ESTABLISHED udp 0 0 localhost:323 0.0.0.0:* udp 0 0 localhost:domain 0.0.0.0:* udp 0 0 vm-tfg.internal.:bootpc 0.0.0.0:* udp 0 0 localhost:52982 localhost:52982 ESTABLISHED udp6 0 0 ip6-localhost:323 [::]:* udp6 0 0 [::]:5683 [::]:* raw6 0 0 [::]:ipv6-icmp [::]:* 7
可以看到MQTT的1883端口处于监听状态,但8081端口未出现在监听列表中。
我的thingsboard.conf配置内容如下:
# # Copyright © 2016-2023 The Thingsboard Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # export JAVA_OPTS="$JAVA_OPTS -Dplatform=deb -Dinstall.data_dir=/usr/share/thingsboard/data" export JAVA_OPTS="$JAVA_OPTS -Xlog:gc*,heap*,age*,safepoint=debug:file=/var/log/thingsboard/gc.log:time,uptime,level,tags:filecount=10,filesize=10M" export JAVA_OPTS="$JAVA_OPTS -XX:+IgnoreUnrecognizedVMOptions -XX:+HeapDumpOnOutOfMemoryError" export JAVA_OPTS="$JAVA_OPTS -XX:-UseBiasedLocking -XX:+UseTLAB -XX:+ResizeTLAB -XX:+PerfDisableSharedMem -XX:+UseCondCardMark" export JAVA_OPTS="$JAVA_OPTS -XX:+UseG1GC -XX:MaxGCPauseMillis=500 -XX:+UseStringDeduplication -XX:+ParallelRefProcEnabled -XX:MaxTenuringThreshold=10" export LOG_FILENAME=thingsboard.out export LOADER_PATH=/usr/share/thingsboard/conf,/usr/share/thingsboard/extensions export SQL_DATA_FOLDER=/usr/share/thingsboard/data/sql # DB Configuration export DATABASE_TS_TYPE=sql export SPRING_DATASOURCE_URL=jdbc:postgresql://localhost:5432/thingsboard export SPRING_DATASOURCE_USERNAME=postgres export SPRING_DATASOURCE_PASSWORD=ahbgs2000 # Specify partitioning size for timestamp key-value storage. Allowed values: DAYS, MONTHS, YEARS, INDEFINITE. export SQL_POSTGRES_TS_KV_PARTITIONING=MONTHS # Update ThingsBoard memory usage and restrict it to 256MB in /etc/thingsboard/conf/thingsboard.conf export JAVA_OPTS="$JAVA_OPTS -Xms256M -Xmx256M" export TB_QUEUE_TYPE=in-memory export export HTTP_BIND_PORT=8081
问题排查与解决建议
1. 修复配置文件语法错误
配置最后一行存在重复的export关键字:export export HTTP_BIND_PORT=8081,这会导致系统无法正确识别该环境变量。
修复操作:将该行修改为export HTTP_BIND_PORT=8081,删除多余的export。
2. 重启ThingsBoard服务
修改配置后必须重启服务才能生效,执行命令:
sudo systemctl restart thingsboard
3. 验证服务状态与日志
确认服务是否正常启动:
sudo systemctl status thingsboard
若服务启动失败,查看日志排查具体错误:
cat /var/log/thingsboard/thingsboard.out
或实时查看系统日志:
journalctl -u thingsboard -f
4. 检查端口监听状态
重启服务后,再次验证8081端口是否处于监听状态:
sudo netstat -tulpn | grep 8081
或使用ss命令:
sudo ss -tulpn | grep 8081
5. Azure安全组配置(如需外部访问)
如果需要从虚拟机外部访问8081端口,需在Azure网络安全组(NSG)中添加入站规则,允许TCP 8081端口的流量通过。
内容的提问来源于stack exchange,提问作者Alejandro Hontanilla
相关产品推荐
相关产品推荐

