- pm2를 이용하여 nodejs를 관리가 되어야 하므로 global 영역에 설치 되어야 함
- npm install -g pm2
아래 파일을 등록하여 node를 여러개 가동 할 수 있도록 한다.
var ignoreWatch = [
'node_modules',
'logs',
'data',
'dist',
'conf'
]
// Options reference: https://pm2.keymetrics.io/docs/usage/application-declaration/
module.exports = {
apps : [
{
name: 'server-1',
script: 'index.js',
autorestart: true,
watch: true,
ignore_watch: ignoreWatch,
max_memory_restart: '1500M',
env: {
'port': '3000'
}
},
{
name: 'server-2',
script: 'index.js',
autorestart: true,
watch: true,
ignore_watch: ignoreWatch,
max_memory_restart: '1500M',
env: {
'port': '3001'
}
},
{
name: 'server-3',
script: 'index.js',
autorestart: true,
watch: true,
ignore_watch: ignoreWatch,
max_memory_restart: '1500M',
env: {
'port': '3002'
}
},
{
name: 'server-4',
script: 'index.js',
autorestart: true,
watch: true,
ignore_watch: ignoreWatch,
max_memory_restart: '1500M',
env: {
'port': '3003'
}
},
]
};
- 서비스 실행 ecosystem형식의 파일을 등록하여 사용할 것
$ pm2 [start|restart|stop|delete] ecosystem.config.js
- 서비스 등록 및 관리
$ pm2 startup // 시스템 boot 활성화
$ pm2 save
- 새로운 NodeJS 업그레이드시에는 서비스 재등록
$ pm2 unstartup // 시스템 boot 비활성화
$ pm2 startup
'개발바닥 > BackEnd' 카테고리의 다른 글
Reverse-Proxy를 통해서 Multi Node Process에 Proxy 처리 (0) | 2021.11.08 |
---|---|
무료 SSL인증서 발급 with Let's Encrypt (0) | 2021.11.08 |
Deno에 대해서 알아보자 (0) | 2021.01.08 |