ThingsBoard 学习笔记 之 编译

系列文章目录

ThingsBoard 学习笔记 之 编译


前言

之前在做项目的时候简单使用了 官方的 ThingsBoard Community Edition docker 镜像搭建了私有化的物联网测试平台,随着项目的进展,有可能需要继续做些二次开发的尝试,这样就需要从代码开始了。因此,写这篇文章用来记录相关过程、困难和要点。

ThingsBoard 的网站有两个:http://www.ithingsboard.com/ 和 https://thingsboard.io/ ,第一个是中文网站第二个是英文的,但不清楚这俩是什么关系。两个网站的内容除了语言不同之外基本都一样。

我们之后的工作将以 https://thingsboard.io 的文档(毕竟这个是源头)为依据并参考 http://www.ithingsboard.com/ 和互联网上的其他案例资料。



ThingsBoard Community 版的编译

编译及安装的环境准备

ubuntu-24.04-live-server-amd64 ( VirtualBox 7.0 虚拟机, 2 核 4GB 内存)
官网上说用 Ubuntu 20.04 LTS,但是这会儿已经2024年8月了,还是用个新的试试吧。
另外4GB内存在之后的编译中发生了内存不足的错误,因此排查的时候改成了8GB内存,磁盘空间100GB。

git (这个 Ubuntu 自带了,没有的话需要自己装一下)

OpenJdk-11-jdk (官网上说编译需要 JAVA_11,但是又说运行的时候需要 JAVA_17,具体如何后续再验证一下)

sudo apt update
sudo apt install openjdk-17-jdk
sudo apt install openjdk-11-jdk
# 选择需要的JAVA 版本:
sudo update-alternatives --config java 

Apache Maven 3.8.7 (官网提到:安装 maven 后,可能会把 JAVA_7 变成默认环境。因为我们没有安装 JAVA_7 没碰到这个问题)

sudo apt-get install maven
# 看下maven 的版本:
mvn --version

获取源码( github 如果上不去的话,可以先同步到 gitee 然后再clone):

git clone -b release-3.7 git@github.com:thingsboard/thingsboard.git --depth 1

编译过程记录

第一次编译(报错):

cd thingsboard
mvn clean install -DskipTests
  • 出错了:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.11.0:compile (default-compile) on project data: Fatal error compiling: error: release version 17 not supported -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <args> -rf :data

用 vs code 远程连接虚拟机进去看下代码,在 thingsboard/pom.xml 里找一下报错的 “ maven-compiler-plugin ” :

        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.11.0</version>
                    <configuration>
                        <release>17</release>

可以看到 17,估计是官网的说明有问题。把JDK换成JAVA_17再试试。

第二次编译(报错):

开始之前最好先等一下啊,因为刚才vs code 进去看代码的时候,如果装了java 插件,注意一下界面提示,应该会有自动获取maven项目的提示,不知道在搞什么,安全起见,等它完成以后再继续吧:

# 选择需要的JAVA_17 版本:
sudo update-alternatives --config java

-又报错了:

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:3.2.4:repackage (default) on project coap: No space left on device -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <args> -rf org.thingsboard.transport:coap

“No space left on device” ,这个跟 ThingsBoard 没关系了,纯粹当时建虚拟机的时候硬盘给小了。
因为我是用的LVM,装系统自动分配的时候逻辑区只有10G,先把25G都分了再说吧:

sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
sudo resize2fs /dev/ubuntu-vg/ubuntu-lv

第三次编译(报错):

-再次报错:

[ERROR] Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.12.0:install-node-and-yarn (install node and npm) on project ui-ngx: Could not download Yarn: Could not download https://github.com/yarnpkg/yarn/releases/download/v1.22.17/yarn-v1.22.17.tar.gz: Remote host terminated the handshake: SSL peer shut down incorrectly -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <args> -rf :ui-ngx

由于不知名的原因,GitHub 连不上了… 用 steam ++ 加速一下再试试吧

第四次编译(报错):

-再次报错

[ERROR] Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.12.0:yarn (yarn build) on project ui-ngx: Failed to run task: 'yarn run build:prod' failed. org.apache.commons.exec.ExecuteException: Process exited with an error: 137 (Exit value: 137) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <args> -rf :ui-ngx

这里的“ Exit value: 137 ” 据yarn的官方错误码解释是内存不足的原因。先调整一下虚拟机的内存,改到8GB再试一下。

第五次编译(成功):

注:安全起见,把磁盘空间也改到100G再编译。改的方法,参考:在virtualbox中为虚拟机增加磁盘大小

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  26:00 min
[INFO] Finished at: 2024-09-03T02:17:03Z
[INFO] ------------------------------------------------------------------------

出现了上述结果,编译完成。
完成后再:

cd  application/target
ls -ll

可以看到编译完的结果。

-rwxrw-r-- 1 ubuntu docker 259606310 Sep  3 07:43 thingsboard-3.7.0-boot.jar
-rw-rw-r-- 1 ubuntu docker   2639329 Sep  3 07:43 thingsboard-3.7.0.jar
-rw-rw-r-- 1 ubuntu docker       536 Sep  3 07:43 thingsboard.changes
-rw-rw-r-- 1 ubuntu docker 248476500 Sep  3 07:43 thingsboard.deb
-rw-rw-r-- 1 ubuntu docker 248159549 Sep  3 07:44 thingsboard.rpm
-rw-rw-r-- 1 ubuntu docker 249454024 Sep  3 07:44 thingsboard-windows.zip

因为官网上说:“We are using docker and docker-compose to run all kind of integration and black-box tests.”

为了后续测试方便,需要把docker images也弄好。

编译本地docker images

前提:需要安装docker,方便起见顺道也把docker compose装了(可以参考:Docker 安装 Compose 插件)。

# 添加阿里的源(docker官方的很难连上了)
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
sudo apt -y install docker-ce docker-ce-cli containerd.io

# 设置docker为none-root user
sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker
sudo systemctl restart docker
第一次编译docker images
cd ~/thingsboard
mvn clean install -DskipTests -Ddockerfile.skip=false

不出意外,又失败了:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  06:29 min
[INFO] Finished at: 2024-09-04T01:02:45Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.spotify:dockerfile-maven-plugin:1.4.13:build (build-docker-tb-postgres-image) on project tb: Could not build image: error pulling image configuration: download failed after attempts=6: dial tcp [2a03:2880:f127:83:face:b00c:0:25de]:443: i/o timeout -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

看错误提示,是无法pull到需要的镜像基础:

[INFO] Step 1/22 : FROM thingsboard/openjdk17:bookworm-slim
[INFO]
[INFO] Pulling from thingsboard/openjdk17
[INFO] Image b0a0cf830b12: Already exists
[INFO] Image 141ac5273e17: Already exists
[INFO] Image be27aa35933c: Already exists
[ERROR] error pulling image configuration: download failed after attempts=6: dial tcp [2a03:2880:f111:83:face:b00c:0:25de]:443: i/o timeout
[WARNING] An attempt failed, will retry 1 more times

试了好几次,但这个 “thingsboard/openjdk17:bookworm-slim” 的docker image 一直无法获取,不知道这个镜像有啥。
晚一点再试试吧。

第二次编译docker images(啥也没改,就是等到第二天又试了下。成功了)
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  40:49 min
[INFO] Finished at: 2024-09-05T05:17:01Z
[INFO] ------------------------------------------------------------------------

# docker images 看一下:

REPOSITORY                       TAG                     IMAGE ID       CREATED             SIZE
# 省略。。。。
thingsboard/tb-postgres          3.7.0                   00a91de4cc30   About an hour ago   2.37GB
thingsboard/tb-postgres          latest                  00a91de4cc30   About an hour ago   2.37GB

编译就算完事了。


感受

  1. 编译环境准备的时候,应该至少配置8GB内存100GB的硬盘空间。
  2. 先安装好docker和docker compose,并配置好镜像加速。
  3. 上述准备妥当的话,编译基本可以一次过。主要浪费的时间是由于网络环境不稳定造成的。尤其是在生成docker image的时候,有时依赖的基础镜像pull不到,需要换一下镜像加速。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值