Upload
yuto-ogi
View
778
Download
2
Embed Size (px)
Citation preview
itamaeで 一撃サーバー構築
Hamamatsu.rb #58 @jacoyutorius
itamae
• サーバーのプロビジョニングツール
• サーバーにインストールするパッケージや ミドルウェアのインストール内容や設定をRubyのコードで記述する
package "nginx" do action :install end
• サーバーの”あるべき状態”を定義したファイルに従ってパッケージやミドルウェアのインストールや設定を自動的にかつ一括で行うツール
• Linuxディストリビューションによる違いを吸収してくれたりする
プロビジョニングツール
• 冪等性(何度実行しても同じ状態になる)
• プログラムから扱いやすい形式のファイルで定義することで、バージョン管理ツールによる差分管理が容易
• Chef, Puppet, Ansibleなど
プロビジョニングツール
覚える用語
・レシピ ・リソース
レシピ
• パッケージやミドルウェアのインストール内容をRubyで記述したもの
package "nginx" do action :install end
リソース• 対象サーバー上にて実行する命令
package "nginx" do action :install end
リソース• package
• file
• directory
• git
• remote_file
• template
• user
• group
• execute
install nginx
package "nginx" do action :install end
create user
user "yuto" do action :create end
create group
group "yuto" do action :create end
template
template "/root/.bash_profile" do source "./templates/bash_profile.erb" variables(root_path: node[:root_path]) end
shell
execute “echo helloitamae" do user "root" command "echo helloitamae" end
$ tree
├── Gemfile
├── Vagrantfile
├── cookbooks
│ └── recipes
│ ├── ruby_install.rb
│ └── templates
└── servers
└── target_server
└── node.yml
install (gem)
gem install itamae
install (package)
> echo 'deb https://dl.bintray.com/itamae/itamae trusty contrib' | sudo tee /etc/apt/sources.list.d/itamae.list
> sudo apt-key adv --keyserver keyserver.ubuntu.com --recv D401AB61
> sudo apt-get install itamae
Ubuntu 14.04 trustlyhttps://github.com/itamae-kitchen/omnibus-itamae
実行(local)
itamae local ruby_install.rb
実行(vagrant)
itamae ssh --vagrant -h hostname ruby_install.rb
実行(ssh)
itamae ssh -h hostname ruby_install.rb
色々オプションをつけて結局こうなる
bundle exec itamae ssh -h hostname cookbooks/recipes/ruby_install.rb -y servers/servername/node.yml -l debug
オプション
dry-run, -d - 試しに実行したい log-level, -l - 詳細なログが見たいとき node-yaml, -y - サーバーの固有情報を記述したファイル(node.yml)のパスを指定
and more …
plugins
•itamae-plugin-recipe-rbenv
•itamae-plugin-resource-iptables
•itamae-plugin-recipe-minecraft
•itamae-plugin-resource-aws
•and more... (https://rubygems.org/search?query=itamae-plugin)
plugins
plugin usage
Gemfile
gem "itamae" gem "itamae-plugin-recipe-rbenv"
覚えるリソースも数種類しかないのでgemの中身も読みやすい。
itamae-plugin-recipe-rbenvのコア部分(system.rb)
itamae-plugin-recipe-rbenv
• 使われているのはgit, package, file, executeリソースくらい
• インストールパスやrubyのバージョンはnode.ymlに定義。 ディストリビューションによる分岐はSpecinfraから取得
itamae-plugin-recipe-rbenv
system.rb
node.yml
system.rb
まとめ
まとめと今後• itamae楽しい
• 上手く動くと全能感
• 多少ハマるところもある (VM宛てに実行した時と実行結果が違うとか。OSイメージの問題かもしれない)
• 実運用ではサーバー構築手順書をレシピ化した(検証中)
• 出来上がったサーバーのテスト( => Serverspec)
otto• 何も考えずにとりあえず開発環境の入ったVMが欲しい場合はotto
• Ruby / PHP / Go / node.jsのインストールされたVMが一発で手に入る(尚、バージョンの指定はできない模様)
おわりHamamatsu.rb #58
@jacoyutorius