반응형

pm2 (백그라운드로 서버 로딩)

설치는  gogo >> https://pm2.io/doc/en/runtime/guide/installation/

 

Installation | Guide | PM2 Documentation

 

pm2.io

에코 시스템 ( 한번 실행으로 서버 올리고 관리 !!! )

pm2 init 

-- 에코 설정 파일 참고

module.exports = {
  apps : [{
    name: 'jisou',
    script: './backEnd/bin/www',

    // Options reference: https://pm2.io/doc/en/runtime/reference/ecosystem-file/
    args: 'one two',
    instances: 1,
    autorestart: true,
    watch: false,
    max_memory_restart: '1G',
    env: {
      NODE_ENV: 'development',
      PORT : 3000
    },
    env_pr: {
      NODE_ENV: 'production',
      PORT:80
    }
  }],
  
};  

참조 >> https://pm2.io/doc/en/runtime/guide/ecosystem-file/

 

Ecosystem File | Guide | PM2 Documentation

 

pm2.io

pm2 log 관리는 pm2 안에서 설치 

pm2 install pm2-logrotate

참조 >> https://pm2.io/doc/en/runtime/guide/log-management/

 

Log Management | Guide | PM2 Documentation

 

pm2.io

30일에 한번씩 로그 삭제 하도록 설정

pm2 set pm2-logrotate:retain  30

참조 >> https://github.com/keymetrics/pm2-logrotate

 

keymetrics/pm2-logrotate

Automatically rotate all applications logs managed by PM2 - keymetrics/pm2-logrotate

github.com

 

참고로 집 서버가 윈도우10  

그냥 윈도우 커맨드 창에서 모두 테스트 완료 !!!

꼭 리눅스로 안해도 됨

pm2 log / pm2 monit/ pm2 status 

현재 노드 서버 체크 가능

으 글이 길어지네 길어지면 잘 안보는데 ㅠ_ㅠ

이것저것 셋팅후 

백엔드 / 프론트 동시 구동하게 설정

-- 제일 상단 package.json
{
  "name": "프로젝트명",
  "version": "0.0.1",
  "scripts": {
    "start": "node ./bin/www",
    "pm2": "cd front && npm install && npm run build && cd ../backEnd && npm install && cd .. && pm2 start --env pr"
  },
  "dependencies": {},
}

npm run pm2 !!

아 한방실행 너무 편함

상단 프로젝트 폴더에서 >> 프론트 이동 >> 프론트 의존성 설치 >> 빌드 >> 백엔드 이동 >> 백엔드 의존성 설치

>> 상단 이동 >> pm2 에코시스템 (개발/운영) 서버 로딩 (^_^)b

 

실행 후 화면 

반응형
반응형

기종 : cent os 6.5


우선 node.js 설치 (root 계정으로 설치)


소스 컴파일 방법입니다.

~$ wget http://nodejs.org/dist/v0.10.28/node-v0.10.28.tar.gz

~$ tar vxzf node-v0.10.28.tar.gz

~$ cd node-v0.10.28

~/node-v0.10.28$ ./configure

~/node-v0.10.28$ make

~/node-v0.10.28$ sudo make install


다음은 apt-get을 이용한 인스톨방법입니다.

$ sudo apt-get install nodejs

$ sudo apt-get install npm



참고 링크 : http://pyrasis.com/nodejs/nodejs-HOWTO#section-8


node.js path 설정.. 


설치 완료 테스트 node -v  

버젼 나오면 성공


간단히 서버 만들어서 테스트 해볼까 했는데...

외부 접근이 안됨 !!!! 머지 ( 팀장닷컴 가상서버 이용중)

팀장닷컴 고객센터 포트포워딩 요청 ... 해결  -0-;;;


npm 으로 각종 소스 형태? 설치


npm install -g express와 같이 -g 옵션을 주면 Node.js 설치 디렉터리에 모듈이 설치됩니다. 

전역 모듈 설치라고 하는데 이렇게 설치하면 app.js 디렉터리와 상관없이 모듈을 사용


express 설치 오류가 나면 ( npm install -g express-generator )


npm install express

npm install date-utils


npm install node-gcm


설치 후 간단한 푸시 테스트 


push.js

    

var gcm = require('node-gcm');

// create a message with default values

var message = new gcm.Message();


// or with object values

var message = new gcm.Message({

    collapseKey: 'demo',

    delayWhileIdle: true,

    timeToLive: 3,

    data: {

        key1: '안녕하세요.',

        key2: 'saltfactory push demo'

    }

});


var server_access_key = '푸시 프로바이더 서버 access key 값';

var sender = new gcm.Sender(server_access_key);

var registrationIds = [];


var registration_id = '안드로이드 registration_id 값';

// At least one required

registrationIds.push(registration_id);


/**

 * Params: message-literal, registrationIds-array, No. of retries, callback-function

 **/

sender.send(message, registrationIds, 4function (err, result) {

    console.log(result);

});


node push.js  로 테스트...





그리고 또다른 서버 설정 pm2 

node.js 는 오류나 내가 나가거나 ctrl+c 하면 서비스가 죽어버린다...

키워드 리눅스 실행 및 부팅시 자동실행  Keep Alive 

Install PM2

$ npm install pm2 -g

npm is a builtin CLI when you install Node.js - Installing Node.js or io.js with NVM

Start an application

$ pm2 start app.js

Main features

Process management

Once apps are started you can list and manage them easily:

Process listing

Listing all running processes:

$ pm2 list

Managing your processes is straightforward:

$ pm2 stop     <app_name|id|all>
$ pm2 restart  <app_name|id|all>
$ pm2 delete   <app_name|id|all>

To have more details on a specific process:

$ pm2 describe 0

Monitoring

Monit

Monitoring all processes launched:

$ pm2 monit

Log facilities

Monit


Startup script generation

PM2 can generate and configure a startup script to keep PM2 and your processes alive at every server restart.

$ pm2 startup
# auto-detect platform
$ pm2 startup [platform]
# render startup-script for a specific platform, the [platform] could be one of:
#   ubuntu|centos|redhat|gentoo|systemd|darwin|amazon

To save a process list just do:

$ pm2 save

centos 는

pm2 startup centos 하면 된다 ~


개 편함 ~!!


참고 URL

(node.js 기본코드를 볼 수 있는곳 많은 도움이 되었다.)

http://cinema4dr12.tistory.com/category/Programming/Web%20App


https://github.com/Unitech/pm2 

http://wingsnote.com/m/post/59






반응형

+ Recent posts