news 2026/7/8 3:39:35

OpenPLC在PREEMPT_RT实时Linux上部署

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
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
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/7/8 3:38:43

0001 - 大模型概念入门

[TOC](大模型概念入门)什么是大模型&#xff1f;一文读懂 AI 大模型本文将带你从零了解大模型的定义、原理、发展历程与分类。一、什么是大模型 大模型&#xff0c;一般也称为大语言模型&#xff0c;是一种基于深度学习技术训练出来的人工智能系统&#xff0c;主要用于处理和生…

作者头像 李华
网站建设 2026/7/8 3:34:16

当出海企业选择服务平台时,如何有效应对埃及市场挑战?

在全球化的背景下&#xff0c;出海企业面临着进入埃及市场时的诸多挑战。选择合适的出海企业服务平台是应对这些挑战的重要。这些平台除了提供合规支持&#xff0c;还能帮助企业了解埃及当地的文化差异和市场动态、确保顺利运营。有效应对埃及市场的合规性要求数据保护法规、需…

作者头像 李华
网站建设 2026/7/8 3:33:35

【AI编程】腾讯云CodeBuddy

一、什么是CodeBuddy CodeBuddy 是腾讯云推出的 AI 辅助编程工具&#xff0c;通过将 AI 深度融入全流程&#xff0c;实现从产品构思到产品发布的一站式高效交付平台。 产品支持IDE、插件和 CLI 三种形态&#xff0c;覆盖从专业开发者到零基础用户的全场景需求。 二、官网下载…

作者头像 李华
网站建设 2026/7/8 3:30:52

终极B站视频下载指南:免费下载大会员4K和充电专属内容

终极B站视频下载指南&#xff1a;免费下载大会员4K和充电专属内容 【免费下载链接】bilibili-downloader B站视频下载&#xff0c;支持下载大会员清晰度4K&#xff0c;持续更新中 项目地址: https://gitcode.com/gh_mirrors/bil/bilibili-downloader 你是否曾经遇到过这…

作者头像 李华
网站建设 2026/7/8 3:29:43

工业阀门制造商80%的咨询来自竞品?揭秘企业线上获客3大断层

对于依赖线下流量的传统企业来说&#xff0c;线上获客渠道的碎片化正在成为新痛点。我们服务过的一家工业阀门制造商曾面临典型困境&#xff1a;虽然开通了企业地图标注&#xff0c;但80%的咨询电话仍来自竞品挂靠的第三方平台。这揭示了当前企业线上曝光的三大断层&#xff1a…

作者头像 李华
网站建设 2026/7/8 3:29:33

无轻奢高级建筑装饰,雕花冲孔铝单板打造梦幻空间

无轻奢高级建筑装饰&#xff0c;雕花冲孔铝单板打造梦幻空间 在高端建筑装饰领域&#xff0c;冲孔铝单板与雕花铝单板正以其独特的魅力和艺术特性&#xff0c;成为打造梦幻空间的首选材料。那么&#xff0c;这两种铝单板的优势是什么&#xff1f;它们适用于哪些场景&#xff1f…

作者头像 李华