Upgrade to Pro — share decks privately, control downloads, hide ads and more …

インフラ構築の自動化・量産化

 インフラ構築の自動化・量産化

Avatar for AkimitsuHamaguchi

AkimitsuHamaguchi

July 11, 2014

Other Decks in Programming

Transcript

  1. Chefの理念 ~Infrastructure as CODE~ インフラをプログラミングしてコード化 Idempotence サーバのあるべき状態に管理 する「冪等性(べきとうせい) 」 手順ではなく状態を定義

    サーバの状態をコードという外部表 現で管理 あるべき状態に収束 冪等性によるあるべき状態 への収束を保証
  2. Chefの理念 ~Infrastructure as CODE~ インフラをプログラミングしてコード化 Idempotence サーバのあるべき状態に管理 する「冪等性(べきとうせい) 」 手順ではなく状態を定義

    サーバの状態をコードという外部表 現で管理 あるべき状態に収束 冪等性によるあるべき状態 への収束を保証 アプリケーション領域との切り分け アプリケーションのデプロイ以前まで のプロビジョニングを行う
  3. Chefの概要 レシピ Workstation Server node node node knife Cookbooks Recipes

    Chef-clientによって構築・設定 変更が行われるマシン
  4. Chefの概要 レシピ Workstation Server node node node Client Client Client

    knife Cookbooks Recipes 構築対象マシンでレシピに基づ いて構築・設定変更を行うクライ アントプログラム
  5. Chefの概要 レシピ Workstation Server node node node Client Client Client

    role Webサーバ DBサーバ Webサーバ knife Cookbooks Recipes Nodeの役割(特定のパターンと プロセス)を記述
  6. Chefの概要 レシピ Workstation Server node node node Client Client Client

    role Environment Webサーバ DBサーバ 本番機 Webサーバ ステージング 本番機 knife Cookbooks Recipes 環境ごとに設定内容を切り分ける
  7. Chefの概要 レシピ Workstation Server node node node Client Client Client

    role Environment Webサーバ DBサーバ 本番機 Webサーバ ステージング 本番機 ドメイン、ホスト名 knife Cookbooks Recipes Attributes ドメイン、ホスト名 テンプレートやレシピから参照でき る値を設定
  8. Chefの概要 Server WebUI # # Cookbook Name:: rcmd # Recipe::

    squid # # Copyright 2014, e-Agency # # All rights reserved - Do Not Redistribute # ##################################################### # munin ##################################################### package "squid" do action :install end service "squid" do supports :restart => true, :start=>true, :stop=>true action [ :enable,:start] end template "/etc/squid/squid.conf" do source "squid/squid.conf.erb" mode "0640" owner "squid" group "root" notifies :restart, 'service[squid]' end # iptables iptables_rule "default" iptables_rule "squid" Recipe
  9. Chefの概要 Server WebUI # # Cookbook Name:: rcmd # Recipe::

    squid # # Copyright 2014, e-Agency # # All rights reserved - Do Not Redistribute # ##################################################### # munin ##################################################### package "squid" do action :install end service "squid" do supports :restart => true, :start=>true, :stop=>true action [ :enable,:start] end template "/etc/squid/squid.conf" do source "squid/squid.conf.erb" mode "0640" owner "squid" group "root" notifies :restart, 'service[squid]' end # iptables iptables_rule "default" iptables_rule "squid" Recipe # # Customized configuration: # acl CONNECT method CONNECT acl allinternets src all acl localhost src 127.0.0.1/32 <% node['squid']['accessserver'].each do |fqdn, ipaddress| -%> acl <%= fqdn %> src <%= ipaddress %> <% end -%> # without any cache cache deny allinternets http_access allow localhost <% node['squid']['accessserver'].each do |fqdn, ipaddress| -%> http_access allow <%= fqdn %> <% end -%> http_access deny allinternets # http_port 3128 # hide client & proxy info forwarded_for off request_header_access Referer deny all request_header_access X-Forwarded-For deny all request_header_access Via deny all # Apache combined format Log emulate_httpd_log off logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" >Hs %<st ¥"%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh access_log /var/log/squid/access.log combined template
  10. Chefの概要 Server WebUI # # Cookbook Name:: rcmd # Recipe::

    squid # # Copyright 2014, e-Agency # # All rights reserved - Do Not Redistribute # ##################################################### # munin ##################################################### package "squid" do action :install end service "squid" do supports :restart => true, :start=>true, :stop=>true action [ :enable,:start] end template "/etc/squid/squid.conf" do source "squid/squid.conf.erb" mode "0640" owner "squid" group "root" notifies :restart, 'service[squid]' end # iptables iptables_rule "default" iptables_rule "squid" Recipe # # Customized configuration: # acl CONNECT method CONNECT acl allinternets src all acl localhost src 127.0.0.1/32 <% node['squid']['accessserver'].each do |fqdn, ipaddress| -%> acl <%= fqdn %> src <%= ipaddress %> <% end -%> # without any cache cache deny allinternets http_access allow localhost <% node['squid']['accessserver'].each do |fqdn, ipaddress| -%> http_access allow <%= fqdn %> <% end -%> http_access deny allinternets # http_port 3128 # hide client & proxy info forwarded_for off request_header_access Referer deny all request_header_access X-Forwarded-For deny all request_header_access Via deny all # Apache combined format Log emulate_httpd_log off logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" >Hs %<st ¥"%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh access_log /var/log/squid/access.log combined template HTTP(S) 通信でのやりとりを前提とした サーバ・クライアント式のモデル
  11. Chefの概要 Server WebUI # # Cookbook Name:: rcmd # Recipe::

    squid # # Copyright 2014, e-Agency # # All rights reserved - Do Not Redistribute # ##################################################### # munin ##################################################### package "squid" do action :install end service "squid" do supports :restart => true, :start=>true, :stop=>true action [ :enable,:start] end template "/etc/squid/squid.conf" do source "squid/squid.conf.erb" mode "0640" owner "squid" group "root" notifies :restart, 'service[squid]' end # iptables iptables_rule "default" iptables_rule "squid" Recipe # # Customized configuration: # acl CONNECT method CONNECT acl allinternets src all acl localhost src 127.0.0.1/32 <% node['squid']['accessserver'].each do |fqdn, ipaddress| -%> acl <%= fqdn %> src <%= ipaddress %> <% end -%> # without any cache cache deny allinternets http_access allow localhost <% node['squid']['accessserver'].each do |fqdn, ipaddress| -%> http_access allow <%= fqdn %> <% end -%> http_access deny allinternets # http_port 3128 # hide client & proxy info forwarded_for off request_header_access Referer deny all request_header_access X-Forwarded-For deny all request_header_access Via deny all # Apache combined format Log emulate_httpd_log off logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" >Hs %<st ¥"%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh access_log /var/log/squid/access.log combined template Rubyによる記述 HTTP(S) 通信でのやりとりを前提とした サーバ・クライアント式のモデル
  12. Chefの概要 Server WebUI # # Cookbook Name:: rcmd # Recipe::

    squid # # Copyright 2014, e-Agency # # All rights reserved - Do Not Redistribute # ##################################################### # munin ##################################################### package "squid" do action :install end service "squid" do supports :restart => true, :start=>true, :stop=>true action [ :enable,:start] end template "/etc/squid/squid.conf" do source "squid/squid.conf.erb" mode "0640" owner "squid" group "root" notifies :restart, 'service[squid]' end # iptables iptables_rule "default" iptables_rule "squid" Recipe # # Customized configuration: # acl CONNECT method CONNECT acl allinternets src all acl localhost src 127.0.0.1/32 <% node['squid']['accessserver'].each do |fqdn, ipaddress| -%> acl <%= fqdn %> src <%= ipaddress %> <% end -%> # without any cache cache deny allinternets http_access allow localhost <% node['squid']['accessserver'].each do |fqdn, ipaddress| -%> http_access allow <%= fqdn %> <% end -%> http_access deny allinternets # http_port 3128 # hide client & proxy info forwarded_for off request_header_access Referer deny all request_header_access X-Forwarded-For deny all request_header_access Via deny all # Apache combined format Log emulate_httpd_log off logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" >Hs %<st ¥"%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh access_log /var/log/squid/access.log combined template Rubyによる記述 HTTP(S) 通信でのやりとりを前提とした サーバ・クライアント式のモデル OS・ディストリビューションによる 違いも吸収