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

進擊的OpsWorks

Hippo
March 05, 2014

 進擊的OpsWorks

Hippo

March 05, 2014
Tweet

Other Decks in Technology

Transcript

  1. instance 原本的構想 Git Agent Application Code Hook Script Deploy Check

    out 利⽤用Git Hook Script,呼叫instance 上的Agent。 將程式Checkout出來。
  2. 聽完⼩小聚Richard演講後的感想 •  驚! •  太讚了 •  OpsWorks 就是我們要的功能! •  網站還沒上線,還有機會換!

    •  看起來不難,Richard花了1個⽉月! •  GitHub上有Richard貢獻的Cookbook,應該 只要花1週就可以上⼿手! •  明天就開始動⼯工!
  3. 實際的狀況 •  從4/18-5/22花了⼀一個⽉月在部署OpsWorks •  不會Chef •  所以試了Chef-Server、Chef-Solo…! •  Cookbook不知從何寫起? • 

    不會Ruby •  Cookbook是⽤用Ruby的語法 •  測試時都要Commit到Git repository,再new ⼀一台 instance,每次都需花上15分鐘!(天呀~)
  4. Cookbook常⽤用的Resource 名稱 ⽤用途 package 套件(http://docs.opscode.com/resource_package.html) package "tar" do action :install

    end directory ⺫⽬目錄(http://docs.opscode.com/resource_directory.html) directory "/var/lib/foo" do owner "root" group "root" mode 00644 action :create end
  5. Cookbook常⽤用的Resource template 從template產⽣生檔案(http://docs.opscode.com/resource_template.html) template "/etc/sudoers" do source "sudoers.erb" mode 0440

    owner "root" group "root" variables({ :sudoers_groups => node[:authorization][:sudo][:groups], :sudoers_users => node[:authorization][:sudo][:users] }) end service 服務(http://docs.opscode.com/resource_service.html) service "example_service" do action :start end
  6. 設定Vagrantfile •  產⽣生Vagrantfile 利⽤用vagrant init來產⽣生 •  設定使⽤用berkshelf及berksfile的Path config.berkshelf.enabled = true

    config.berkshelf.berksfile_path = ”./mycookbook/Berksfile” •  設定vm在開機時,透過omnibus安裝指定的chef,⺫⽬目前 OpsWorks使⽤用的是Chef 11.4.4。 config.omnibus.chef_version = "11.4.4"
  7. 設定Vagrantfile(vm部份) config.vm.define :w1 do |app|! app.vm.hostname = 'w1'! app.vm.network :private_network,

    ip: "192.168.33.11"! app.vm.network 'public_network'! app.berkshelf.berksfile_path = ”./mycookbook/Berksfile"! app.vm.box = 'CentOS6.5’! app.vm.provision :chef_solo do |chef|! chef.json = loadJson('/Users/hippo/mylab/w1.json')! chef.json[:deploy][:wwwroot][:scm][:revision] = “”! chef.run_list = [! "recipe[udntv::hosts]",! "recipe[monit]",! "recipe[opsworks_initial_setup]",! "recipe[udntv::setup]",! "recipe[udntv::deploy]",! ]! end! end! vm名稱叫w1 IP 要執⾏行的recipe 使⽤用Box的名稱
  8. 設定Berksfile 建議加⼊入的cookbook設定! cookbook 'packages', path: '../opsworks-cookbooks/packages'! cookbook 'gem_support', path: '../opsworks-cookbooks/gem_support'!

    cookbook 'ssh_users', path: '../opsworks-cookbooks/ssh_users'! cookbook 'scm_helper', path: '../opsworks-cookbooks/scm_helper'! cookbook 'opsworks_initial_setup', path: '../opsworks-cookbooks/opsworks_initial_setup'! cookbook 'dependencies', path: '../opsworks-cookbooks/dependencies'! cookbook 'ruby', path: '../opsworks-cookbooks/ruby'! cookbook 'ruby_enterprise', path: '../opsworks-cookbooks/ruby_enterprise'! cookbook 'opsworks_rubygems', path: '../opsworks-cookbooks/opsworks_rubygems'! cookbook 'opsworks_bundler', path: '../opsworks-cookbooks/opsworks_bundler'! cookbook 'opsworks_commons', path: '../opsworks-cookbooks/opsworks_commons'! cookbook 'opsworks_nodejs', path: '../opsworks-cookbooks/opsworks_nodejs'! cookbook 'mod_php5_apache2', path: '../opsworks-cookbooks/mod_php5_apache2'! cookbook 'opsworks_agent_monit', path: '../opsworks-cookbooks/opsworks_agent_monit'! cookbook 'opsworks_java', path: '../opsworks-cookbooks/opsworks_java'! cookbook ‘apache2’, path: ‘../opsworks-cookbooks/apache2’
  9. 設定Berksfile •  加⼊入⾃自⼰己的cookbook cookbook ‘cookbook-name', path: ‘cookbook-path’ •  例如: cookbook

    'udntv', path: './udntv' cookbook 'yum', path: './yum' cookbook 'php', path: './php' cookbook 'build-essential', path: './build-essential' cookbook 'xml', path: './xml' cookbook 'openssl', path: './openssl' cookbook 'deploy', path: './deploy' cookbook 'nginx', path: './nginx' cookbook 'php-fpm', path: './php-fpm' cookbook 'memcached', path: './memcached' cookbook 'monit', path: './monit' cookbook 'apt', path: './apt'
  10. Vagrant 指令 •  vagrant up [vm-name] - 開機 •  vagrant

    ssh [vm-name] – 登⼊入⾄至vm •  vagrant provision [vm-name] – 重新執⾏行recipe •  vagrant halt [vm-name] – 關機 •  vagrant destory [vm-name] – 把機器砍掉
  11. 參考資料 •  Does OpsWorks work? - Richard Lee https://speakerdeck.com/dlackty/does-opsworks-work • 

    A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩 - Wen-Tien Chang http://www.slideshare.net/ihower/vagrant-osdc •  客製化 Vagrant Box http://blog.xuite.net/tkunlin/blog/139190227-%5B %E6%95%99%E5%AD%B8%5D+%E5%AE %A2%E8%A3%BD%E5%8C%96+Vagrant+Box