1.编译项目源码
源代码编译ThingsBoard-3.3.2
2.环境准备
修改ssh登录配置
sudo vi /etc/ssh/sshd_config
打开密码登录和root用户登录
3.安装docker
更新apt
sudo apt update
安装必备软件
sudo apt install apt-transport-https ca-certificates curl gnupg2 software-properties-common
错误一
E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
参考文章
依次执行
sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock*
sudo dpkg --configure -a
sudo apt update
将官方 Docker hub 的 GPG key 添加到系统中
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
将 Docker 版本库添加到APT源:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
安装docker
sudo apt update
sudo apt install docker-ce
检查运行
sudo systemctl status docker
安装docker-compose
安装docker-compose
curl -L https://get.daocloud.io/docker/compose/releases/download/v2.4.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
更改权限
sudo chmod +x /usr/local/bin/docker-compose
docker-compose version
4.docker集群
初始化主节点
--advertise-addr参数设定为主节点的ip
docker swarm init --advertise-addr 192.168.200.10
子节点加入
docker swarm join --token SWMTKN-1-30b3cmx28ufw2n1mufspl4vckej58wkt50oj03vbjqdycb7mcv-61lnupb8w4a07d95p8pmgjdl8 192.168.200.10:2377
查看docker集群
docker node ls
安装docker本地仓库
docker pull registry
选择master节点搭建本地仓库
vi /etc/docker/daemon.json
{
"insecure-registries": ["192.168.200.10:5000"],
"registry-mirrors": ["https://4abdkxlk.mirror.aliyuncs.com"]
}
子节点指定本地仓库地址
echo '{ "insecure-registries": ["192.168.200.10:5000"] }' > /etc/docker/daemon.json
重启docker
systemctl daemon-reload
systemctl restart docker.service
mkdir -p /software/registry
主节点部署仓库
docker run -d -p 5000:5000 -v /software/registry:/tmp/registry --restart=always registry
'//-p指定端口,一内一外;-v表示挂载,前者是宿主机,后者是容器'
查看仓库镜像
curl -X GET http://192.168.200.10:5000/v2/_catalog
不做
#打标签
docker tag nginx:latest 192.168.59.111:5000/nginx
#上传
docker push 192.168.59.111:5000/nginx
集群解散命令
docker swarm leave --force
4.部署ThingsBoard
创建文件夹
编译镜像
去到对应目录
docker build -t tb-js-executor .
docker build -t tb-node .
docker build -t tb-web-ui .
docker build -t tb-mqtt-transport .
docker build -t tb-http-transport .
发布镜像到本地仓库
vi push.sh
docker tag tb-node:latest 192.168.200.10:5000/tb-node
#推送到本地仓库
docker push 192.168.200.10:5000/tb-node
docker tag tb-web-ui:latest 192.168.200.10:5000/tb-web-ui
#推送到本地仓库
docker push 192.168.200.10:5000/tb-web-ui
docker tag tb-mqtt-transport:latest 192.168.200.10:5000/tb-mqtt-transport
#推送到本地仓库
docker push 192.168.200.10:5000/tb-mqtt-transport
docker tag tb-http-transport:latest 192.168.200.10:5000/tb-http-transport
#推送到本地仓库
docker push 192.168.200.10:5000/tb-http-transport
docker tag tb-js-executor:latest 192.168.200.10:5000/tb-js-executor
#推送到本地仓库
docker push 192.168.200.10:5000/tb-js-executor
docker rmi 192.168.200.10:5000/tb-js-executor:latest
docker rmi 192.168.200.10:5000/tb-mqtt-transport:latest
docker rmi 192.168.200.10:5000/tb-http-transport:latest
docker rmi 192.168.200.10:5000/tb-web-ui:latest
docker rmi 192.168.200.10:5000/tb-node:latest
# docker tag local-image:tagname new-repo:tagname
# tag复制一份镜像并改名,然后推送到私有仓库,删除本地推送的镜像
docker tag tb-node:latest 192.168.200.20:5000/tb-node
docker push 192.168.200.20:5000/tb-node
docker tag tb-web-ui:latest 192.168.200.20:5000/tb-web-ui
docker push 192.168.200.20:5000/tb-web-ui
docker tag tb-mqtt-transport:latest 192.168.200.20:5000/tb-mqtt-transport
docker push 192.168.200.20:5000/tb-mqtt-transport
docker tag tb-http-transport:latest 192.168.200.20:5000/tb-http-transport
docker push 192.168.200.20:5000/tb-http-transport
docker tag tb-js-executor:latest 192.168.200.20:5000/tb-js-executor
docker push 192.168.200.20:5000/tb-js-executor
docker rmi 192.168.200.20:5000/tb-node:latest
docker rmi 192.168.200.20:5000/tb-web-ui:latest
docker rmi 192.168.200.20:5000/tb-js-executor:latest
docker rmi 192.168.200.20:5000/tb-mqtt-transport:latest
docker rmi 192.168.200.20:5000/tb-http-transport:latest
查看仓库镜像
curl -X GET http://192.168.200.10:5000/v2/_catalog
上传docker文件夹
安装rabbitmq
docker pull rabbitmq:3.7.7-management
docker run -d -p 5672:5672 -p 15672:15672 -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=admin --name rabbitmq --hostname=rabbitmq rabbitmq:3.7.7-management
5672服务地址
15672webUI
http://192.168.200.10:15672/#/
上传源码中的docker文件夹
vi docker-compose.rabbitmq.yml
将不使用的协议注释
编辑环境变量
配置来源compose-utils.sh
vi env.sh
TB_QUEUE_TYPE=rabbitmq
DOCKER_REPO=192.168.200.10:5000
JS_EXECUTOR_DOCKER_NAME=tb-js-executor
TB_NODE_DOCKER_NAME=tb-node
WEB_UI_DOCKER_NAME=tb-web-ui
MQTT_TRANSPORT_DOCKER_NAME=tb-mqtt-transport
HTTP_TRANSPORT_DOCKER_NAME=tb-http-transport
COAP_TRANSPORT_DOCKER_NAME=tb-coap-transport
LWM2M_TRANSPORT_DOCKER_NAME=tb-lwm2m-transport
SNMP_TRANSPORT_DOCKER_NAME=tb-snmp-transport
TB_VERSION=latest
# Database used by ThingsBoard, can be either postgres (PostgreSQL) or hybrid (PostgreSQL for entities database and Cassandra for timeseries database).
# According to the database type corresponding docker service will be deployed (see docker-compose.postgres.yml, docker-compose.hybrid.yml for details).
DATABASE=postgres
LOAD_BALANCER_NAME=haproxy-certbot
# If enabled Prometheus and Grafana containers are deployed along with other containers
MONITORING_ENABLED=false
vi docker-compose.yml
将不需要的协议注释
#
# Copyright © 2016-2021 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.
#
version: '2.2'
services:
zookeeper:
restart: always
image: "zookeeper:3.5"
ports:
- "2181"
environment:
ZOO_MY_ID: 1
ZOO_SERVERS: server.1=zookeeper:2888:3888;zookeeper:2181
redis:
restart: always
image: redis:4.0
ports:
- "6379"
tb-js-executor:
restart: always
image: "${DOCKER_REPO}/${JS_EXECUTOR_DOCKER_NAME}:${TB_VERSION}"
scale: 20
env_file:
- tb-js-executor.env
tb-core1:
restart: always
image: "${DOCKER_REPO}/${TB_NODE_DOCKER_NAME}:${TB_VERSION}"
ports:
- "8080"
- "7070"
logging:
driver: "json-file"
options:
max-size: "200m"
max-file: "30"
environment:
TB_SERVICE_ID: tb-core1
TB_SERVICE_TYPE: tb-core
EDGES_ENABLED: "true"
env_file:
- tb-node.env
volumes:
- ./tb-node/conf:/config
- ./tb-node/log:/var/log/thingsboard
depends_on:
- zookeeper
- redis
- tb-js-executor
- tb-rule-engine1
- tb-rule-engine2
tb-core2:
restart: always
image: "${DOCKER_REPO}/${TB_NODE_DOCKER_NAME}:${TB_VERSION}"
ports:
- "8080"
- "7070"
logging:
driver: "json-file"
options:
max-size: "200m"
max-file: "30"
environment:
TB_SERVICE_ID: tb-core2
TB_SERVICE_TYPE: tb-core
EDGES_ENABLED: "true"
env_file:
- tb-node.env
volumes:
- ./tb-node/conf:/config
- ./tb-node/log:/var/log/thingsboard
depends_on:
- zookeeper
- redis
- tb-js-executor
- tb-rule-engine1
- tb-rule-engine2
tb-rule-engine1:
restart: always
image: "${DOCKER_REPO}/${TB_NODE_DOCKER_NAME}:${TB_VERSION}"
ports:
- "8080"
logging:
driver: "json-file"
options:
max-size: "200m"
max-file: "30"
environment:
TB_SERVICE_ID: tb-rule-engine1
TB_SERVICE_TYPE: tb-rule-engine
env_file:
- tb-node.env
volumes:
- ./tb-node/conf:/config
- ./tb-node/log:/var/log/thingsboard
depends_on:
- zookeeper
- redis
- tb-js-executor
tb-rule-engine2:
restart: always
image: "${DOCKER_REPO}/${TB_NODE_DOCKER_NAME}:${TB_VERSION}"
ports:
- "8080"
logging:
driver: "json-file"
options:
max-size: "200m"
max-file: "30"
environment:
TB_SERVICE_ID: tb-rule-engine2
TB_SERVICE_TYPE: tb-rule-engine
env_file:
- tb-node.env
volumes:
- ./tb-node/conf:/config
- ./tb-node/log:/var/log/thingsboard
depends_on:
- zookeeper
- redis
- tb-js-executor
tb-mqtt-transport1:
restart: always
image: "${DOCKER_REPO}/${MQTT_TRANSPORT_DOCKER_NAME}:${TB_VERSION}"
ports:
- "1883"
environment:
TB_SERVICE_ID: tb-mqtt-transport1
env_file:
- tb-mqtt-transport.env
volumes:
- ./tb-transports/mqtt/conf:/config
- ./tb-transports/mqtt/log:/var/log/tb-mqtt-transport
depends_on:
- zookeeper
tb-mqtt-transport2:
restart: always
image: "${DOCKER_REPO}/${MQTT_TRANSPORT_DOCKER_NAME}:${TB_VERSION}"
ports:
- "1883"
environment:
TB_SERVICE_ID: tb-mqtt-transport2
env_file:
- tb-mqtt-transport.env
volumes:
- ./tb-transports/mqtt/conf:/config
- ./tb-transports/mqtt/log:/var/log/tb-mqtt-transport
depends_on:
- zookeeper
tb-http-transport1:
restart: always
image: "${DOCKER_REPO}/${HTTP_TRANSPORT_DOCKER_NAME}:${TB_VERSION}"
ports:
- "8081"
environment:
TB_SERVICE_ID: tb-http-transport1
env_file:
- tb-http-transport.env
volumes:
- ./tb-transports/http/conf:/config
- ./tb-transports/http/log:/var/log/tb-http-transport
depends_on:
- zookeeper
tb-http-transport2:
restart: always
image: "${DOCKER_REPO}/${HTTP_TRANSPORT_DOCKER_NAME}:${TB_VERSION}"
ports:
- "8081"
environment:
TB_SERVICE_ID: tb-http-transport2
env_file:
- tb-http-transport.env
volumes:
- ./tb-transports/http/conf:/config
- ./tb-transports/http/log:/var/log/tb-http-transport
depends_on:
- zookeeper
# tb-coap-transport:
# restart: always
# image: "${DOCKER_REPO}/${COAP_TRANSPORT_DOCKER_NAME}:${TB_VERSION}"
# ports:
# - "5683:5683/udp"
# environment:
# TB_SERVICE_ID: tb-coap-transport
# env_file:
# - tb-coap-transport.env
# volumes:
# - ./tb-transports/coap/conf:/config
# - ./tb-transports/coap/log:/var/log/tb-coap-transport
# depends_on:
# - zookeeper
# tb-lwm2m-transport:
# restart: always
# image: "${DOCKER_REPO}/${LWM2M_TRANSPORT_DOCKER_NAME}:${TB_VERSION}"
# ports:
# - "5685:5685/udp"
# environment:
# TB_SERVICE_ID: tb-lwm2m-transport
# env_file:
# - tb-lwm2m-transport.env
# volumes:
# - ./tb-transports/lwm2m/conf:/config
# - ./tb-transports/lwm2m/log:/var/log/tb-lwm2m-transport
# depends_on:
# - zookeeper
# tb-snmp-transport:
# restart: always
# image: "${DOCKER_REPO}/${SNMP_TRANSPORT_DOCKER_NAME}:${TB_VERSION}"
# environment:
# TB_SERVICE_ID: tb-snmp-transport
# env_file:
# - tb-snmp-transport.env
# volumes:
# - ./tb-transports/snmp/conf:/config
# - ./tb-transports/snmp/log:/var/log/tb-snmp-transport
# depends_on:
# - zookeeper
tb-web-ui1:
restart: always
image: "${DOCKER_REPO}/${WEB_UI_DOCKER_NAME}:${TB_VERSION}"
ports:
- "8080"
env_file:
- tb-web-ui.env
tb-web-ui2:
restart: always
image: "${DOCKER_REPO}/${WEB_UI_DOCKER_NAME}:${TB_VERSION}"
ports:
- "8080"
env_file:
- tb-web-ui.env
haproxy:
restart: always
container_name: "${LOAD_BALANCER_NAME}"
image: thingsboard/haproxy-certbot:1.3.0
volumes:
- ./haproxy/config:/config
- ./haproxy/letsencrypt:/etc/letsencrypt
- ./haproxy/certs.d:/usr/local/etc/haproxy/certs.d
ports:
- "80:80"
- "443:443"
- "1883:1883"
- "7070:7070"
- "9999:9999"
cap_add:
- NET_ADMIN
environment:
HTTP_PORT: 80
HTTPS_PORT: 443
MQTT_PORT: 1883
EDGES_RPC_PORT: 7070
FORCE_HTTPS_REDIRECT: "false"
links:
- tb-core1
- tb-core2
- tb-web-ui1
- tb-web-ui2
- tb-mqtt-transport1
- tb-mqtt-transport2
- tb-http-transport1
- tb-http-transport2
正式安装ThingsBoard-3.3.2
创建日志文件夹
sh docker-create-log-folders.sh
执行安装脚本
sh docker-install-tb.sh
错误一
docker-install-tb.sh: 18: docker-install-tb.sh: [[: not found
docker-install-tb.sh: 34: [: unexpected operator
docker-install-tb.sh: 42: docker-install-tb.sh: source: not found
参考文章
sudo dpkg-reconfigure dash
弹出页面选择no
错误二
docker-install-tb.sh: line 42: source: compose-utils.sh: file not found
source命令找不到文件,在所有报错的文件前加./ 指定目录
source命令找不到的文件
docker-install-tb.sh
compose-utils.sh
docker-start-services.sh
docker-stop-services.sh
vi docker-compose.rabbitmq.yml
#不使用的协议注释
错误三
[0.001s][error][logging] Error opening log file '/var/log/thingsboard/tb-core1-gc.log': Permission denied
[0.001s][error][logging] Initialization of output 'file=/var/log/thingsboard/tb-core1-gc.log' using options 'filecount=10,filesize=10M' failed.
Invalid -Xlog option '-Xlog:gc*,heap*,age*,safepoint=debug:file=/var/log/thingsboard/tb-core1-gc.log:time,uptime,level,tags:filecount=10,filesize=10M', see error log for details.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
解决,重新赋予文件夹访问权限
sh docker-start-services.sh
安装成功,查看进程
docker-compose ps
系统管理员账号:sysadmin@thingsboard.org
密码:sysadmin