ebson

[fform 정기 재배포] 6. pm2로 애플리케이션 관리하기 본문

NODEJS WEB PROJECT/DEPLOY

[fform 정기 재배포] 6. pm2로 애플리케이션 관리하기

ebson 2022. 8. 15. 15:17

pm2로 애플리케이션 관리하기

 

What is PM2?

PM2 is deamon process manager that will help you manage and keep your application online.

 

Why do we want to use PM2?

1. keep your Node.js applications alive forever

2. if node.js goes down, PM2 brings it back up automatically with zero downtime.

3. it comes with a built-in load-balancer, which makes scailng applications way easier.

4. it works on Linux, Windows, and macOS.

5. it can help us how to manage logs for the application.

 

1. pm2 설치하기

- $npm install pm2@latest -g

 

2. pm2 시작하기

- $pm2 start ./server/index.js

 

3. pm2 중지하기

- $pm2 stop [name]

 

4. pm2 애플리케이션에 이름주어 시작하기

- $pm2 start ./server/index.js –name “API”

 

5. pm2 상세보기

- $pm2 show [name]

 

6. pm2 삭제하기

- $pm2 delete [name]

 

7. pm2 로그 남기기

- $pm2 start ./server/index.js --name “API” -o ./api.log -e ./api.log --merge-logs



Initiate Cluster Mode with PM2

The cluster mode allows networked Node.js applications (http(s)/tcp/udp server) to be scaled across all CPUs available. without any code modifications. This greatly increases the performance and reliability of your applications, depending on the number of CPUs available. Under the hood, this uses the Node.js cluster module such that the scaled application’s child processes can automatically share server ports.

 

8. pm2 클러스터 모드 사용하기

- $pm2 start ./server/index.js --name "API" -i max





출처

https://www.youtube.com/watch?v=yPd9sds9lJ4

 

Comments