Auto-sync: 2026-04-17 08:37
This commit is contained in:
38
wiki/concepts/pm2.md
Normal file
38
wiki/concepts/pm2.md
Normal file
@@ -0,0 +1,38 @@
|
||||
---
|
||||
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
|
||||
Reference in New Issue
Block a user