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

Supervisor 使用教程:进程守护的最佳实践指南

6609c93d70cf3bc79f3dc9dba757ada1cd11728bfcf7.jpg


Supervisor 教程, Supervisor 配置, Linux 进程守护, 后台任务管理, 运维工具手册


一、Supervisor 是什么?

Supervisor 是一款用于管理和监控进程的工具,适用于在 Linux 服务器上保持后台任务持续运行,常用于:

  • Laravel 队列监听器

  • Python 脚本守护

  • Node.js 服务托管

  • 后台计划任务(如 crontab 替代方案)

它的核心价值在于 自动重启进程集中日志 和 统一配置管理


二、安装 Supervisor

Ubuntu / Debian:
sudo apt update
sudo apt install supervisor -y
CentOS / RHEL:
sudo yum install epel-release -y
sudo yum install supervisor -y
启动并设置开机自启:
sudo systemctl enable supervisor
sudo systemctl start supervisor

三、配置进程管理任务

Supervisor 的配置文件目录在 /etc/supervisor/conf.d/。我们以 Laravel 队列监听器为例:

新建配置文件:
sudo nano /etc/supervisor/conf.d/laravel-worker.conf
配置内容如下:
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/html/artisan queue:work --sleep=3 --tries=3
autostart=true
autorestart=true
user=www-data
numprocs=1
redirect_stderr=true
stdout_logfile=/var/www/html/storage/logs/worker.log

保存后,重新加载配置并启动:

sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start laravel-worker:*

四、常用操作命令

操作命令
查看所有任务状态sudo supervisorctl status
启动进程sudo supervisorctl start
停止进程sudo supervisorctl stop
重新启动进程sudo supervisorctl restart


五、错误排查与日志查看

Supervisor 自动记录日志,若进程未启动成功,可通过如下方式查看:

cat /var/www/html/storage/logs/worker.log

也可以查看 Supervisor 本身的日志:

cat /var/log/supervisor/supervisord.log

六、总结

Supervisor 是现代运维中不可或缺的进程管理工具,特别适合部署 Laravel、Node.js、Python 等需要长期运行的任务。通过合理配置与日志监控,你可以大大提高服务的稳定性和可维护性。

本文来自:码农资讯网,专注 DevOps、PHP、数据库、系统运维干货。


文章转载自:
http://biocoenose.wjrtg.cn
http://bristle.wjrtg.cn
http://chemomorphosis.wjrtg.cn
http://bacterial.wjrtg.cn
http://bassi.wjrtg.cn
http://aromatic.wjrtg.cn
http://borrower.wjrtg.cn
http://cataleptic.wjrtg.cn
http://adiaphorous.wjrtg.cn
http://ayah.wjrtg.cn
http://busker.wjrtg.cn
http://authenticity.wjrtg.cn
http://beadsman.wjrtg.cn
http://arpanet.wjrtg.cn
http://acalephe.wjrtg.cn
http://attend.wjrtg.cn
http://ballistics.wjrtg.cn
http://bisayan.wjrtg.cn
http://amt.wjrtg.cn
http://algae.wjrtg.cn
http://agony.wjrtg.cn
http://cautionary.wjrtg.cn
http://bantam.wjrtg.cn
http://arioso.wjrtg.cn
http://bernardine.wjrtg.cn
http://bindery.wjrtg.cn
http://active.wjrtg.cn
http://acceptive.wjrtg.cn
http://chiao.wjrtg.cn
http://abm.wjrtg.cn
http://www.dtcms.com/a/281800.html

相关文章:

  • 06-C语言:第06天笔记
  • 数据分析与AI丨从传感器到智能决策:数据驱动企业发展与 ESG 创新的全链路实践
  • 18.理解 Python 中的切片赋值
  • OpenCV-Python Tutorial : A Candy from Official Main Page(三)
  • Redis原理之持久化
  • 【构建 SHAP 解释器】X:每个样本的特征表(不能含 label,否则解释不纯粹)。
  • 隐私计算四大主流开源框架:从学术研究到工业落地,附PySyft实战Demo
  • 梁的振动特征函数分析2
  • 智驾芯片软件分层测试
  • kdump生成转储文件调试内核崩溃、死机
  • 电涡流位移测量技术深度解密
  • View2 UI聊天框架源码分享 - 支持[图文视频]混排 加入AI 分享一套功能强大的View2 UI聊天框架源码
  • Python初学者笔记第十四期 -- (自定义模块与包)
  • NFS磁盘共享
  • 基础专有术语
  • Model Control Protocol 一种开放的应用层协议,让大模型与工具能够协调配合起来,了解他的定义、定位、组成及实现机制...
  • 手提式干粉灭火器检查工作,如何做到可执行、可追溯、可管理?
  • 移动碰撞法 ——套料排版算法——CAD c#
  • java基础(day08)-面向对象
  • Redis 高频面试题
  • 【删库跑路】一次删除pip的所有第三方库
  • vllm本地部署qwen3-4b
  • 场景设计题+智力题
  • windows下安装difi(无docker desktop版)
  • 7.15 腾讯云智面经整理
  • Wiz笔记二次开发
  • AI大模型开发架构设计(22)——LangChain的大模型架构案例实战
  • 记忆力训练day41
  • 1-Nodejs介绍与安装
  • 基于STM32的智能火灾报警系统设计