Files
nexus/wiki/concepts/pm2.md
2026-04-17 08:38:12 +08:00

39 lines
974 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "pm2"
type: concept
tags: [node-js, process-manager, devops]
last_updated: 2026-04-17
---
## 定义
pm2 是 Node.js 进程管理器,提供进程守护、日志管理、负载均衡和开机自启等功能。
## 用途
- 守护 Node.js 进程,保持持续运行
- 管理系统日志
- 实现进程崩溃后自动重启
- 配置开机自启动
- 负载均衡cluster 模式)
## 安装方法
```bash
npm install -g pm2
```
## 常用命令
```bash
pm2 start <script> --name <name> # 启动进程
pm2 status # 查看状态
pm2 logs <name> # 查看日志
pm2 restart <name> # 重启进程
pm2 stop <name> # 停止进程
pm2 delete <name> # 删除进程
pm2 save # 保存当前进程列表
pm2 startup systemd # 生成自启动脚本
```
## 关联
- 配合工具:[[npm]]
- 管理对象:[[Node-js]]
- 替代工具forever、supervisor