授权声明:本篇文章授权活动官方亚马逊云科技文章转发、改写权,包括不限于在 Developer Centre, 知乎,自媒体平台,第三方开发者媒体等亚马逊云科技官方渠道。
- ubuntu22(注意4G内存勉强够,部署完啥都不干用到2.75G)
- win10 + MQTTX + POSTMAN
- aws
登录https://aws.amazon.com/cn/
创建服务器
Search栏输入 -> EC2
-> 启动实例 ->
-> Quick Start: Amazon Linux aws,
-> 实例类型:选择符合条件的免费套餐,这里我账号免费的只有1G1核
-> 密钥对:创建密钥对
-> 名称:zzzzzzzzzzzzzzzzzzzz2#,RSA,.pem,然后保存到本地。ssh登录需要用到。
-> 创建实例
得到了服务器IP:54.195.159.170
连接到实例
打开 MobaXterm -> Session -> SSH
-> Remote host: 54.195.159.170
-> 勾选Specify username: ec2-user
-> Avanced SSH settings
-> 勾选 Use private key,选择zzzzzzzzzzzzzzzzzzzz2#.pem
按照惯例部署frp
wget https://github.com/fatedier/frp/releases/download/v0.52.3/frp_0.52.3_linux_amd64.tar.gz && \
tar -zvxf frp_0.52.3_linux_amd64.tar.gz && \
cd frp_0.52.3_linux_amd64 && \
vim frps.toml
添加以下内容:
bindPort = 30000
auth.method = "token"
auth.token = "520101"
webServer.addr = "0.0.0.0"
webServer.port = 30001
webServer.user = "admin"
webServer.password = "jian@123"
运行
./frps -c frps.toml &
服务器开启端口
通过web配置,开启自定义TCP,30000、30001、30002、30003
$ sudo yum remove docker-ce docker-ce-cli containerd.io
$ sudo dnf install -y docker
$ sudo systemctl enable --now docker
$ sudo systemctl status docker
$ sudo docker run hello-world
$ sudo apt remove docker docker-engine docker && \
sudo apt update && \
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common && \
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add - && \
sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" && \
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7EA0A9C3F273FCD8
$ sudo apt update
$ sudo apt install docker-ce docker-ce-cli containerd.io
$ sudo systemctl status docker
$ sudo systemctl restart docker
$ sudo docker run hello-world
mkdir -p ~/.mytb-data && sudo chown -R 799:799 ~/.mytb-data && \
mkdir -p ~/.mytb-logs && sudo chown -R 799:799 ~/.mytb-logs
运行:
docker run -itd -p 18080: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
配置frp
wget https://github.com/fatedier/frp/releases/download/v0.51.3/frp_0.51.3_linux_amd64.tar.gz
tar -zvxf frp_0.51.3_linux_amd64.tar.gz
cd frp_0.51.3_linux_amd64
gedit frpc_aws.ini
输入以下内容:
serverAddr = "54.195.159.170"
serverPort = 30000
auth.method = "token"
auth.token = "520101"
[[proxies]]
name = "tcp1"
type = "tcp"
localIP = "127.0.0.1"
localPort = 18080
remotePort = 30002
[[proxies]]
name = "web1"
type = "tcp"
localIP = "127.0.0.1"
localPort = 1883
remotePort = 30003
运行
./frpc -c frpc_aws.ini &
浏览器打开:54.195.159.170:30002
默认账号:
System Administrator: [email protected] / sysadmin
Tenant Administrator: [email protected] / tenant
Customer User: [email protected] / customer
以租户管理员登录thingsboard
Tenant Administrator: [email protected] / tenant
-> 实体 -> 设备 -> 添加设备 -> 添加设备 ->
-> 名称:My New Device -> 添加
用mqtt.fx调试:
IP: 192.168.125.146
port: 1883
client id: 1234
UserName: FBXGO4WNt8u1E5UwJD2E
发送主题: v1/devices/me/telemetry
发送内容: {temperature:25.2}
用postman调试:
postman -> file -> import:
curl -v -X POST http://54.195.159.170:30002/api/v1/FBXGO4WNt8u1E5UwJD2E/telemetry --header Content-Type:application/json --data "{temperature:26}"
用mqtt.fx调试:
订阅主题: v1/devices/me/attributes
-> 实体 -> 设备 -> My New Device -> 属性 -> 客户端属性 -> 添加或修改 键名:test,数值:1236
接收到内容: {test: 1236}
用mqtt.fx调试:
IP: 54.195.159.170
port: 30003
client id: 1234
UserName: FBXGO4WNt8u1E5UwJD2E
发送主题: v1/devices/me/attributes
发送内容: {"attribute1": "value2", "attribute2": true}
用curl调试:
修改:
curl -v -X POST --data "{"attribute1": "value2", "attribute2":true, "attribute3": 43.0}" http://54.195.159.170:30002/api/v1/FBXGO4WNt8u1E5UwJD2E/attributes --header "Content-Type:application/json"
获取:
curl -v -X GET "http://54.195.159.170:30002/api/v1/FBXGO4WNt8u1E5UwJD2E/attributes?clientKeys=attribute1,attribute2&sharedKeys=shared1,shared2"
可以得到{"client":{"attribute2":true,"attribute1":"value2"}}
仪表板 -> 添加仪表板 -> 标题:New Dashboard
-> 添加部件 -> Cards -> Value card
-> 设备: My New Device
-> Value: decimals 1
-> 添加
仪表板 -> 选择仪表板:New Dashboard -> Edit mode
-> 添加部件 -> Alarm widgets -> Alarm table
-> 设备: My New Device
-> 添加
-> 保存
配置 -> 设备配置 -> default ->
-> 告警规则
-> 切换编辑模式
-> 添加告警规则
-> 告警类型:High Temperature
-> 添加告警条件 -> 添加键名筛选器 -> 键类型:Timeseries -> 键名:temperature -> 键类型:数字 -> 添加 -> 操作:大于 -> 值:35 -> 添加 -> 保存
当上传温度数据大于刚才告警设置的规则, 就会提示告警信息。
参考:
[1]Amazon Linux 2023 安装Docker和Docker Compose,https://juejin.cn/post/7243828605044850749
[2]https://thingsboard.io/docs/user-guide/