Jetson 远程管理与 OTA 更新实战1. 远程管理架构远程管理方案 ├── SSH 远程终端基础管理 ├── VS Code Remote代码开发 ├── Jupyter Notebook交互式调试 ├── Web 监控系统状态面板 ├── OTA 更新远程固件/模型/代码更新 └── 看门狗自动重启和故障恢复2. SSH 远程配置# 安装 SSHsudoaptinstall-yopenssh-server# 配置密钥登录在主机上执行ssh-keygen-ted25519 ssh-copy-id jetson192.168.1.100# 禁用密码登录安全sudosed-is/#PasswordAuthentication yes/PasswordAuthentication no//etc/ssh/sshd_configsudosystemctl restartssh# SSH 端口转发远程访问 Jetson 服务ssh-L8080:localhost:8080 jetson192.168.1.100# 现在本地 localhost:8080 可以访问 Jetson 的 8080 服务3. VS Code Remote SSH// .vscode/settings.json{remote.SSH.defaultHosts:[jetson192.168.1.100],remote.SSH.serverInstallPath:{jetson192.168.1.100:/home/jetson/.vscode-server}}4. Jupyter Notebook 远程# 在 Jetson 上安装pip3installjupyter jupyterlab# 启动后台运行nohupjupyter lab--ip0.0.0.0--port8888--no-browser --allow-root# 获取 tokenjupyter server list# 浏览器访问http://jetson-ip:8888/?tokenxxx5. 系统监控 Web 面板#!/usr/bin/env python3monitor_web.py - Web 系统监控fromflaskimportFlask,jsonifyimportpsutilimportsubprocess appFlask(__name__)defget_gpu_info():try:resultsubprocess.run([cat,/sys/devices/17000000.ga10b/devfreq/17000000.ga10b/load],capture_outputTrue,textTrue)returnfloat(result.stdout.strip())except:return0defget_temp():try:withopen(/sys/devices/virtual/thermal/thermal_zone0/temp)asf:returnfloat(f.read().strip())/1000except:return0app.route(/api/status)defstatus():returnjsonify({cpu:psutil.cpu_percent(interval0.1),memory:psutil.virtual_memory().percent,gpu:get_gpu_info(),temp:get_temp(),disk:psutil.disk_usage(/).percent})if__name____main__:app.run(host0.0.0.0,port5000)6. OTA 更新系统#!/usr/bin/env python3ota_updater.py - OTA 远程更新importosimportjsonimporthashlibimportsubprocessimportrequestsfrompathlibimportPathclassOTAUpdater:OTA 更新管理器def__init__(self,update_server,local_dir/opt/app):self.serverupdate_server self.local_dirPath(local_dir)self.manifest_fileself.local_dir/manifest.jsondefcheck_update(self):检查更新remoterequests.get(f{self.server}/manifest.json).json()localself._load_local_manifest()updates[]forfile_infoinremote.get(files,[]):local_fileself.local_dir/file_info[path]ifnotlocal_file.exists():updates.append(file_info)elifself._file_hash(local_file)!file_info[md5]:updates.append(file_info)returnupdatesdefapply_update(self,updates):应用更新forfile_infoinupdates:urlf{self.server}/files/{file_info[path]}local_pathself.local_dir/file_info[path]print(f下载:{file_info[path]})local_path.parent.mkdir(parentsTrue,exist_okTrue)responserequests.get(url)local_path.write_bytes(response.content)# 校验ifself._file_hash(local_path)!file_info[md5]:raiseException(f校验失败:{file_info[path]})print(f更新完成:{len(updates)}个文件)defrestart_service(self):重启服务subprocess.run([sudo,systemctl,restart,jetson-app])def_file_hash(self,path):returnhashlib.md5(path.read_bytes()).hexdigest()def_load_local_manifest(self):ifself.manifest_file.exists():returnjson.loads(self.manifest_file.read_text())return{}if__name____main__:updaterOTAUpdater(http://update.example.com/v1)updatesupdater.check_update()ifupdates:print(f发现{len(updates)}个更新)updater.apply_update(updates)updater.restart_service()else:print(已是最新版本)7. 看门狗服务#!/bin/bash# watchdog.sh - 应用看门狗APP_CMDpython3 /opt/app/main.pyLOG_FILE/var/log/watchdog.logMAX_RESTARTS10restart_count0whiletrue;doecho$(date)启动应用$LOG_FILE$APP_CMD$LOG_FILE21exit_code$?restart_count$((restart_count1))echo$(date)应用退出 (code$exit_code, restart$restart_count)$LOG_FILEif[$restart_count-ge$MAX_RESTARTS];thenecho$(date)达到最大重启次数等待 5 分钟$LOG_FILEsleep300restart_count0fisleep5done# /etc/systemd/system/jetson-app.service [Unit] DescriptionJetson AI Application Afternetwork.target [Service] ExecStart/opt/app/watchdog.sh Restartalways RestartSec10 Userjetson WorkingDirectory/opt/app [Install] WantedBymulti-user.target总结功能工具用途远程终端SSH命令行管理代码开发VS Code Remote远程编码调试系统监控Flask Web实时状态查看OTA 更新自定义脚本远程代码/模型更新故障恢复systemd 看门狗自动重启
Jetson 远程管理与 OTA 更新实战
Jetson 远程管理与 OTA 更新实战1. 远程管理架构远程管理方案 ├── SSH 远程终端基础管理 ├── VS Code Remote代码开发 ├── Jupyter Notebook交互式调试 ├── Web 监控系统状态面板 ├── OTA 更新远程固件/模型/代码更新 └── 看门狗自动重启和故障恢复2. SSH 远程配置# 安装 SSHsudoaptinstall-yopenssh-server# 配置密钥登录在主机上执行ssh-keygen-ted25519 ssh-copy-id jetson192.168.1.100# 禁用密码登录安全sudosed-is/#PasswordAuthentication yes/PasswordAuthentication no//etc/ssh/sshd_configsudosystemctl restartssh# SSH 端口转发远程访问 Jetson 服务ssh-L8080:localhost:8080 jetson192.168.1.100# 现在本地 localhost:8080 可以访问 Jetson 的 8080 服务3. VS Code Remote SSH// .vscode/settings.json{remote.SSH.defaultHosts:[jetson192.168.1.100],remote.SSH.serverInstallPath:{jetson192.168.1.100:/home/jetson/.vscode-server}}4. Jupyter Notebook 远程# 在 Jetson 上安装pip3installjupyter jupyterlab# 启动后台运行nohupjupyter lab--ip0.0.0.0--port8888--no-browser --allow-root# 获取 tokenjupyter server list# 浏览器访问http://jetson-ip:8888/?tokenxxx5. 系统监控 Web 面板#!/usr/bin/env python3monitor_web.py - Web 系统监控fromflaskimportFlask,jsonifyimportpsutilimportsubprocess appFlask(__name__)defget_gpu_info():try:resultsubprocess.run([cat,/sys/devices/17000000.ga10b/devfreq/17000000.ga10b/load],capture_outputTrue,textTrue)returnfloat(result.stdout.strip())except:return0defget_temp():try:withopen(/sys/devices/virtual/thermal/thermal_zone0/temp)asf:returnfloat(f.read().strip())/1000except:return0app.route(/api/status)defstatus():returnjsonify({cpu:psutil.cpu_percent(interval0.1),memory:psutil.virtual_memory().percent,gpu:get_gpu_info(),temp:get_temp(),disk:psutil.disk_usage(/).percent})if__name____main__:app.run(host0.0.0.0,port5000)6. OTA 更新系统#!/usr/bin/env python3ota_updater.py - OTA 远程更新importosimportjsonimporthashlibimportsubprocessimportrequestsfrompathlibimportPathclassOTAUpdater:OTA 更新管理器def__init__(self,update_server,local_dir/opt/app):self.serverupdate_server self.local_dirPath(local_dir)self.manifest_fileself.local_dir/manifest.jsondefcheck_update(self):检查更新remoterequests.get(f{self.server}/manifest.json).json()localself._load_local_manifest()updates[]forfile_infoinremote.get(files,[]):local_fileself.local_dir/file_info[path]ifnotlocal_file.exists():updates.append(file_info)elifself._file_hash(local_file)!file_info[md5]:updates.append(file_info)returnupdatesdefapply_update(self,updates):应用更新forfile_infoinupdates:urlf{self.server}/files/{file_info[path]}local_pathself.local_dir/file_info[path]print(f下载:{file_info[path]})local_path.parent.mkdir(parentsTrue,exist_okTrue)responserequests.get(url)local_path.write_bytes(response.content)# 校验ifself._file_hash(local_path)!file_info[md5]:raiseException(f校验失败:{file_info[path]})print(f更新完成:{len(updates)}个文件)defrestart_service(self):重启服务subprocess.run([sudo,systemctl,restart,jetson-app])def_file_hash(self,path):returnhashlib.md5(path.read_bytes()).hexdigest()def_load_local_manifest(self):ifself.manifest_file.exists():returnjson.loads(self.manifest_file.read_text())return{}if__name____main__:updaterOTAUpdater(http://update.example.com/v1)updatesupdater.check_update()ifupdates:print(f发现{len(updates)}个更新)updater.apply_update(updates)updater.restart_service()else:print(已是最新版本)7. 看门狗服务#!/bin/bash# watchdog.sh - 应用看门狗APP_CMDpython3 /opt/app/main.pyLOG_FILE/var/log/watchdog.logMAX_RESTARTS10restart_count0whiletrue;doecho$(date)启动应用$LOG_FILE$APP_CMD$LOG_FILE21exit_code$?restart_count$((restart_count1))echo$(date)应用退出 (code$exit_code, restart$restart_count)$LOG_FILEif[$restart_count-ge$MAX_RESTARTS];thenecho$(date)达到最大重启次数等待 5 分钟$LOG_FILEsleep300restart_count0fisleep5done# /etc/systemd/system/jetson-app.service [Unit] DescriptionJetson AI Application Afternetwork.target [Service] ExecStart/opt/app/watchdog.sh Restartalways RestartSec10 Userjetson WorkingDirectory/opt/app [Install] WantedBymulti-user.target总结功能工具用途远程终端SSH命令行管理代码开发VS Code Remote远程编码调试系统监控Flask Web实时状态查看OTA 更新自定义脚本远程代码/模型更新故障恢复systemd 看门狗自动重启