文章目录
- 一、物联网云边协同
- 1.IoT云边协同设计
- 2.物联网平台设计
- 3.物联网平台实现
- 二、部署环境
- 1.节点配置
- 2.版本信息
- 三、IoT云边协同部署
- 1.部署Kubernetes集群
- 2.部署KubeEdge
- 3.部署ThingsBoard集群
- 4.部署Node-RED边缘网关
- 4.1.边缘网关功能
- 4.2.部署EMQX
- 4.2.部署Node-RED
- 5.配置边缘网关
- 5.1.ThingsBaord创建网关
- 5.2.Node-RED上传遥测
- 5.3.Node-RED连接EMQX
- 5.4.MQTTX连接EMQX
- 6.云边协同测试
- 6.1.测试方法
- 6.2.上传遥测数据
- KubeEdge
# KubeEdgehttps://iothub.org.cn/docs/kubeedge/
https://iothub.org.cn/docs/kubeedge/edge/iot/
一、物联网云边协同
1.IoT云边协同设计
物联网平台(IoT)部署在云上,网关部署在边缘节点,设备通过边缘网关接入物联网平台。
云边协同设计:
- Kubernetes 在云端部署 IoT 平台
- KubeEdge 在边缘节点部署网关
- IoT 设备通过 MQTT 协议接入边缘网关
2.物联网平台设计
物联网平台选择 ThingsBoard,边缘网关选择 EMQX、Node-RED,MQTTX 工具模拟终端设备。
IoT平台设计:
-
使用 Kubernetes 在云端部署 ThingsBoard 集群
-
使用 KubeEdge 在边缘节点部署 EMQX、Node-Red,实现边缘网关
-
MQTTX 工具模拟终端设备,通过 MQTT 协议接入边缘网关
3.物联网平台实现
物联网平台(IoT)具体实现:
- 部署 Kubernetes 集群
- 部署 KubeEdge
- 部署 ThingsBoard 集群
- 部署 EMQX、Node-RED 边缘网关
- 配置 Node-RED、MQTTX
- 测试 IoT 设备向 ThingsBoard 发送遥测数据
二、部署环境
1.节点配置
主机名 | IP地址 | 角色 |
---|---|---|
k8s-master | 192.168.202.201 | master |
k8s-node1 | 192.168.202.202 | node |
k8s-node2 | 192.168.202.203 | node |
edge-1 | 192.168.202.211 | edge |
2.版本信息
信息 | 版本 | 备注 |
---|---|---|
K8s | v1.23.12 | |
centos | 7.8 | # cat /etc/redhat-release |
KubeEdge | v1.13.4 | |
ThingsBoard | v3.5.1 | |
EMQX | 4.4.17 | |
Node-RED | latest | |
三、IoT云边协同部署
1.部署Kubernetes集群
部署 Kubernetes 集群参考
# 部署 Kubernetes 集群https://iothub.org.cn/docs/kubernetes/pro/deploy-kubernetes/
[root@k8s-master ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master Ready control-plane,master 27d v1.23.12
k8s-node1 Ready <none> 27d v1.23.12
k8s-node2 Ready <none> 10d v1.23.12
2.部署KubeEdge
部署 KubeEdge 参考
# 部署 KubeEdgehttps://iothub.org.cn/docs/kubeedge/deploy/deploy/
[root@k8s-master ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
edge-1 Ready agent,edge 4d4h v1.23.17-kubeedge-v1.13.4
k8s-master Ready control-plane,master 27d v1.23.12
k8s-node1 Ready <none> 27d v1.23.12
k8s-node2 Ready <none> 10d v1.23.12[root@k8s-master ~]# kubectl get all -n kubeedge
NAME READY STATUS RESTARTS AGE
pod/cloud-iptables-manager-592m5 1/1 Running 3 (3d22h ago) 4d5h
pod/cloud-iptables-manager-pg4pl 1/1 Running 3 (3d22h ago) 4d5h
pod/cloudcore-5959c5986f-8hsc4 1/1 Running 3 (3d22h ago) 4d5hNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/cloudcore NodePort 10.110.71.216 <none> 10000:30976/TCP,10001:31372/TCP,10002:31922/TCP,10003:30163/TCP,10004:31927/TCP 4d5hNAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
daemonset.apps/cloud-iptables-manager 2 2 2 2 2 <none> 4d5hNAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/cloudcore 1/1 1 1 4d5hNAME DESIRED CURRENT READY AGE
replicaset.apps/cloudcore-5959c5986f 1 1 1 4d5h
3.部署ThingsBoard集群
部署 ThingsBoard 参考
# ThingsBoard 单机部署
https://iothub.org.cn/docs/iot/deploy/deploy-single/# ThingsBoard 集群部署
https://iothub.org.cn/docs/iot/deploy/deploy-cluster/
备注:考虑测试环境资源有限,部署单机代替ThingsBoard集群
4.部署Node-RED边缘网关
4.1.边缘网关功能
- 边缘网关使用 EMQX、Node-RED 实现 MQTT-Broker 功能
- 边缘网关通过 Node-RED 与 ThingsBoard 平台通信
- IoT 设备通过 MQTT 协议与边缘网关 EMQX 通信
4.2.部署EMQX
gateway-emqx.yaml
[root@k8s-master kubeedge]# vim gateway-emqx.yaml apiVersion: apps/v1
kind: Deployment
metadata:name: gateway-emqx
spec:replicas: 1selector:matchLabels:app: emqxtemplate:metadata:labels:app: emqxspec:nodeName: edge-1 #调度到指定机器containers:- name: emqximage: emqx/emqx:4.4.17ports:- containerPort: 1883hostPort: 1884- containerPort: 18083hostPort: 18084- containerPort: 8081hostPort: 8082- containerPort: 8083hostPort: 8085- containerPort: 8883hostPort: 8884- containerPort: 8084hostPort: 8086
[root@k8s-master iot]# kubectl apply -f gateway-emqx.yaml
deployment.apps/gateway-emqx created[root@k8s-master iot]# kubectl get all
NAME READY STATUS RESTARTS AGE
pod/gateway-emqx-6fcb56cb4f-n8z5s 1/1 Running 0 12sNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 27dNAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/gateway-emqx 1/1 1 1 12sNAME DESIRED CURRENT READY AGE
replicaset.apps/gateway-emqx-6fcb56cb4f 1 1 1 12s
访问EMQX
# 访问地址http://192.168.202.211:18084
账号:admin
初始密码:public
修改密码:1qaz2wsx
# 参考$ docker run -d --name emqx -p 18083:18083 -p 1883:1883 emqx/emqx:latest$ docker run -d --name emqx -p 1883:1883 -p 8081:8081 -p 8083:8083 -p 8883:8883 -p 8084:8084 -p 18083:18083 emqx/emqx:v4.0.0
4.2.部署Node-RED
gateway-node-red.yaml
[root@k8s-master kubeedge]# vim gateway-node-red.yaml apiVersion: apps/v1
kind: Deployment
metadata:name: gateway-node-red
spec:replicas: 1selector:matchLabels:app: noderedtemplate:metadata:labels:app: noderedspec:nodeName: edge-1 #调度到指定机器hostNetwork: true # 使用主机网络containers:- name: noderedimage: nodered/node-red:latest
部署 Node-RED 到边缘节点
[root@k8s-master iot]# kubectl apply -f gateway-node-red.yaml
deployment.apps/gateway-node-red created[root@k8s-master iot]# kubectl get all
NAME READY STATUS RESTARTS AGE
pod/gateway-5847c4f88c-bqx5j 1/1 Running 0 30sNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 27dNAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/gateway 1/1 1 1 31sNAME DESIRED CURRENT READY AGE
replicaset.apps/gateway-5847c4f88c 1 1 1 30s
访问 Node-RED
# 访问地址http://192.168.202.211:1880
# 参考# docker run --network host --restart=always -v node_red_data:/data --name nodered nodered/node-red:latest
5.配置边缘网关
5.1.ThingsBaord创建网关
5.2.Node-RED上传遥测
将设备遥测发布到ThingsBoard服务器节点,请向以下主题发送publish消息:
Topic: v1/gateway/telemetry
Message:
{"Device A": [{"ts": 1483228800000,"values": {"temperature": 42,"humidity": 80}},{"ts": 1483228801000,"values": {"temperature": 43,"humidity": 82}}],"Device B": [{"ts": 1483228800000,"values": {"temperature": 42,"humidity": 80}}]
}
5.3.Node-RED连接EMQX
Node-RED 连接 EMQX,接收 IoT 设备遥测数据
Topic: v1/gateway/telemetry
5.4.MQTTX连接EMQX
6.云边协同测试
6.1.测试方法
- 使用 MQTTX 工具模拟物联网设备,向 EMQX 发送遥测数据
- Node-RED 通过 EMQX 订阅遥测数据
- Node-RED 把遥测数据上传到 ThingsBoard
6.2.上传遥测数据
- 通过 MQTTX 工具 上传遥测数据
v1/gateway/telemetry{"Device A": [{"ts": 1483228800000,"values": {"temperature": 42,"humidity": 80}},{"ts": 1483228801000,"values": {"temperature": 43,"humidity": 82}}],"Device B": [{"ts": 1483228800000,"values": {"temperature": 42,"humidity": 80}}]
}
-
ThingsBoard
-
Node-RED
-
KubeEdge
# KubeEdgehttps://iothub.org.cn/docs/kubeedge/
https://iothub.org.cn/docs/kubeedge/edge/iot/