【IoT平台】thingsboard v3.6.2编译过程记录
文章目录
- 一、背景介绍
- 二、获取源码
- 三、编译源码
- 四、启动系统
- 五、总结
一、背景介绍
近期公司希望快速搭建一个IoT平台,用于即将给客户带来的演示demo,以及未来基础IoT平台的搭建。既然是为未来考虑,那肯定不能随便写一个,工作不能白做,那么找个靠得住的开源IoT平台是首选。经大佬推荐最终选择了thingsboard,支持协议多,文档齐全。
平台架构如下:
本身设计能够应对高并发场景,也是基于spring的微服务架构,可以放心使用。
官网地址:https://thingsboard.io/
二、获取源码
如果有VPN可以从github直接获取,地址:https://github.com/thingsboard/thingsboard
也可以从gitee的镜像仓获取,地址:https://gitee.com/mirrors/ThingsBoard
我使用的版本是v3.6.2,因为maven主仓的包版本最新只有v3.6.2,太新的版本会出现拉不到包的问题
cd d:/development/workSpace git clone https://gitee.com/mirrors/ThingsBoard.git git checkout -b dev3.6.2 tags/v3.6.2
三、编译源码
推荐使用maven命令行拉取包并完成编译,我试过eclipse、idea都会遇到莫名其妙的包获取不到或者版本不对的问题。经过多次尝试,最终使用maven命令行编译通过。
1.编译环境
jdk使用jdk11,从v3.2.2之后就切到11了
maven使用v3.9.6,请从管网下载安装https://maven.apache.org/download.cgi,不推荐使用eclipse或idea内置的maven
配置maven环境变量,将D:\apache-maven-3.9.6\bin加入到windows path环境变量即可。
验证maven安装情况
mvn -v Maven home: D:\tools\apache-maven-3.9.6 Java version: 11.0.23, vendor: Eclipse Adoptium, runtime: D:\development\jvm\windows\jdk-11.0.23+9 Default locale: zh_CN, platform encoding: GBK OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
安装node、yarn
可以在ThingsBoard\msa\web-ui\pom.xml文件搜素yarn关键词找到编译依赖的node、yarn版本
v3.6.2对应的版本是node v16.20.2、yarn 1.22.17
2.修改maven配置文件,设置本地仓库路径,增加阿里镜像仓库
修改maven配置文件,\apache-maven-3.9.6\conf\settings.xml
D:/development/m3/repository nexus-aliyun central Nexus aliyun https://maven.aliyun.com/repository/public
3.执行编译
cd d:\development\workSpace\ThingsBoard mvn clean install -DskipTests -X
-DskipTests是跳过测试用例,这样能够缩短编译时间
-X是编译时输出详细日志便于排查问题
上述命令执行后,mvn会按照pom.xml的依赖关系从仓库获取jar包,可能遇到的问题如下:
(1) Web UI编译失败
[INFO] ThingsBoard Docker Images .......................... SUCCESS [ 0.519 s] [INFO] ThingsBoard Web UI Microservice .................... FAILURE [ 9.116 s] [INFO] ThingsBoard Version Control Executor ............... SKIPPED [ERROR] Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:3.2.0:clean (default-clean) on project web-ui: Failed to clean project: Failed to delete D:\development\idea-space\ThingsBoard\msa\web-ui\target\node\node.exe -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:3.2.0:clean (default-clean) on project web-ui: Failed to clean project: Failed to delete D:\development\idea-space\ThingsBoard\msa\web-ui\target\node\node.exe at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:333) at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174) at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
杀掉node.exe进程后重试
(2) yarn run pkg报错,编译失败
[ERROR] Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.12.0:yarn (yarn pkg) on project web-ui: Failed to run task: "yarn run pkg" failed. org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1) -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.12.0:yarn (yarn pkg) on project web-ui: Failed to run task
web-ui前端工程依赖angluar,但是angluar依赖的js包没有拉下来导致报错
解决方法:
进入ThingsBoard\msa\web-ui,删除target、node_modules文件夹,配置node、yarn从阿里镜像站获取依赖包,重新编译
执行全量编译会消耗很长的时间,可以通过命令指定编译某一个模块
mvn clean install -rf :web-ui
编程成功,信息如下:
[INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary for Thingsboard 3.6.2: [INFO] [INFO] Thingsboard ........................................ SUCCESS [ 21.583 s] [INFO] Thingsboard Server Commons ......................... SUCCESS [ 0.436 s] [INFO] Thingsboard Server Common Data ..................... SUCCESS [ 15.793 s] [INFO] Thingsboard Server Common Utils .................... SUCCESS [ 2.025 s] [INFO] Netty MQTT Client .................................. SUCCESS [ 3.655 s] [INFO] Thingsboard Server Common Messages ................. SUCCESS [ 6.493 s] [INFO] Thingsboard Actor system ........................... SUCCESS [ 1.412 s] [INFO] Thingsboard Server Stats ........................... SUCCESS [ 0.783 s] [INFO] Thingsboard Server Common Protobuf and gRPC structures SUCCESS [ 17.350 s] [INFO] Thingsboard Server Common Cluster API .............. SUCCESS [ 1.097 s] [INFO] Thingsboard Server Queue components ................ SUCCESS [ 8.138 s] [INFO] Thingsboard Server Common Cache .................... SUCCESS [ 1.730 s] [INFO] Thingsboard Server Commons ......................... SUCCESS [ 0.154 s] [INFO] Thingsboard Server Common Transport components ..... SUCCESS [ 2.302 s] [INFO] Thingsboard MQTT Transport Common .................. SUCCESS [ 7.782 s] [INFO] Thingsboard HTTP Transport Common .................. SUCCESS [ 1.339 s] [INFO] Thingsboard CoAP server ............................ SUCCESS [ 1.346 s] [INFO] Thingsboard CoAP Transport Common .................. SUCCESS [ 6.041 s] [INFO] Thingsboard LwM2M Transport Common ................. SUCCESS [ 5.353 s] [INFO] Thingsboard SNMP Transport Common .................. SUCCESS [ 2.510 s] [INFO] Thingsboard Server Common DAO API .................. SUCCESS [ 2.105 s] [INFO] Thingsboard Server Remote Edge wrapper ............. SUCCESS [ 9.731 s] [INFO] Thingsboard Server Version Control API ............. SUCCESS [ 1.974 s] [INFO] Thingsboard Script Invoke Commons .................. SUCCESS [ 0.044 s] [INFO] Thingsboard Server Script invoke API ............... SUCCESS [ 2.134 s] [INFO] Thingsboard Extensions ............................. SUCCESS [ 0.159 s] [INFO] Thingsboard Rule Engine API ........................ SUCCESS [ 2.214 s] [INFO] Thingsboard Server JS Client for remote JS execution SUCCESS [ 1.123 s] [INFO] Thingsboard Server DAO Layer ....................... SUCCESS [ 13.035 s] [INFO] Thingsboard Rule Engine Components ................. SUCCESS [ 9.141 s] [INFO] Thingsboard Server Transport Modules ............... SUCCESS [ 0.072 s] [INFO] Thingsboard HTTP Transport Service ................. SUCCESS [ 31.316 s] [INFO] Thingsboard MQTT Transport Service ................. SUCCESS [ 21.042 s] [INFO] Thingsboard CoAP Transport Service ................. SUCCESS [ 19.931 s] [INFO] Thingsboard LwM2m Transport Service ................ SUCCESS [ 21.451 s] [INFO] Thingsboard SNMP Transport Service ................. SUCCESS [ 20.368 s] [INFO] ThingsBoard Server UI .............................. SUCCESS [03:25 min] [INFO] Thingsboard Server Tools ........................... SUCCESS [ 1.073 s] [INFO] Thingsboard Rest Client ............................ SUCCESS [ 1.202 s] [INFO] ThingsBoard Server Application ..................... SUCCESS [01:05 min] [INFO] ThingsBoard Microservices .......................... SUCCESS [ 4.254 s] [INFO] ThingsBoard Docker Images .......................... SUCCESS [ 1.119 s] [INFO] ThingsBoard Web UI Microservice .................... SUCCESS [ 59.959 s] [INFO] ThingsBoard Version Control Executor ............... SUCCESS [ 20.290 s] [INFO] ThingsBoard Version Control Executor Microservice .. SUCCESS [ 0.116 s] [INFO] ThingsBoard Node Microservice ...................... SUCCESS [ 0.178 s] [INFO] ThingsBoard Transport Microservices ................ SUCCESS [ 0.024 s] [INFO] ThingsBoard MQTT Transport Microservice ............ SUCCESS [ 0.221 s] [INFO] ThingsBoard HTTP Transport Microservice ............ SUCCESS [ 0.338 s] [INFO] ThingsBoard COAP Transport Microservice ............ SUCCESS [ 0.171 s] [INFO] ThingsBoard LWM2M Transport Microservice ........... SUCCESS [ 0.271 s] [INFO] ThingsBoard SNMP Transport Microservice ............ SUCCESS [ 0.157 s] [INFO] ThingsBoard JavaScript Executor Microservice ....... SUCCESS [01:11 min] [INFO] ThingsBoard Monitoring Service ..................... SUCCESS [ 9.981 s] [INFO] ThingsBoard Monitoring Microservice ................ SUCCESS [ 0.087 s] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 11:46 min [INFO] Finished at: 2024-05-21T11:14:20+08:00 [INFO] ------------------------------------------------------------------------
四、启动系统
1.系统启动依赖PostgreSQL数据库,启动前先安装好
2.创建thingsboard数据库
3.配置ThingsBoard\application\src\main\resources\thingsboard.yml里面的数据库用户名和密码
datasource: # Database driver for Spring JPA - org.postgresql.Driver driverClassName: "${SPRING_DRIVER_CLASS_NAME:org.postgresql.Driver}" # Database connection URL url: "${SPRING_DATASOURCE_URL:jdbc:postgresql://localhost:5432/thingsboard}" # Database user name username: "${SPRING_DATASOURCE_USERNAME:postgres}" # Database user password password: "${SPRING_DATASOURCE_PASSWORD:yourpassword}"
4.将ThingsBoard\dao\src\main\resources\sql文件夹复制到ThingsBoard\application\src\main\data
5.启动ThingsBoard\application\src\main\java\org\thingsboard\server\ThingsboardInstallApplication.java
执行成功过后会自动创建数据库表
6.打开http://127.0.0.1:8080,输入账号密码进入系统
默认账号密码:
System Administrator(系统管理员): sysadmin@thingsboard.org / sysadmin
Tenant Administrator(租户管理员): tenant@thingsboard.org / tenant
Customer User(客户用户): customer@thingsboard.org / customer
系统界面如下:
五、总结
thingsboard编译其实并不难,容易出现问题的地方在于,大家习惯IDE的自动化功能,会出现许多莫名其妙的依赖包问题,要会设置依赖包的国内镜像站。编译报错不要慌,多看报错提示就会发现大部分问题都是依赖包、编译环境或者版本不匹配问题,细心一点相信大家都能自行排查解决。