KEMBAR78
Chef introduction | PDF
Chef	
  introduc.on	
Touch	
  the	
  chef-­‐solo
Agenda	
1. Goal	
  
2. About	
  Chef	
  
3. Install	
  Chef	
  
4. Chef	
  Basic	
  Usage
Agenda	
1. Goal	
  
2. About	
  Chef	
  
3. Install	
  Chef	
  
4. Chef	
  Basic	
  Usage
Goal	
1. Learn	
  basic	
  knowledge	
  of	
  Chef	
  
2. Learn	
  basic	
  command	
  of	
  Chef-­‐solo	
  
3. Use	
  Chef-­‐solo	
  
Agenda	
1. Goal	
  
2. About	
  Chef	
  
3. Install	
  Chef	
  
4. Chef	
  Basic	
  Usage
About	
  Chef	
•  Chef	
  (Opscode)	
  developed	
  this	
  
–  hIp://www.getchef.com/blog/2013/12/09/chef-­‐the-­‐company-­‐
formerly-­‐known-­‐as-­‐opscode/	
  
•  System	
  configure	
  management	
  tool	
  using	
  
Ruby	
  
•  Similar	
  Tool	
  
– CFEngine	
  
– Puppet	
  
– Ansible	
  	
  
Specially	
•  idempotence	
  
– The	
  same	
  result	
  even	
  if	
  performed	
  mul.ple	
  .mes	
  
*	
  Chef	
  defines	
  the	
  last	
  server	
  configura.on	
  
•  Independent	
  to	
  plaVorm	
  
•  Reuse	
  cookbook	
  /	
  recipe	
  
– These	
  are	
  published	
  on	
  Community/Github	
  
•  We	
  can	
  construct	
  server	
  by	
  code	
  
•  We	
  can	
  manage	
  server	
  status	
  by	
  code	
  
Chef	
  Rela.onship	
From	
  official	
  
Repository	
  /	
  Cookbook	
  /	
  Recipe	
Repository	
  
Cookbook	
  
Recipe	
  
•  Repository:	
  The	
  loca.on	
  in	
  which	
  cookbooks,roles,	
  data	
  bags,	
  environment	
  
and	
  configura.on	
  files	
  are	
  stored	
  
•  Cookbook:	
  The	
  fundamental	
  unit	
  of	
  configura.on	
  and	
  policy	
  distribu.on	
  
•  Recipe:	
  The	
  most	
  fundamental	
  configura.on	
  element	
  within	
  the	
  organiza.on	
  
What	
  kind	
  of	
  vender	
  used	
  Chef	
• Facebook	
  
• Splunk	
  
• CyberAgent	
  
• GREE
Agenda	
1. Goal	
  
2. About	
  Chef	
  
3. Install	
  Chef	
  
4. Chef	
  Basic	
  Usage
Install	
  Chef	
  (Client)	
•  Package	
  
hIps://opscode-­‐omnibus-­‐packages.s3.amazonaws.com/el/6/
x86_64/chef-­‐11.14.2-­‐1.el6.x86_64.rpm	
  
hIps://opscode-­‐omnibus-­‐packages.s3.amazonaws.com/debian/6/
x86_64/chef_11.14.2-­‐1_amd64.deb	
  
•  Shell	
  
curl	
  -­‐L	
  hIps://www.opscode.com/chef/install.sh	
  |	
  
bash	
  
•  Gem	
  (not	
  recommend)	
  
gem	
  install	
  chef	
From	
  hIp://www.getchef.com/chef/install/	
  
Agenda	
1. Goal	
  
2. About	
  Chef	
  
3. Install	
  Chef	
  
4. Chef	
  Basic	
  Usage
Chef-­‐solo	
  Basic	
  Usage	
1. Repository	
  crea.on	
  (knife	
  solo	
  init	
  
[Path])	
  
2. Chef-­‐solo	
  config	
  fie	
  crea.on	
  
3. Get/Create	
  cookbook	
  
4. Node	
  file	
  included	
  run_list	
  crea.on	
  
5. Chef-­‐solo	
  execu.on	
  
1.	
  Repository	
  crea.on	
•  Command	
  
–  knife	
  solo	
  init	
  [Path]	
  
※Before	
  this	
  command,	
  setup	
  knife	
  through	
  [knife	
  configure]	
  
•  Detail	
  of	
  under	
  repository	
  
–  Cookbooks	
  :	
  The	
  store	
  of	
  published	
  cookbook	
  
–  data_bags	
  :	
  A	
  piacere	
  data	
  store	
  which	
  we	
  can	
  refer	
  
–  Environments	
  :	
  The	
  informa.on	
  to	
  map	
  an	
  organiza.on’s	
  
real-­‐life	
  workflow	
  
–  Nodes	
  :	
  The	
  informa.on	
  that	
  is	
  configured	
  to	
  be	
  
maintained	
  by	
  chef	
  client	
  
–  Roles	
  :	
  The	
  informa.on	
  to	
  define	
  certain	
  paIerns	
  and	
  
processes	
  
–  site-­‐cookbooks	
  :	
  The	
  store	
  of	
  self	
  cookbook
2.	
  Chef-­‐solo	
  Configure	
  File	
•  cookbook_path	
  
The	
  path	
  of	
  cookbooks	
  (This	
  is	
  separated	
  by	
  comma)	
  
•  file_backup_path	
  
The	
  path	
  of	
  backup	
  file	
  
Default:	
  /var/chef/backup	
  
•  file_cache_path	
  
The	
  path	
  to	
  cache	
  data	
  which	
  is	
  	
  temporary	
  and	
  
cookbook	
  
•  log_level	
  
The	
  level	
  of	
  log	
  which	
  is	
  wriIen	
  to	
  file	
  
Default:	
  auto	
  (other:	
  debug,	
  info,	
  warn,	
  error,	
  fatal)	
  
If	
  you	
  more	
  learn,	
  please	
  check	
  hIp://docs.getchef.com/config_rb_solo.html	
  
3.	
  Get/Create	
  cookbook	
•  In	
  the	
  case	
  to	
  get	
  external	
  such	
  as	
  community	
  
– The	
  environment	
  which	
  is	
  needed	
  proxy	
  
•  Write	
  the	
  followings	
  to	
  .chef/knife.rb	
  (Under	
  the	
  
repository)	
  
–  hIp_proxy	
  “hIp://VIP:PORT”	
  
–  hIps_proxy	
  hIp://VIP:PORT	
  
– knife	
  cookbook	
  site	
  download	
  “[Recipe-­‐Name]”	
  
•  We	
  can	
  get	
  the	
  file	
  formaIed	
  tar.gz	
  from	
  
hIps://supermarket.getchef.com/cookbooks	
  	
  
•  Ajer	
  unpacking,	
  we	
  need	
  to	
  move	
  it	
  to	
  cookbook	
  
directory	
  
3.	
  Get/Create	
  cookbook	
•  In	
  the	
  case	
  of	
  self	
  cookbook	
  
– knife	
  cookbook	
  create	
  [Recipe-­‐name]	
  –o	
  site-­‐
cookbooks	
  
– The	
  above	
  command	
  creates	
  unnecessary	
  
directories.	
  So	
  we	
  need	
  to	
  delete	
  these.	
  
– On	
  the	
  other	
  hand,	
  we	
  create	
  only	
  needed	
  
directories	
  by	
  mkdir	
  command	
  
3.	
  Detail	
  the	
  under	
  the	
  Recipe	
•  Detail	
  of	
  under	
  Recipe	
  
•  recipes	
  (default.rb	
  is	
  wriIen	
  to	
  main)	
  
The	
  processing	
  file	
  
•  Templates	
  
The	
  file	
  which	
  changes	
  dynamically	
  (such	
  as	
  configura.on	
  file)	
  
This	
  exten.on	
  is	
  .erb.	
  In	
  basic	
  usage,	
  target	
  file	
  is	
  set	
  under	
  this	
  
ajer	
  crea.ng	
  default	
  directory	
  
•  aIributes	
  (default	
  value	
  is	
  wriIen	
  on	
  default.rb)	
  
The	
  default	
  value	
  selng	
  file	
  
•  files	
  
The	
  file	
  which	
  not	
  change	
  (such	
  as	
  upload	
  file)	
  
In	
  basic	
  usage,	
  target	
  file	
  is	
  set	
  under	
  this	
  ajer	
  crea.ng	
  default	
  
directory	
  
If	
  you	
  more	
  learn,	
  please	
  check	
  hIp://docs.getchef.com/essen.als_cookbooks.h
4.	
  Node	
  file	
  crea.on	
•  Set	
  a	
  variable	
  value	
  
•  Set	
  recipe	
  which	
  we	
  use	
  (run_list)	
  
Reference	
•  公式サイト	
  
–  h#p://www.getchef.com/	
  
•  今更聞けない人の為の Chef	
  再入門	
–  h#p://blog.schoolwith.me/chef-­‐re-­‐introduc:on/	
  
•  Chef入門 ドットインストール	
–  hIp://do.nstall.com/lessons/basic_chef	
  
•  Chef入門	
  
–  hIp://tatsu-­‐zine.com/books/chef-­‐solo	
  
•  Chef活用ガイド	
  
–  hIp://books.rakuten.co.jp/rk/
fec960065935329eb2ae093098277f99/	
  

Chef introduction

  • 1.
  • 2.
    Agenda 1. Goal   2. About  Chef   3. Install  Chef   4. Chef  Basic  Usage
  • 3.
    Agenda 1. Goal   2. About  Chef   3. Install  Chef   4. Chef  Basic  Usage
  • 4.
    Goal 1. Learn  basic  knowledge  of  Chef   2. Learn  basic  command  of  Chef-­‐solo   3. Use  Chef-­‐solo  
  • 5.
    Agenda 1. Goal   2. About  Chef   3. Install  Chef   4. Chef  Basic  Usage
  • 6.
    About  Chef •  Chef  (Opscode)  developed  this   –  hIp://www.getchef.com/blog/2013/12/09/chef-­‐the-­‐company-­‐ formerly-­‐known-­‐as-­‐opscode/   •  System  configure  management  tool  using   Ruby   •  Similar  Tool   – CFEngine   – Puppet   – Ansible    
  • 7.
    Specially •  idempotence   – The  same  result  even  if  performed  mul.ple  .mes   *  Chef  defines  the  last  server  configura.on   •  Independent  to  plaVorm   •  Reuse  cookbook  /  recipe   – These  are  published  on  Community/Github   •  We  can  construct  server  by  code   •  We  can  manage  server  status  by  code  
  • 8.
  • 9.
    Repository  /  Cookbook  /  Recipe Repository   Cookbook   Recipe   •  Repository:  The  loca.on  in  which  cookbooks,roles,  data  bags,  environment   and  configura.on  files  are  stored   •  Cookbook:  The  fundamental  unit  of  configura.on  and  policy  distribu.on   •  Recipe:  The  most  fundamental  configura.on  element  within  the  organiza.on  
  • 10.
    What  kind  of  vender  used  Chef • Facebook   • Splunk   • CyberAgent   • GREE
  • 11.
    Agenda 1. Goal   2. About  Chef   3. Install  Chef   4. Chef  Basic  Usage
  • 12.
    Install  Chef  (Client) • Package   hIps://opscode-­‐omnibus-­‐packages.s3.amazonaws.com/el/6/ x86_64/chef-­‐11.14.2-­‐1.el6.x86_64.rpm   hIps://opscode-­‐omnibus-­‐packages.s3.amazonaws.com/debian/6/ x86_64/chef_11.14.2-­‐1_amd64.deb   •  Shell   curl  -­‐L  hIps://www.opscode.com/chef/install.sh  |   bash   •  Gem  (not  recommend)   gem  install  chef From  hIp://www.getchef.com/chef/install/  
  • 13.
    Agenda 1. Goal   2. About  Chef   3. Install  Chef   4. Chef  Basic  Usage
  • 14.
    Chef-­‐solo  Basic  Usage 1. Repository  crea.on  (knife  solo  init   [Path])   2. Chef-­‐solo  config  fie  crea.on   3. Get/Create  cookbook   4. Node  file  included  run_list  crea.on   5. Chef-­‐solo  execu.on  
  • 15.
    1.  Repository  crea.on • Command   –  knife  solo  init  [Path]   ※Before  this  command,  setup  knife  through  [knife  configure]   •  Detail  of  under  repository   –  Cookbooks  :  The  store  of  published  cookbook   –  data_bags  :  A  piacere  data  store  which  we  can  refer   –  Environments  :  The  informa.on  to  map  an  organiza.on’s   real-­‐life  workflow   –  Nodes  :  The  informa.on  that  is  configured  to  be   maintained  by  chef  client   –  Roles  :  The  informa.on  to  define  certain  paIerns  and   processes   –  site-­‐cookbooks  :  The  store  of  self  cookbook
  • 16.
    2.  Chef-­‐solo  Configure  File •  cookbook_path   The  path  of  cookbooks  (This  is  separated  by  comma)   •  file_backup_path   The  path  of  backup  file   Default:  /var/chef/backup   •  file_cache_path   The  path  to  cache  data  which  is    temporary  and   cookbook   •  log_level   The  level  of  log  which  is  wriIen  to  file   Default:  auto  (other:  debug,  info,  warn,  error,  fatal)   If  you  more  learn,  please  check  hIp://docs.getchef.com/config_rb_solo.html  
  • 17.
    3.  Get/Create  cookbook • In  the  case  to  get  external  such  as  community   – The  environment  which  is  needed  proxy   •  Write  the  followings  to  .chef/knife.rb  (Under  the   repository)   –  hIp_proxy  “hIp://VIP:PORT”   –  hIps_proxy  hIp://VIP:PORT   – knife  cookbook  site  download  “[Recipe-­‐Name]”   •  We  can  get  the  file  formaIed  tar.gz  from   hIps://supermarket.getchef.com/cookbooks     •  Ajer  unpacking,  we  need  to  move  it  to  cookbook   directory  
  • 18.
    3.  Get/Create  cookbook • In  the  case  of  self  cookbook   – knife  cookbook  create  [Recipe-­‐name]  –o  site-­‐ cookbooks   – The  above  command  creates  unnecessary   directories.  So  we  need  to  delete  these.   – On  the  other  hand,  we  create  only  needed   directories  by  mkdir  command  
  • 19.
    3.  Detail  the  under  the  Recipe •  Detail  of  under  Recipe   •  recipes  (default.rb  is  wriIen  to  main)   The  processing  file   •  Templates   The  file  which  changes  dynamically  (such  as  configura.on  file)   This  exten.on  is  .erb.  In  basic  usage,  target  file  is  set  under  this   ajer  crea.ng  default  directory   •  aIributes  (default  value  is  wriIen  on  default.rb)   The  default  value  selng  file   •  files   The  file  which  not  change  (such  as  upload  file)   In  basic  usage,  target  file  is  set  under  this  ajer  crea.ng  default   directory   If  you  more  learn,  please  check  hIp://docs.getchef.com/essen.als_cookbooks.h
  • 20.
    4.  Node  file  crea.on •  Set  a  variable  value   •  Set  recipe  which  we  use  (run_list)  
  • 21.
    Reference •  公式サイト   – h#p://www.getchef.com/   •  今更聞けない人の為の Chef  再入門 –  h#p://blog.schoolwith.me/chef-­‐re-­‐introduc:on/   •  Chef入門 ドットインストール –  hIp://do.nstall.com/lessons/basic_chef   •  Chef入門   –  hIp://tatsu-­‐zine.com/books/chef-­‐solo   •  Chef活用ガイド   –  hIp://books.rakuten.co.jp/rk/ fec960065935329eb2ae093098277f99/