Tüm Rehberler

PM2 ile Node.js Uygulama Yönetimi

PM2 process manager ile Node.js uygulamalarınızı production'da yönetin.

Orta15 dk

Kurulum Adımları

1. PM2'yi global olarak kurun:

npm install -g pm2

2. Uygulamayı başlatın:

pm2 start app.js --name "uygulama"

3. Next.js uygulaması başlatma:

pm2 start npm --name "nextjs" -- start

4. Temel komutlar:

pm2 list                # Uygulamaları listele
pm2 stop uygulama       # Durdur
pm2 restart uygulama    # Yeniden başlat
pm2 delete uygulama     # Sil
pm2 logs uygulama       # Logları göster
pm2 monit               # Canlı monitör

5. Otomatik başlatma ayarı:

pm2 startup
pm2 save

6. Ecosystem dosyası (ecosystem.config.js):

module.exports = {
  apps: [{
    name: 'uygulama',
    script: 'app.js',
    instances: 'max',
    exec_mode: 'cluster',
    env: {
      NODE_ENV: 'production',
      PORT: 3000
    }
  }]
}

7. Ecosystem ile başlatma:

pm2 start ecosystem.config.js

8. Sıfır kesinti ile güncelleme:

pm2 reload uygulama