不要点到重置!!!要刷新虚拟机就点重启
xshell连接虚拟机:ssh root@Public IP
环境构建
vim /etc/hosts
按 i 进入插入模式,加内网ip和主机名,按esc,按 : ,按wq
三个虚拟机都这样配
# 在 k8s-master01 上
ping yurt-edge01
ping yurt-edge02# 在 yurt-edge01 上
ping k8s-master01
ping yurt-edge02# 在 yurt-edge02 上
ping k8s-master01
ping yurt-edge01
# 下面是命令,但这里测试不需要输入命令,直接测试就行
# 查看节点状态
kubectl get nodes
# 查看所有 pods 状态
kubectl get pods --all-namespaces
cd /data/script/
ls | grep install_openyurt_manager
# ./install_openyurt_manager_v5.sh是搜索到的脚本文件
./install_openyurt_manager_v5.sh > /data/logs/install_openyurt_manager.log 2>&1
2.2自动对了
3.3运行
kubectl get pods -A
等一会儿,等最后一个也ready
启动edge01的虚拟机
cd /data/script
ls | grep yurtadm_join_edge01 或 02
# 这里的*根据上一个命令的结果来填写,后面这个VC...是master01虚拟机的密码
./yurtadm_join_edge01_*.sh 'VCtYS9aA#dB' > /data/logs/yurtadm_join.log
kubectl get nodes
kubectl get pods -A
edge02同上
kubectl edit cm -n kube-system kube-proxy
先按i,光标移动到这一行,按shift+#注释掉,按esc,按 : ,输入wq,按回车
kubectl delete pod --selector k8s-app=kube-proxy -n kube-system
kubectl get pods -A -owide | grep kube-proxy
# 下面两行是一条命令,csdn自动换行了
kubectl annotate svc kube-dns -n kube-system openyurt.io/topologyKeys='openyurt.io/nodepool'
kubectl get svc kube-dns -n kube-system -o yaml
cd /data/soft/openyurt/openyurt-helm-main
helm install yurt-iot-dock ./charts/yurt-iot-dockkubectl get crds -A
# 每一大段都全部复制
cat << EOF | kubectl apply -f -
apiVersion: apps.openyurt.io/v1beta1
kind: NodePool
metadata:
name: beijing
spec:
type: Cloud
EOF
cat << EOF | kubectl apply -f -
apiVersion: apps.openyurt.io/v1beta1
kind: NodePool
metadata:
name: hangzhou01
spec:
type: Edge
EOF
cat << EOF | kubectl apply -f -
apiVersion: apps.openyurt.io/v1beta1
kind: NodePool
metadata:
name: hangzhou02
spec:
type: Edge
EOF
kubectl label node k8s-master01 apps.openyurt.io/nodepool=beijing
kubectl label node yurt-edge01 apps.openyurt.io/nodepool=hangzhou01
kubectl label node yurt-edge02 apps.openyurt.io/nodepool=hangzhou02
cat <<EOF | kubectl apply -f - apiVersion: iot.openyurt.io/v1alpha2 kind: PlatformAdmin metadata: name: edgex-edge01 spec: version: minnesota poolName: hangzhou01 #components: #- name: yurt-iot-dock #- name: edgex-device-modbus #- name: edgex-core-data #- name: edgex-ui-go #- name: edgex-nodered EOF
# 新开一个ssh会话,再登录一个master01的虚拟机
/data/script/edgex_pod_ok.sh
cat <<EOF | kubectl apply -f - apiVersion: iot.openyurt.io/v1alpha2 kind: PlatformAdmin metadata: name: edgex-edge01 spec: version: minnesota poolName: hangzhou01 components: - name: yurt-iot-dock - name: edgex-device-modbus - name: edgex-core-data - name: edgex-ui-go - name: edgex-nodered EOF
kubectl get pa
kubectl get pods -owide
kubectl edit cm platformadmin-framework
按 : ,输入290,按 i ,把imagePullPolicy的值修改成IfNotPresent,把image的值修改成v1.4.1,按esc,按 : ,按wq按回车
去模块说明里面找
等下就把这个复制粘贴到文件里面
kubectl edit cm platformadmin-framework
按 i ,找deployment,从那开始整体下移一行,然后缩进对齐
- deployment: selector: matchLabels: app: edgex-device-modbus strategy: {} template: metadata: creationTimestamp: null labels: app: edgex-device-modbus spec: containers: - env: - name: SERVICE_HOST value: edgex-device-modbus envFrom: - configMapRef: name: common-variables image: edgexfoundry/device-modbus:3.0.0 imagePullPolicy: IfNotPresent name: edgex-device-modbus ports: - containerPort: 59901 name: tcp-59901 protocol: TCP resources: {} hostname: edgex-device-modbus name: edgex-device-modbus service: ports: - name: tcp-59901 port: 59901 protocol: TCP targetPort: 59901 selector: app: edgex-device-modbus # nodered的yaml片段 - deployment: selector: matchLabels: app: edgex-nodered strategy: {} template: metadata: creationTimestamp: null labels: app: edgex-nodered spec: containers: - env: - name: SERVICE_HOST value: edgex-nodered envFrom: - configMapRef: name: common-variables image: nodered/node-red:3.1.9 imagePullPolicy: IfNotPresent name: edgex-nodered ports: - containerPort: 1880 name: tcp-1880 protocol: TCP resources: {} hostname: edgex-nodered name: edgex-nodered service: ports: - name: tcp-1880 port: 1880 protocol: TCP targetPort: 1880 selector: app: edgex-nodered
把上面这一大段复制进去,然后按esc,按 :wq
kubectl apply -f platformadmin-framework.yaml
kubectl get pods -n default -l app=edgex-device-modbus
kubectl get pods -n default -l app=edgex-nodered
如果报错了就跳过,这个实在不会
cat <<EOF | kubectl apply -f -
apiVersion: iot.openyurt.io/v1alpha2
kind: PlatformAdmin
metadata:
name: edgex-edge02
spec:
version: minnesota
poolName: hangzhou02
components:
- name: yurt-iot-dock
- name: edgex-device-modbus
- name: edgex-core-data
- name: edgex-ui-go
- name: edgex-nodered
EOF
kubectl get pods -o wide -w | grep yurt-edge02
kubectl label nodes k8s-master01 megagame=cloud
kubectl get node k8s-master01 --show-labels
cd /data/yaml/mqtt/
ls | grep mqtt_
# 根据名字更改下面命令
kubectl apply -f /data/yaml/mqtt/mqtt_v4.yaml
kubectl apply -f /data/yaml/fuxa/fuxa.yaml
kubectl label nodes k8s-master01 megagame=cloud
kubectl get node k8s-master01 --show-labels
kubectl label nodes yurt-edge02 megagame=edge02
kubectl get node yurt-edge02 --show-labels
kubectl apply -f /data/yaml/yurt-edge02/openplc-megagame.yaml
kubectl get pods -o wide --field-selector spec.nodeName=yurt-edge02
数据采集
到谷歌浏览器把edgex-ui放上去,右上角切换中英文
在设备管理中,点击设备元信息,添加里面写
name: Env_Device_Profile
deviceResources:
- name: temp_sensor
isHidden: false
attributes:
primaryTable: HOLDING_REGISTERS
startingAddress: 0
properties:
valueType: Float32
readWrite: R
- name: wets_sensor
isHidden: false
attributes:
primaryTable: HOLDING_REGISTERS
startingAddress: 2
properties:
valueType: Float32
readWrite: R
- name: pm25_sensor
isHidden: false
attributes:
primaryTable: HOLDING_REGISTERS
startingAddress: 4
properties:
valueType: Float32
readWrite: R
- name: alarm
isHidden: false
attributes:
primaryTable: COILS
startingAddress: 0
properties:
valueType: Bool
readWrite: RWdeviceCommands: []
在设备中,点击添加设备出来这个页面,左边勾选后点击下一页
自动采集为空,直接点下一页
选这个协议
题目给了模板,把address改成edge01虚拟机的内外ip就行
边缘计算应用
时间戳:设置按3秒重复
Http请求:获取温度的URL(GET请求)
http://10.244.1.78:59882/api/v3/device/name/env-device/temp_sensor
Function 1代码
var value = msg.payload.event.readings[0].value; global.set("temp_sensor", parseFloat(value)); msg.payload = parseFloat(value); return msg;
- Http请求:获取湿度的URL(GET请求)
http://10.244.1.78:59882/api/v3/device/name/env-device/wets_sensor
- Function 2代码
var value = msg.payload.event.readings[0].value; global.set("wets_sensor", parseFloat(value)); msg.payload = parseFloat(value); return msg;
Http请求:获取PM2.5的URL(GET请求)
http://10.244.1.78:59882/api/v3/device/name/env-device/pm25_sensor
Function 3代码
var value = msg.payload.event.readings[0].value; global.set("pm25_sensor", parseFloat(value)); msg.payload = parseFloat(value); return msg;
- Function 4代码
var temp_sensor = global.get("temp_sensor"); var wets_sensor = global.get("wets_sensor"); var pm25_sensor = global.get("pm25_sensor");if (temp_sensor > 35 || wets_sensor > 60 || pm25_sensor > 100) {msg.payload = { alarm: true } } else {msg.payload = { alarm: false } } return msg;
- Http请求:设置报警器的URL(PUT请求)
http://10.244.1.78:59882/api/v3/device/name/env-device/alarm
输入nodered
右上角的settings里面设置中文
灰色的拖下来
双击http请求,在URL地址中放入command,后缀见上面的格式
返回处把utf-8改成json对象
function1里面放上面的代码,写完后点击左上角的部署
把每个http请求和function按上面格式修改,记得看眼请求方式
任务二
把时间戳改成周期性执行
任务一的
任务二的
任务三
数据分析
做不动了
数据清洗与挖掘
开启jupyter_AioT虚拟机
按照模块说明进行连接
输入jupyter lab后,浏览器输入Public_IP:8888