A

A

레일스 배포 구조와 방법

 

Rails 배포

 

 

1.배포 구조의 결정

2. 배포 방법의 자동화

 

 

 

1. 배포 구조의 결정

 

배포 구조 결정의 기준

  • 성능
  • 확장성
  • 용이성
  • 타 웹프레임워크 지원
  • 정적 파일 처리
  • SSL
  • ...

 

 

 

완전 기본 - Webrick

  • 순수 루비 웹서버
  • + 설치, 설정 불필요
  • - 성능

 

빠르지만 고통스러운 - Apache + Fast CGI

  • public/.htaccess ,  public/dispatch.fcgi
  • - 500 Internal Server Error
  • + 성능

 

 

 

한 때 날렸던 -  Lighttpd + Fast CGI

  • + 안정적 Fast CGI 지원
  • + 쉬운 설정
  • - 개발이 다소 정체 상태

 

 

 

지금은? 완전 개 판!

images/visual.jpg

  • Mongrel
  • 루비로 구현된 웹서버(파싱은 C로 구현)
  • + 설정 불필요
  • + 성능
  • + 어느 정도의 정적 파일 처리 능력
  • + 활발한 개발과 다양하고 상세한 문서 제공
  • 보통 똥개가 아니다!

 

 품종 개량 (Evented Mongrel)

  • 루비 스레딩의 취약성
  • Threaded -> Evented
  1. gem install eventmachine  
  2. gem install swiftiply  
  3. env EVENT=1 mongrel_rails start -e production -d 

 

 

개 떼가 필요해! (Mongrel Cluster)

  • Mongrel is threaded But Rails is (by default) NOT threaded

    • concurrency 를 위해서는  -> 여러 개의 mongrel 필요
  • mongrel_cluster gem 으로 한 번에 관리

     

 

먹이 분배 문제? (Load Balancer)

  • load balancer + mongrels(mongrel cluster)

    • tcp balancer
    • http balancer
    • web server (with balancer)

docs/SimpleLighttpdMongrelSetup.jpg

 

TCP Balancer : Pen / Balance

  • + 정말 쉬워요
  • - SSL 불가
  1. pen -H 4000 localhost:3000 localhost:3001

 

 

HTTP Balancer : Pound

  • + 간단한 설정파일
  • + SSL 지원

 

 

 

Web Servers

  • + 정적 파일 별도 처리
  • + 다른 웹플랫폼 지원
  • - 복잡 (Apache는 엄청 복잡)
  • 웹서버들

    • Apche+mod_proxy_balancer
    • Lightspeed  
    • Lighttpd
    • Nginx

 

images/nginx-black-logo.jpg

  • Made in Russia
  • + 성능, 성능, 성능!!
  • + 활발한 개발
  • + 비교적 쉬운 설정

 

 

배포 스택 결정 초간단 기준표

레일스 오늘 처음이에요 Webrick
이제 조금 알 것 같네요. Mongrel ( evented Mongrel)
좀 더 빠른거요. 쉬우면서. Pen/Balance + Mongrel_cluster
좀 더 빠르거요. SSL 되면서요 Pound + Mongrel_cluster
아파치 아니면 안되요. 좀  복잡해도 참을께요 Apache + mod_proxy_balance + Mongrel_cluster
무지 빠르고. 간지나는 NginX + Mongrel_cluster

 

참고 문헌

 

 

 

2. 배포 절차

 

heading_to_ground2.JPG

 

 

Capistrano 

Nerja_Capistrano_Playa_Hotel_Nerja.jpg

 

Content/3/3386/1361575.jpg

 

 

Capistrano 개념

capistrano_basic_concept.PNG

 

cap : capfile = make : makefile

 

 

 

 

 

 

 

필요사항

  •   전제 조건

    • SSH 로 원격 서버에 접근 가능

 

  •  설치
  1. gem install capistrano

 

 

task 정의

  • 원격에서  수행될 내용을 정의
  1. # Capfile
  2. task :count_libs do
  3.     run "ls -x1 /usr/lib | wc -l"
  4. end

 

  • 실행
  1. cap count_libs

 

  • 내장된 두 개의 task

    • invoke : 한 개의 명령 수행
  1. cap invoke COMMAND="ls -l"
  2. cap invoke COMMAND="ls -l" HOSTS="some.host.org"
  • shell : interactive shell 시작

    1. cap shell

 

role 정의

task가 수행 될 대상 원격 서버들을  역할 별로 구분하여 정의

 

  1. role :web, "web1.doggy.com", "web2.doggy.com"
  2. role :db,   "db.doggy.com"
  3. taks :check_free, :roles => [:web, :db] do
  4.     run "df -h /"
  5. end

 

 

Capistrano with Rails

개발서버 원격서버(운용서버)

install mongrel, mongrel_cluster

install capsitrano

mongrel_rails cluster::configure

capify .

edit depoy.rb

svn add and commit

cap deploy:setup

cap deploy:cold (최초 deploy)

cap deploy (두번째 이후 deploy)

install database

create a db for Rails app.

install mongrel, mongrel_cluster,

install capistrano

useradd -d /home/APP -m APP

APP ALL=(ALL) ALL (in /etc/sudoers )

 

capify

  • Rails 어플리케이션 폴더에 Capitstrano  사용을 기본 설정 파일 생성
  1. capfify .

 

  • [prj_root]/Capfile
  1. load 'deploy'
  • [prj_root]/config/deploy.rb 생성

 

deploy.rb

  • deploy.rb 의 예

 

  1. # 원격 서버 login id = 'APP'
    set :runner, "APP"
  2. set :user, "APP"
  3. # application name
  4. set :application, "dry"
  5. # svn repository
    set :repository,  "svn://src.doggy.com/trunk"
  6. # 최신 deploy소스 위치 : /home/APP/dry/current
    set :deploy_to, "/home/APP/#{application}"

  7. role :app, "www.doggy.com"
    role :web, "www.doggy.com"
    role :db,  "www.doggy.com", :primary => true

 

 

script/spin

  • rails  서버 실행 스크립트

 

  1. mongrel_rails cluster:start

 

 

참고문헌

  1.  Rails, Capistrano, Mongrels and nginx on Gentoo / valibuk.net
  2. Capistrano Basics
  3. Using Capistrano with Rails
  4. Deploying Rails Applications /  Pragmatic Programmers

photos/uncategorized/2007/08/20/fr_deploy.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

2007/07/thank-you.jpg

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

files/2007/07/question-mark.jpg

 

Recent Updates
    All Pages
      Show/Hide the left navigation
      Show/Hide bookmarks

      Header

      1. View current page

        ikspres님의 노트

      loginBar