54
Vagrant와 Chef로 개발서버 구축 자동화하기 1

Vagrant와 chef로 개발서버 구축 자동화하기

Embed Size (px)

DESCRIPTION

제10회 개발자를 위한 ‘共感(공감)’ 세미나 - Session 5 Vagrant와 Chef로 개발서버 구축 자동화하기의 장표입니다. 규모가 있는 자바 웹 프로젝트는 대부분 개발, 테스트, 이관, 운영 등 n개의 서버로 배포/관리가 된다. 테스트, 이관, 운영과 같은 서버는 별도의 서버가 마련되어 구축되지만 개발서버는 일반적으로 개발자 자신의 PC에 구축해서 진행하는 경우가 많다. 이러다보니 개발자별로 조금씩 미묘하게 다른 서버 환경이 자신의 PC에서는 잘 되는 기능이 다른 서버에 배포되면 구동되지 않는 경우도 많고, 프로젝트에 참여하는 개발자들이 개발서버를 구축하기 위해서 들이는 비용도 만만치 많이 들어간다. Vagrant와 Chef라는 도구를 사용하면 개발자들이 자신의 PC에 개발서버를 구축하고 관리하는데 들어가는 비용을 획기적으로 줄일 수 있다. 예제에 보여준 동영상 : http://youtu.be/W28iX5WFRXU 예제에 사용된 소스 : https://gist.github.com/4366784

Citation preview

Page 1: Vagrant와 chef로 개발서버 구축 자동화하기

Vagrant와����������� ������������������  Chef로����������� ������������������  개발서버����������� ������������������  구축

자동화하기

1

Page 2: Vagrant와 chef로 개발서버 구축 자동화하기

박용권SK����������� ������������������  planet����������� ������������������  /����������� ������������������  Platform����������� ������������������  Software����������� ������������������  개발팀

반갑습니다.

-����������� ������������������  한국����������� ������������������  스프링����������� ������������������  사용자����������� ������������������  그룹(KSUG)-����������� ������������������  봄싹(SpringSprout)-����������� ������������������  라����������� ������������������  스칼라����������� ������������������  코딩단(La����������� ������������������  Scala����������� ������������������  Coding����������� ������������������  Dan)-����������� ������������������  ...

2

Page 3: Vagrant와 chef로 개발서버 구축 자동화하기

이야깃거리가상화����������� ������������������  그리고����������� ������������������  Vagrant!

설정����������� ������������������  자동화를����������� ������������������  위한����������� ������������������  Chef!

개발서버����������� ������������������  구축����������� ������������������  자동화����������� ������������������  예제!

3

Page 4: Vagrant와 chef로 개발서버 구축 자동화하기

Server

4

Page 5: Vagrant와 chef로 개발서버 구축 자동화하기

서버����������� ������������������  :����������� ������������������  개발����������� ������������������  /����������� ������������������  테스트����������� ������������������  /����������� ������������������  이관����������� ������������������  /����������� ������������������  운영

개발

테스트

이관

운영

개발자

품질관리자

시스템관리자

5

Page 6: Vagrant와 chef로 개발서버 구축 자동화하기

서버����������� ������������������  :����������� ������������������  개발����������� ������������������  /����������� ������������������  테스트����������� ������������������  /����������� ������������������  이관����������� ������������������  /����������� ������������������  운영

개발

테스트

이관

운영

개발자

품질관리자

시스템관리자

6

Page 7: Vagrant와 chef로 개발서버 구축 자동화하기

개발자����������� ������������������  PC����������� ������������������  ==����������� ������������������  개발서버

개발자

7

Page 8: Vagrant와 chef로 개발서버 구축 자동화하기

개발자����������� ������������������  PC����������� ������������������  ==����������� ������������������  개발서버

개발자

8

Page 9: Vagrant와 chef로 개발서버 구축 자동화하기

개발자����������� ������������������  PC����������� ������������������  ==����������� ������������������  개발서버

개발자

9

Page 10: Vagrant와 chef로 개발서버 구축 자동화하기

개발자����������� ������������������  PC����������� ������������������  ==����������� ������������������  개발서버

개발자

10

Page 11: Vagrant와 chef로 개발서버 구축 자동화하기

난.장.판.

11

Page 12: Vagrant와 chef로 개발서버 구축 자동화하기

H3����������� ������������������  컨퍼런스에서����������� ������������������  해결책을����������� ������������������  찾다!

12

Page 13: Vagrant와 chef로 개발서버 구축 자동화하기

가상화����������� ������������������  그리고����������� ������������������  Vagrant!

+

13

Page 14: Vagrant와 chef로 개발서버 구축 자동화하기

가상화는����������� ������������������  이미����������� ������������������  사용하고����������� ������������������  있었지만...

14

Page 15: Vagrant와 chef로 개발서버 구축 자동화하기

가상화는����������� ������������������  이미����������� ������������������  사용하고����������� ������������������  있었지만...

14

Page 16: Vagrant와 chef로 개발서버 구축 자동화하기

가상화는����������� ������������������  이미����������� ������������������  사용하고����������� ������������������  있었지만...

14

Page 17: Vagrant와 chef로 개발서버 구축 자동화하기

가상화는����������� ������������������  이미����������� ������������������  사용하고����������� ������������������  있었지만...

14

Page 18: Vagrant와 chef로 개발서버 구축 자동화하기

가상화는����������� ������������������  이미����������� ������������������  사용하고����������� ������������������  있었지만...

14

Page 19: Vagrant와 chef로 개발서버 구축 자동화하기

가상화는����������� ������������������  이미����������� ������������������  사용하고����������� ������������������  있었지만...

14

Page 20: Vagrant와 chef로 개발서버 구축 자동화하기

가상화는����������� ������������������  이미����������� ������������������  사용하고����������� ������������������  있었지만...

14

Page 21: Vagrant와 chef로 개발서버 구축 자동화하기

가상화는����������� ������������������  이미����������� ������������������  사용하고����������� ������������������  있었지만...

15

Page 22: Vagrant와 chef로 개발서버 구축 자동화하기

Vagrant를����������� ������������������  소개합니다.

가상머신����������� ������������������  관리����������� ������������������  도구@mitchellh오픈소스����������� ������������������  MIT����������� ������������������  라이센스Ruby����������� ������������������  기반����������� ������������������  설정v1.0.5

16

Page 23: Vagrant와 chef로 개발서버 구축 자동화하기

Vagrant����������� ������������������  :����������� ������������������  Quick����������� ������������������  Start����������� ������������������  -����������� ������������������  1/3

1.����������� ������������������  VirtualBox����������� ������������������  설치

17

Page 24: Vagrant와 chef로 개발서버 구축 자동화하기

Vagrant����������� ������������������  :����������� ������������������  Quick����������� ������������������  Start����������� ������������������  -����������� ������������������  2/3

2.����������� ������������������  Vagrant����������� ������������������  설치

18

Page 25: Vagrant와 chef로 개발서버 구축 자동화하기

Vagrant����������� ������������������  :����������� ������������������  Quick����������� ������������������  Start����������� ������������������  -����������� ������������������  3/3

3.����������� ������������������  Ubuntu����������� ������������������  10.04����������� ������������������  가상머신����������� ������������������  설치����������� ������������������  및����������� ������������������  구동

$����������� ������������������  vagrant����������� ������������������  box����������� ������������������  add����������� ������������������  base����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  http://files.vagrantup.com/lucid32.box

[vagrant]����������� ������������������  Downloading����������� ������������������  with����������� ������������������  Vagrant::Downloaders::HTTP...[vagrant]����������� ������������������  Downloading����������� ������������������  box:����������� ������������������  http://files.vagrantup.com/lucid32.box

$����������� ������������������  vagrant����������� ������������������  init

A����������� ������������������  `Vagrantfile`����������� ������������������  has����������� ������������������  been����������� ������������������  placed����������� ������������������  in����������� ������������������  this����������� ������������������  directory.����������� ������������������  You����������� ������������������  are����������� ������������������  now����������� ������������������  ready����������� ������������������  to����������� ������������������  `vagrant����������� ������������������  up`����������� ������������������  your����������� ������������������  first����������� ������������������  virtual����������� ������������������  environment!����������� ������������������  Please����������� ������������������  read����������� ������������������  the����������� ������������������  comments����������� ������������������  in����������� ������������������  the����������� ������������������  Vagrantfile����������� ������������������  as����������� ������������������  well����������� ������������������  as����������� ������������������  documentation����������� ������������������  on����������� ������������������  `vagrantup.com`����������� ������������������  for����������� ������������������  more����������� ������������������  information����������� ������������������  on����������� ������������������  using����������� ������������������  Vagrant.

$����������� ������������������  vagrant����������� ������������������  up

[default]����������� ������������������  Importing����������� ������������������  base����������� ������������������  box����������� ������������������  'base'...

19

Page 26: Vagrant와 chef로 개발서버 구축 자동화하기

Vagrant����������� ������������������  기본지식����������� ������������������  :����������� ������������������  Command����������� ������������������  Line����������� ������������������  Interface

$����������� ������������������  vagrantUsage:����������� ������������������  vagrant����������� ������������������  [-v]����������� ������������������  [-h]����������� ������������������  command����������� ������������������  [<args>]

����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  -v,����������� ������������������  --version����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  Print����������� ������������������  the����������� ������������������  version����������� ������������������  and����������� ������������������  exit.����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  -h,����������� ������������������  --help����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  Print����������� ������������������  this����������� ������������������  help.

Available����������� ������������������  subcommands:����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  box����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  destroy����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  gem����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  halt����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  init����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  package����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  provision����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  reload����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  resume����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ssh����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ssh-config����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  status����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  suspend����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  up

For����������� ������������������  help����������� ������������������  on����������� ������������������  any����������� ������������������  individual����������� ������������������  command����������� ������������������  run����������� ������������������  `vagrant����������� ������������������  COMMAND����������� ������������������  -h`

CommandLineInterface

20

Page 27: Vagrant와 chef로 개발서버 구축 자동화하기

Vagrant����������� ������������������  기본지식����������� ������������������  :����������� ������������������  Box

Box����������� ������������������  :����������� ������������������  기본����������� ������������������  설정����������� ������������������  및����������� ������������������  OS가����������� ������������������  설치된����������� ������������������  VM����������� ������������������  템플릿����������� ������������������  이미지

메모리네트워크파일시스템운영체제공유폴더SSH...

21

Page 28: Vagrant와 chef로 개발서버 구축 자동화하기

Vagrant����������� ������������������  기본지식����������� ������������������  :����������� ������������������  Box

Box����������� ������������������  저장소

$����������� ������������������  vagrant����������� ������������������  box����������� ������������������  add����������� ������������������  ubuntu32����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  http://boxes.com/ubuntu32.box

$����������� ������������������  vagrant����������� ������������������  box����������� ������������������  add����������� ������������������  win2k����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  http://boxes.com/win2k.box

$����������� ������������������  vagrant����������� ������������������  box����������� ������������������  add����������� ������������������  centos51����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  http://boxes.com/centos51.box

22

Page 29: Vagrant와 chef로 개발서버 구축 자동화하기

Vagrant����������� ������������������  기본지식����������� ������������������  :����������� ������������������  Box

제공되는����������� ������������������  Box:����������� ������������������  http://www.vagrantbox.es/

23

Page 30: Vagrant와 chef로 개발서버 구축 자동화하기

Vagrant����������� ������������������  기본지식����������� ������������������  :����������� ������������������  Vagrantfile

Ruby����������� ������������������  기반에����������� ������������������  Vagrant����������� ������������������  프로젝트����������� ������������������  설정����������� ������������������  파일

# -*- mode: ruby -*-# vi: set ft=ruby :

Vagrant::Config.run do |config|

config.vm.box = "Ubuntu lucid 64" config.vm.box_url = "http://files.vagrantup.com/lucid64.box"

# config.vm.boot_mode = :headless# config.vm.network :hostonly, "192.168.10.1"# config.vm.network :bridged# config.vm.forward_port 80, 8080# config.vm.share_folder "v-data", "/vagrant_data", "../data"

end

24

Page 31: Vagrant와 chef로 개발서버 구축 자동화하기

Vagrant����������� ������������������  :����������� ������������������  개발환경����������� ������������������  구성하기����������� ������������������  -����������� ������������������  1/3

Box����������� ������������������  저장소

$����������� ������������������  vagrant����������� ������������������  package����������� ������������������  dev.box$����������� ������������������  scp����������� ������������������  dev.box����������� ������������������  [email protected]:...

형상관리����������� ������������������  저장소

$����������� ������������������  cat����������� ������������������  >����������� ������������������  Vagrantfile����������� ������������������  ����������� ������������������  ����������� ������������������  ....$����������� ������������������  svn����������� ������������������  add����������� ������������������  Vagrantfile$����������� ������������������  svn����������� ������������������  commit����������� ������������������  -m����������� ������������������  “개발서버����������� ������������������  구성”

25

Page 32: Vagrant와 chef로 개발서버 구축 자동화하기

Vagrant����������� ������������������  :����������� ������������������  개발환경����������� ������������������  구성하기����������� ������������������  -����������� ������������������  2/3

Box����������� ������������������  저장소

$����������� ������������������  vagrant����������� ������������������  package����������� ������������������  dev.box$����������� ������������������  scp����������� ������������������  dev.box����������� ������������������  [email protected]:...

형상관리����������� ������������������  저장소

$����������� ������������������  cat����������� ������������������  >����������� ������������������  Vagrantfile����������� ������������������  ����������� ������������������  ����������� ������������������  ....$����������� ������������������  svn����������� ������������������  add����������� ������������������  Vagrantfile$����������� ������������������  svn����������� ������������������  commit����������� ������������������  -m����������� ������������������  “개발서버����������� ������������������  구성”

26

Page 33: Vagrant와 chef로 개발서버 구축 자동화하기

Vagrant����������� ������������������  :����������� ������������������  개발환경����������� ������������������  구성하기����������� ������������������  -����������� ������������������  3/3

$����������� ������������������  svn����������� ������������������  checkout����������� ������������������  svn://...$����������� ������������������  vagrant����������� ������������������  up

$����������� ������������������  svn����������� ������������������  checkout����������� ������������������  svn://...$����������� ������������������  vagrant����������� ������������������  up

Box����������� ������������������  저장소

형상관리����������� ������������������  저장소

27

Page 34: Vagrant와 chef로 개발서버 구축 자동화하기

Vagrant����������� ������������������  :����������� ������������������  해결되지����������� ������������������  않은����������� ������������������  문제점...

이미...����������� ������������������  ����������� ������������������  ����������� ������������������  Box는...����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  배포되었다!?

28

Page 35: Vagrant와 chef로 개발서버 구축 자동화하기

Provisioning

프로비저닝(Provisioning)

29

Page 36: Vagrant와 chef로 개발서버 구축 자동화하기

Provisioning

Configuration����������� ������������������  /����������� ������������������  System����������� ������������������  Management����������� ������������������  Tools

Shell

30

Page 37: Vagrant와 chef로 개발서버 구축 자동화하기

Provisioning

Configuration����������� ������������������  /����������� ������������������  System����������� ������������������  Management����������� ������������������  Tools

Shell

31

Page 38: Vagrant와 chef로 개발서버 구축 자동화하기

Provisioning

Configuration����������� ������������������  /����������� ������������������  System����������� ������������������  Management����������� ������������������  Tools

Shell

32

Page 39: Vagrant와 chef로 개발서버 구축 자동화하기

Chef를����������� ������������������  소개합니다.

오픈����������� ������������������  소스����������� ������������������  시스템����������� ������������������  관리����������� ������������������  프레임워크OPSCODE(www.opscode.com)2009년����������� ������������������  1월에����������� ������������������  정식����������� ������������������  발표루비����������� ������������������  기반����������� ������������������  DSL(Domain����������� ������������������  Specific����������� ������������������  Language)풍부한����������� ������������������  기반����������� ������������������  설정����������� ������������������  파일����������� ������������������  제공(github.com/opscode/cookbooks)

33

Page 40: Vagrant와 chef로 개발서버 구축 자동화하기

Chef����������� ������������������  :����������� ������������������  뭘����������� ������������������  할����������� ������������������  수����������� ������������������  있나요?

34

Page 41: Vagrant와 chef로 개발서버 구축 자동화하기

Chef����������� ������������������  :����������� ������������������  뭘����������� ������������������  할����������� ������������������  수����������� ������������������  있나요?

복잡해!!!

35

Page 42: Vagrant와 chef로 개발서버 구축 자동화하기

Chef����������� ������������������  :����������� ������������������  뭘����������� ������������������  할����������� ������������������  수����������� ������������������  있나요?

1.����������� ������������������  MySql����������� ������������������  설치법����������� ������������������  작성

2.����������� ������������������  설치법����������� ������������������  +����������� ������������������  대상����������� ������������������  서버를����������� ������������������  Chef에게����������� ������������������  전달

4.����������� ������������������  MySql이����������� ������������������  설치된����������� ������������������  서버로����������� ������������������  변신

3.����������� ������������������  설치법으로����������� ������������������  서버����������� ������������������  설정

36

Page 43: Vagrant와 chef로 개발서버 구축 자동화하기

Chef����������� ������������������  기본����������� ������������������  지식����������� ������������������  :����������� ������������������  Cookbook

Recipe Metadata

Template Provider

37

Page 44: Vagrant와 chef로 개발서버 구축 자동화하기

Chef����������� ������������������  기본����������� ������������������  지식����������� ������������������  :����������� ������������������  Cookbook

https://github.com/opscode-cookbooks

38

Page 45: Vagrant와 chef로 개발서버 구축 자동화하기

Chef����������� ������������������  기본����������� ������������������  지식����������� ������������������  :����������� ������������������  Cookbook

mysql/recipes/client.rb

39

Page 46: Vagrant와 chef로 개발서버 구축 자동화하기

Chef����������� ������������������  기본����������� ������������������  지식����������� ������������������  :����������� ������������������  Workstation,����������� ������������������  Server,����������� ������������������  Node

Chef����������� ������������������  Server

Workstation Node

40

Page 47: Vagrant와 chef로 개발서버 구축 자동화하기

Chef����������� ������������������  기본����������� ������������������  지식����������� ������������������  :����������� ������������������  Workstation,����������� ������������������  Server,����������� ������������������  Node

Chef����������� ������������������  Server

Workstation Node

1.����������� ������������������  MySql����������� ������������������  CookbooK업로드

3.����������� ������������������  MySqlCookbook

으로����������� ������������������  서버����������� ������������������  구성

2.����������� ������������������  MySql����������� ������������������  서버����������� ������������������  구성해!

41

Page 48: Vagrant와 chef로 개발서버 구축 자동화하기

Chef����������� ������������������  기본����������� ������������������  지식����������� ������������������  :����������� ������������������  Workstation,����������� ������������������  Server,����������� ������������������  Node

Chef����������� ������������������  Server

Workstation Node

42

Page 49: Vagrant와 chef로 개발서버 구축 자동화하기

Chef����������� ������������������  기본����������� ������������������  지식����������� ������������������  :����������� ������������������  Workstation,����������� ������������������  Server,����������� ������������������  Node

Workstation Node

Chef����������� ������������������  Solo

43

Page 50: Vagrant와 chef로 개발서버 구축 자동화하기

개발서버����������� ������������������  구축����������� ������������������  자동화����������� ������������������  예제

+ +

44

Page 51: Vagrant와 chef로 개발서버 구축 자동화하기

개발서버����������� ������������������  구축����������� ������������������  자동화����������� ������������������  예제

Ubuntu����������� ������������������  64bit����������� ������������������  12.04

MySql����������� ������������������  설치새로운����������� ������������������  데이터베이스����������� ������������������  생성����������� ������������������  :����������� ������������������  KSUG

새로운����������� ������������������  사용자����������� ������������������  생성����������� ������������������  :����������� ������������������  KSUG

Host����������� ������������������  Machine에서����������� ������������������  Virtual����������� ������������������  

Machine::MySql����������� ������������������  접속되게����������� ������������������  설정

45

Page 52: Vagrant와 chef로 개발서버 구축 자동화하기

궁금해요?

46

Page 53: Vagrant와 chef로 개발서버 구축 자동화하기

47

Page 54: Vagrant와 chef로 개발서버 구축 자동화하기

http://www.flickr.com/photos/zcuervo/402403453/

http://www.flickr.com/photos/pahudson/2217562952/

http://www.flickr.com/photos/sparkleglowplug/80286190/

http://www.flickr.com/photos/hawk59/6038847752/

http://www.scalarium.com/features/automation/

http://wiki.opscode.com/pages/viewpage.action?pageId=7274862

이미지����������� ������������������  출처

참고자료http://h3.kthcorp.com/2012/session/index/S036

http://h3.kthcorp.com/2012/session/index/S026

http://wiki.opscode.com/display/chef/Home

http://vagrantup.com/

http://www.flickr.com/photos/wwworks/4759535950/

48