当前位置: 首页 > news >正文

OpenPLC在PREEMPT_RT实时Linux上部署

Web 服务器与plc_main绑定在一个CPU上

1. 找到 OpenPLC 的 systemd 服务文件

通常位于/etc/systemd/system/openplc.service

2. 编辑服务文件

找到文件路径后,使用vim编辑:

vim /etc/systemd/system/openplc.service

3. 在 [Service] 部分添加/修改以下指令

[Unit] Description=OpenPLC Runtime v4 Service After=network.target ​ [Service] Type=simple Restart=always RestartSec=5 User=root Group=root # 设置实时调度策略和优先级 (99 为最高) CPUSchedulingPolicy=fifo CPUSchedulingPriority=99 # 绑定到特定 CPU 核心 (例如 CPU 2) CPUAffinity=2 # 允许锁定内存,防止被换出 LimitMEMLOCK=infinity ​ WorkingDirectory=/run/media/mmcblk2p12/openplc-runtime ExecStart=/run/media/mmcblk2p12/openplc-runtime/start_openplc.sh ​ [Install] WantedBy=multi-user.target ​

4. 重启 systemd 并启动服务

systemctl daemon-reload systemctl restart openplc-runtime.service

5. 验证是否生效

chrt -p $(pgrep plc_main)

输出中应显示pid 1714's current scheduling policy: SCHED_FIFO

Web 服务器与plc_main绑定在不同的CPU上

1. 创建正确的openplc.service
tee /etc/systemd/system/openplc.service << 'EOF' [Unit] Description=OpenPLC v4 - Web Server After=network.target PartOf=openplc.target ​ [Service] Type=simple User=root WorkingDirectory=/run/media/mmcblk2p12/openplc-runtime CPUAffinity=0 Environment="PYTHONPATH=/run/media/mmcblk2p12/openplc-runtime" ExecStart=/run/media/mmcblk2p12/openplc-runtime/venvs/runtime/bin/python /run/media/mmcblk2p12/openplc-runtime/webserver/app.py ExecStop=/usr/bin/pkill -f "app.py" Restart=on-failure RestartSec=5 ​ [Install] WantedBy=openplc.target EOF
2. 创建正确的openplc-plc.service
tee /etc/systemd/system/openplc-plc.service << 'EOF' [Unit] Description=OpenPLC v4 - PLC Core After=network.target openplc.service PartOf=openplc.target Wants=openplc.service ​ [Service] Type=simple User=root WorkingDirectory=/run/media/mmcblk2p12/openplc-runtime CPUAffinity=2 CPUSchedulingPolicy=fifo CPUSchedulingPriority=99 LimitMEMLOCK=infinity ExecStart=/run/media/mmcblk2p12/openplc-runtime/build/plc_main ExecStop=/usr/bin/pkill -f "plc_main" Restart=on-failure RestartSec=5 ​ [Install] WantedBy=openplc.target EOF
4. 创建 target 文件(可选,用于统一管理)
tee /etc/systemd/system/openplc.target << 'EOF' [Unit] Description=OpenPLC v4 - All Services Requires=openplc.service openplc-plc.service After=openplc.service openplc-plc.service EOF

🚀 使用 target 的日常管理命令

操作命令
启动所有服务systemctl start openplc.target
停止所有服务systemctl stop openplc.target
重启所有服务systemctl restart openplc.target
查看整体状态systemctl status openplc.target
查看依赖的服务systemctl list-dependencies openplc.target
5. 重新加载 systemd
systemctl daemon-reload
6. 验证文件已被识别
systemctl list-unit-files | grep openplc

应该看到:

text

openplc-plc.service disabled disabled openplc-runtime.service enabled enabled openplc.service disabled disabled openplc.target static -

target 不需要 enable

7. 启用并启动服务
systemctl enable openplc.service systemctl enable openplc-plc.service systemctl start openplc.service systemctl start openplc-plc.service
8. 检查状态
sudo systemctl status openplc.service sudo systemctl status openplc-plc.service

📌 如果openplc-runtime.service与你冲突

如果openplc-runtime.service也会启动 OpenPLC,你可能需要先停止并禁用它,避免重复启动:

systemctl stop openplc-runtime.service systemctl disable openplc-runtime.service

验证 target 是否工作

# 启动所有服务 sudo systemctl start openplc.target ​ # 检查状态 sudo systemctl status openplc.target sudo systemctl status openplc.service sudo systemctl status openplc-plc.service ​ # 确认进程 ps -eo pid,comm,psr,rtprio,policy,args | grep -E "app|webserver|openplc" | grep -v grep
http://www.cnnetsun.cn/news/3213744.html

相关文章:

  • 0001 - 大模型概念入门
  • 当出海企业选择服务平台时,如何有效应对埃及市场挑战?
  • 【AI编程】腾讯云CodeBuddy
  • 终极B站视频下载指南:免费下载大会员4K和充电专属内容
  • 工业阀门制造商80%的咨询来自竞品?揭秘企业线上获客3大断层
  • 无轻奢高级建筑装饰,雕花冲孔铝单板打造梦幻空间
  • Python正则表达式完整教程:从入门到实战,解决文本匹配所有难题
  • AI 辅助 Code Review 的团队落地:从试用到痛点解决的完整路径
  • ChatGPT已过时?揭秘AI Agent如何彻底改变你的工作方式!
  • Acrobat Pro DC 2024安装本质:云原生软件的三方握手认证
  • 这次终于选对了!2026年亲测好用的专业AI论文写作软件
  • 音频处理深入:混音、降噪、音量调节与格式转换
  • ADP5350电源管理IC在嵌入式系统中的应用与优化
  • 绵竹深夜连震,iPhone 用户只能刷朋友圈?我写了一个开源地震预警系统
  • 采购智慧养老设备总踩坑?星梦云康轻量化方案提供参考
  • A股实时行情 API 接入教程:TickDB REST ticker、K线与 WebSocket 实测
  • 2026OpenClaw企业版品牌下载推荐 八款商用智能体分行业量化选型测评指南
  • PyTorch 2.0 线性回归实战:3步从数据加载到模型保存(附完整代码)
  • ZIP密码破解工具对比:ARCHPR vs fcrackzip vs ZipCracker 3款实战评测
  • TraceID 跨越异步任务:不要让消息队列切断调用链
  • 孩子书桌用什么灯好?盘点护眼效果好的护眼台灯,品质过硬!
  • 半导体超纯水系统 2026:3种主流配置方案与18.2 MΩ·cm水质保障
  • 2026工程物资管理软件哪个好?5款轻付费和免费的管理软件对比!
  • 智算中心冷板批量焊接的产能瓶颈:柔性换型怎么破?
  • 多版本Python共存以及环境变量配置
  • 翠湖逛累了别瞎跑!翠怡酒店旁藏着机关食堂开的便民小吃点
  • 报社登报多少钱?报社登报如何办理?办理须注意什么?
  • 全终端接入:OKCC呼叫中心五大接入方式的技术实现解析
  • 深化实验室数智化管理:广凌实验室一体化管理系统的创新实践
  • 太原装修最容易后悔的10个设计|花钱添堵!入住90%想拆掉