Mac下ThingsBoard本地源代码安装和运行

1、前言

讲解在Mac环境下,ThingsBoard本地源代码安装和运行的过程和问题的解决

2、ThingsBoard中文网文档

安装的文档主要借鉴ThingsBoard中文网文档:

源代安装 | ThingsBoard社区版icon-default.png?t=N7T8http://www.ithingsboard.com/docs/user-guide/install/building-from-source/#%E5%AE%89%E8%A3%85%E5%8C%85

3、前置环境

为了还原实际部署可能遇到的问题,我使用的是本机已下载的环境展开讲解。

3.1、Java版本

11.0.18

3.2、Maven版本

3.9.5

3.3、node版本

v21.5.0

3.3.1、node版本切换

如果node版本有报错过低,则可以切换版本,node版应该至少v16.5.0。

3.3.3.1、安装node版本管理模块
// 安装方式以下三选一
// 使用 npm
sudo npm install n -g
//  yarn
yarn global add n
// 使用 brew
brew install n
3.3.3.2、管理模块指定node版本
sudo n 版本

3.4、npm版本

10.2.4

3.5、yarn版本

4、安装编译

4.1、克隆代码

clone成功后,先不要去编辑器中运行,最好先命令(控制台命令)编译好,因为需要下载很多依赖,编译安装的过程中也会生成一些类,直接打开会报错。

git clone https://github.com/thingsboard/thingsboard.git
cd thingsboard

4.2、编译运行

在thingsboard项目目录下运行maven install指令开始编译安装:

mvn clean install -DskipTests

4.3、出现的编译失败

4.3.1、报错内容

[INFO] --- frontend:1.12.0:yarn (yarn pkg) @ web-ui ---
[INFO] Running 'yarn run pkg' in /Users/lidongbin/code/java/thingsboard/msa/web-ui
[INFO] yarn run v1.22.17
[INFO] $ tsc && pkg -t node16-linux-x64,node16-win-x64 --out-path ./target ./target/src && node install.js
[INFO] > pkg@5.7.0
[INFO] > Fetching base Node.js binaries to PKG_CACHE_PATH
[INFO] > Not found in remote cache:
[INFO]   {"tag":"v3.4","name":"node-v16.15.0-linux-x64"}
[INFO] > Building base binary from source:
[INFO]   built-v16.15.0-linux-x64
[INFO] > Error! Not able to build for 'linux' here, only for 'macos'
[INFO] info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

[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: 2 (Exit value: 2) -> [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 :web-ui

4.2.2、报错问题

pkg-cache下没有对应mac版本的node16.5.0版本的pkg相关文件。

4.2.3、问题解决

我们可以通过下载对应的pkg-cache相关文件来避免此错误。

4.2.3.1、切换版本

参考3.3.1、node版本切换

4.2.3.2、pkg-cache相关文件下载和使用

pkg-cache相关文件下载地址(vercel/pkg-fetch · GitHub)A utility to fetch or build patched Node binaries used by `pkg` to generate executables. This repo hosts prebuilt binaries in Releases. - Releases · vercel/pkg-fetchicon-default.png?t=N7T8https://github.com/vercel/pkg-fetch/releases找到node16.5.0版本的assets,将linux,macos,win都下载(其实在mac下只需要macos)。

将下载后的文件,重命名为

  • 将node-v16.15.0-macos-x64更名为fetched-v16.15.0-macos-x64
  • 将node-v16.15.0-linux-x64更名为fetched-v16.15.0-linux-x64
  • 将node-v16.15.0-win-x64更名为fetched-v16.15.0-win-x64

然后放入~\.pkg-chche\3.4目录中。

 4.2.3.3、重新编译
mvn clean install -DskipTests

5、运行

在IDEA中打开项目,并修改thingsboard.yml中数据库相关配置,替换用户名密码,需要建一个名为thingsboard的库。

截屏2023-12-01 10.39.16.png

dao模块下,sql文件拷贝至application模块data/sql目录中

截屏2023-12-01 10.46.59.png

运行 ThingsboardInstallApplication,完成thingsboard表结构和数据的初始化。默认情况下,使用系统管理员sysadmin@thingsboard.orgsysadmin进行登录 。当然,初始化用户可以在配置文件中自定义。

截屏2023-12-01 10.46.16.png

接着运行ThingsboardServerApplication,访问http://localhost:8080/ 自动跳转至登录页面

截屏2023-12-01 10.49.11.png

  • 18
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值