简介

最近学习物联网,实验课需要我们安装Thingsboard,查资料发现可以使用docker安装,果断选择docker安装,但是docker安装也有一些坑,故记录安装过程以防后人踩坑。

ThingsBoard是一个开源物联网平台,主要用于数据收集、处理、可视化和设备管理,但是安装部署却是我们新手入门的一个大难题,使用docker安装可让我们省略环境配置的苦恼,节省安装时间。

ThingsBoard is an open-source IoT platform that enables rapid development, management, and scaling of IoT projects. Our goal is to provide the out-of-the-box IoT cloud or on-premises solution that will enable server-side infrastructure for your IoT applications.

Docker安装Thingsboard

需要拥有一台操作系统为CentOS7.6的服务器

已安装docker,安装docker命令:yum install -y docker

已安装nginx,一键安装nginx脚本参考我的博客:Linux服务器开发环境配置

前往Thingsboard中文网选择docker镜像,这里选择thingsboard/tb-postgres

在docker官方镜像thingsboard/tb-postgres可以找到详细安装教程(推荐看这个)

docker官方安装教程

1
2
3
4
mkdir -p ~/.mytb-data && sudo chown -R 799:799 ~/.mytb-data
mkdir -p ~/.mytb-logs && sudo chown -R 799:799 ~/.mytb-logs
docker run -it -p 9090:9090 -p 7070:7070 -p 1883:1883 -p 5683-5688:5683-5688/udp -v ~/.mytb-data:/data \
-v ~/.mytb-logs:/var/log/thingsboard --name mytb --restart always thingsboard/tb-postgres

如果更换安装位置需要替换~/.

1
2
3
mkdir -p /www/mytb/mytb-data && sudo chown -R 799:799 /www/mytb/mytb-data
mkdir -p /www/mytb/mytb-logs && sudo chown -R 799:799 /www/mytb/mytb-logs
docker run -itd -p 9090:9090 -p 1883:1883 -p 7070:7070 -p 5683-5688:5683-5688/udp -v /www/mytb/mytb-data:/data -v /www/mytb/mytb-logs:/var/log/thingsboard --name mytb --restart always thingsboard/tb-postgres

安装好后,此时还不能使用外网连接,因为Thingsboard默认内网连接,官方原话:

1
2
These commands install ThingsBoard and load demo data and accounts.
ThingsBoard UI will be available using the URL: http://localhost:8080. You may use username tenant@thingsboard.org and password tenant. More info about demo accounts is available here.

此时我们需使用Nginx做端口映射:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
server {
listen 9136;
location / {
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 120s;

proxy_set_header Upgrade websocket;
proxy_set_header Connection Upgrade;
proxy_pass http://127.0.0.1:9090;
}
}

访问http://ip:9136即可

服务器没有nginx可参考我的博客:Linux服务器开发环境配置使用一键安装脚本

登录Thingsboard

在docker官方教程也给出Thingsboard默认账号:

1
2
3
Systen Administrator: sysadmin@thingsboard.org / sysadmin
Tenant Administrator: tenant@thingsboard.org / tenant
Customer User: customer@thingsboard.org / customer

登录Thingsboard

Docker升级Thingsboard

1
2
3
4
5
docker pull thingsboard/tb-postgres
docker stop mytb
docker run -it -v ~/.mytb-data:/data --rm thingsboard/tb-postgres upgrade-tb.sh
docker rm mytb
docker run -it -p 9090:9090 -p 1883:1883 -p 7070:7070 -p 5683-5688:5683-5688/udp -v ~/.mytb-data:/data -v ~/.mytb-logs:/var/log/thingsboard --name mytb --restart always thingsboard/tb-postgres

常见问题

1、[0.001s][error][logging] Error opening log file '/var/log/thingsboard/gc.log': Permission denied

还没有创建目录,并且未授权,需要执行命令:

1
2
mkdir -p ~/.mytb-data && sudo chown -R 799:799 ~/.mytb-data
mkdir -p ~/.mytb-logs && sudo chown -R 799:799 ~/.mytb-logs

2、无法访问

需要做端口映射:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
server {
listen 9136;
location / {
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 120s;

proxy_set_header Upgrade websocket;
proxy_set_header Connection Upgrade;
proxy_pass http://127.0.0.1:9090;
}
}

访问http://ip:9136即可