2017년 11월 21일 화요일

[LiNuX] 시간 동기화


root@freecatz:~# rdate -s time.bora.net && hwclock --systohc

root@freecatz:~# vi /etc/crontab

# m : minute (0 - 59) 
# h : hour (0 - 23)
# dom : day of month (1 -     ) 
# mon : month (1 - 12) OR jan,feb,mar,apr ... 
# dow : day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# m h dom mon dow user  command
59 23   * * *   root    rdate -s time.bora.net && hwclock --systohc



2017년 11월 20일 월요일

[EtC] nodejs 로 Hello World

1. nodejs 다운로드 및 설치

   https://nodejs.org

  설치 과정 생략


2. 프로젝트 디렉토리 생성

   D:\>helloworld 생성

3. nodejs 실행 파일 생성

   D:\>helloworld 에 server.js 파을 생성 후 아래의 코드를 입력 한다.

   var express = require('express');
   var app = express();

   /*
get으로 / 요청시 아래의 내용들이 실행 된다.
   */
   app.get('/', function (req, res) {

      _date = new Date();
      console.log('Date :', _date.getFullYear() + '.' + _date.getMonth() + 1 + '.' + _date.getDate());
      console.log('uptime : ' + process.uptime());
      console.log('Client : ' + req.connection.remoteAddress);
      res.send('Hello World!');
   });

   /*
테스트용 코드로 /exit 주소를 호출 하는 경우 서버 프로그램을 종료 시킨다.
실제 운영시에는 사용하지 않는다.
   */
   /*
   app.get('/exit', function (req, res) {
      console.log('program self kill');
      process.exit();
   });
   */


   /*
9090 포트로 프로그램을 실행 후, 콘솔에 로그를 찍는다.
   */
   app.listen(9090, function () {

       /* public 디렉토리내 static 리소스들을 사용 하기 위한 코드 */
       app.use(express.static('public'));

       /* 서버가 시작 되고 1초 후 아래의 내용들을 찍어 준다. */
       setTimeout(function() {
       console.log('PID : ' + process.pid);
       console.log('node ver : ' + process.version);
       console.log('arch : ' + process.arch);
   console.log('platform : ' + process.platform);
   console.log('-----> nodejs server started');
       }, 1000);
   });


4. npm init


  D:\helloworld 에서 npm init 명령을 실행 한다.

  D:\helloworld> npm init
  This utility will walk you through creating a package.json file.
  It only covers the most common items, and tries to guess sensible defaults.

  See `npm help json` for definitive documentation on these fields
  and exactly what they do.

  Use `npm install <pkg>` afterwards to install a package and
  save it as a dependency in the package.json file.

  Press ^C at any time to quit.
  package name: (helloworld)          # 프로젝트 명칭. Mandatory.
  version: (1.0.0)                      # 프로젝트 버전. Optional.
  description: hello world              # 프로젝트 설명. Optional.
  entry point: (index.js)                # 프로젝트 진입점 파일명. Mandatory.
  test command:                      # 모름. Optional.
  git repository:                       # git repository 가 있는 경우. Optional.
  keywords:                          # 키워드. Optional.
  author:                             # 작성자. Optional.
  license: (ISC)                        # 라이센스. Optional.
  About to write to D:\helloworld\package.json:

  {
    "name": "helloworld",
    "version": "1.0.0",
    "description": "hello world",
    "main": "index.js",
    "scripts": {
      "test": "echo \"Error: no test specified\" && exit 1"
    },
    "author": "",
    "license": "ISC"
  }


  Is this ok? (yes)                # 최종 위의 내용으로 package.json 파일이 생성.

  D:\helloworld>


  npm init 명령 실행 후, D:\helloworld\package.json 파일이 생성 된다.


5. express 패키지 설치


    D:\>helloworld> npm install express --save

    위의 명령 실행 후 D:\helloworld 디렉토리 아래 node_module 디렉토리가 생성 되고
    그 아래 express 패키지와 의존성 패키지들이 설치 된다.

6. 실행

   D:\>npm server.js


7. 브라우저와 콘솔을 통한 확인


   http://localhost:9090