vagrant ,chef ,git を使いcakephpを立ち上げるまでの道のり。NO3
knife-solo を使うやり方とvagrantfileのconfig.vm.provision :chef_solo do |chef|の項目を使うやりかたをごっちゃに考えていた。
以下のファイル構成で進める
Sites ├── cakephp_sample │ ├── cookbooks │ │ ├── group │ │ │ ├── CHANGELOG.md │ │ │ ├── README.md │ │ │ ├── attributes │ │ │ ├── definitions │ │ │ ├── files │ │ │ │ └── default │ │ │ ├── libraries │ │ │ ├── metadata.rb │ │ │ ├── providers │ │ │ ├── recipes │ │ │ │ └── default.rb │ │ │ ├── resources │ │ │ └── templates │ │ │ └── default │ │ ├── httpd │ │ │ ├── CHANGELOG.md │ │ │ ├── README.md │ │ │ ├── attributes │ │ │ ├── definitions │ │ │ ├── files │ │ │ │ └── default │ │ │ ├── libraries │ │ │ ├── metadata.rb │ │ │ ├── providers │ │ │ ├── recipes │ │ │ │ └── default.rb │ │ │ ├── resources │ │ │ └── templates │ │ │ └── default │ │ ├── mysql │ │ │ ├── CHANGELOG.md │ │ │ ├── README.md │ │ │ ├── attributes │ │ │ ├── definitions │ │ │ ├── files │ │ │ │ └── default │ │ │ ├── libraries │ │ │ ├── metadata.rb │ │ │ ├── providers │ │ │ ├── recipes │ │ │ │ └── default.rb │ │ │ ├── resources │ │ │ └── templates │ │ │ └── default │ │ └── php │ │ ├── CHANGELOG.md │ │ ├── README.md │ │ ├── attributes │ │ ├── definitions │ │ ├── files │ │ │ └── default │ │ ├── libraries │ │ ├── metadata.rb │ │ ├── providers │ │ ├── recipes │ │ │ └── default.rb │ │ ├── resources │ │ └── templates │ │ └── default │ └── vagrantfile
レシピの編集
$ vi cookbooks/httpd/recipes/default.rb
service "iptables" do action [:stop,:disable] end #php mysql-server httpd %w{php mysql-server httpd}.each do |p| package p do action :install end end service "httpd" do action [:start,:enable] end
recipeを反映する場合は vagrant provisionを実行する
$ vagrant provision
vagrant,chef の設定。起動するまで。NO.2
VirtualBox(Oracle)のダウンロードページが元に戻ってたのでインストール。
そして
vagrant box add
$ vagrant box add centos64 http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.4-x86_64-v20130309.box
vagrant up
[default] The guest additions on this VM do not match the install version of VirtualBox! This may cause things such as forwarded ports, shared folders, and more to not work properly. If any of those things fail on this machine, please update the guest additions and repackage the box. Guest Additions Version: 4.2.8 VirtualBox Version: 4.2.18
とりあえずスルー。
vagrant ssh
.ssh/configにHostの書き込み
$ vagrant ssh-config --host mm >>~/.ssh/config $ ssh mm Warning: Permanently added '[127.0.0.1]:2222' (RSA) to the list of known hosts.
このwarningがどうも消えない。スルー。
knife solo
$ knife solo prepare mm $ knife solo init chef-repo $ knife cookbook create hello -o site-cookbooks
レシピの作成
./site-cookbooks/hello/recipes/default.rb
package "vim-enhanced" do action :install end #service iptables stop #chkconfig iptables off service "iptables" do action [:stop,:disable] end
nodeファイル編集
{ "run_list":[ "recipe[hello]" ] }
ファイル構成
. └── vagrant ├── chef │ ├── chef-repo │ │ ├── cookbooks │ │ ├── data_bags │ │ ├── nodes │ │ │ └── mm.json │ │ ├── roles │ │ └── site-cookbooks │ │ ├── group │ │ │ ├── CHANGELOG.md │ │ │ ├── README.md │ │ │ ├── attributes │ │ │ ├── definitions │ │ │ ├── files │ │ │ │ └── default │ │ │ ├── libraries │ │ │ ├── metadata.rb │ │ │ ├── providers │ │ │ ├── recipes │ │ │ │ └── default.rb │ │ │ ├── resources │ │ │ └── templates │ │ │ └── default │ │ ├── hello │ │ │ ├── CHANGELOG.md │ │ │ ├── README.md │ │ │ ├── attributes │ │ │ ├── definitions │ │ │ ├── files │ │ │ │ └── default │ │ │ ├── libraries │ │ │ ├── metadata.rb │ │ │ ├── providers │ │ │ ├── recipes │ │ │ │ └── default.rb │ │ │ ├── resources │ │ │ └── templates │ │ │ └── default │ │ ├── httpd │ │ │ ├── CHANGELOG.md │ │ │ ├── README.md │ │ │ ├── attributes │ │ │ ├── definitions │ │ │ ├── files │ │ │ │ └── default │ │ │ ├── libraries │ │ │ ├── metadata.rb │ │ │ ├── providers │ │ │ ├── recipes │ │ │ │ └── default.rb │ │ │ ├── resources │ │ │ └── templates │ │ │ └── default │ │ ├── mysql │ │ │ ├── CHANGELOG.md │ │ │ ├── README.md │ │ │ ├── attributes │ │ │ ├── definitions │ │ │ ├── files │ │ │ │ └── default │ │ │ ├── libraries │ │ │ ├── metadata.rb │ │ │ ├── providers │ │ │ ├── recipes │ │ │ │ └── default.rb │ │ │ ├── resources │ │ │ └── templates │ │ │ └── default │ │ └── php │ │ ├── CHANGELOG.md │ │ ├── README.md │ │ ├── attributes │ │ ├── definitions │ │ ├── files │ │ │ └── default │ │ ├── libraries │ │ ├── metadata.rb │ │ ├── providers │ │ ├── recipes │ │ │ └── default.rb │ │ ├── resources │ │ └── templates │ │ └── default │ └── nodes │ └── mm.json └── vagrantfile
vagrantfileの編集
Vagrant::Config.run do |config| config.vm.box = "Cent64" config.vm.network :hostonly, "192.168.33.77" config.vm.provision :chef_solo do |chef| chef.cookbooks_path = "./chef" chef.add_recipe "hello" end end
vagrant,chef の設定。起動するまで。
treeコマンドが入ってなかったのでhomebrewからインストール
$ brew install tree
他にもchef,vagrant,knife-soloも。
$ gem install chef $ gem install vagrant $ gem install knife-solo
knife-soloの予備知識
knife-solo DESCRIPTION: knife-solo adds a handful of commands that aim to make working with chef-solo as powerful as chef-server. It currently adds 5 subcommands to knife: knife solo init is used to create a new directory structure (i.e. “kitchen”) that fits with Chef's standard structure and can be used to build and store recipes. knife solo prepare installs Chef on a given host. It's structured to auto-detect the target OS and change the installation process accordingly. knife solo cook uploads the current kitchen (Chef repo) to the target host and runs chef-solo on that host. knife solo bootstrap combines the two previous ones (prepare and cook). knife-solo also adds --solo command line option and +knife+ configuration parameter to knife bootstrap that can be used for triggering “knife solo bootstrap” instead of the normal template based chef-client bootstrap. knife solo clean removes the uploaded kitchen from the target host. Preliminary Windows support for “knife solo cook” is available (see below).
次に仮想環境を整えるためVirtualBoxをインストールする。が
このサイトのセキュリティ証明書は失効しています www.virtualbox.org にアクセスしようとしましたが、サーバーから提示された証明書は有効期限が切れています。この証明書の有効期限が切れた後に証明書がセキュリティ侵害を受けたのかどうかについて確認できる情報はありません。つまり Google Chrome では、悪意のあるユーザーでなく www.virtualbox.org と確かに通信していることを保証することはできません。お使いのパソコンの時刻は現在 2013年10月5日土曜日18:41:55 に設定されています。時刻が正しくない場合は、エラーを修正してからこのページを更新してください。 先に進まないでください。このサイトについて今回初めてこの警告メッセージが表示された場合は特に注意が必要です。 このまま続行 セキュリティで保護されたページに戻る ヘルプ情報
どうもできない。
政府機関の一部が昨日してないのが関係してる??
ruby update
ruby -v :ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]
ruby1.9以上にする。
インストール
- homebrew
$ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
- Fink
Fink は Open Source ソフトウェアなどの Unix の世界を Darwin や Mac OS X で使えるようにするためのプロジェクトです。
XcodeのcommandLineToolをインストール
- ruby-build
- rbenv
- zshを使う
Z Shell の環境設定
Z Shell のあらゆる機能を活用するためには、環境設定ファイルを書いて Z Shell にそのファイルを読み込ませる必要があります。現在、University of California, Santa Cruz の William G. Scott 博士のイニシアティブにより、Mac OS X の Z Shell 環境を構築するプロジェクトが動いています。私もこのプロジェクトに参加させていただいています。この環境設定パッケージをインストールすれば、Mac 上で Z Shell を快適に利用できます。このパッケージを、X線結晶構造解析を意識して少し手を加えたものを準備しました。良ければ使ってください。インストール方法を以下に示します。
Z Shell
zsh,Finkからアップデータするのは断念。
代わりにOS X Mountain Lion に Homebrew + rbenv で Ruby 1.9.3 をインストールしたを参考にしてみる。
だめだ・・
次Mac OS X rbenvでRubyのバージョンを切り替えるをためす。
出来た出来た!!
どうも環境変数の設定が出来てなかったみたい。
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
$ exec $SHELL -l
vagrant ssh
知らずに使ってた。
SSH CONFIG Command: vagrant ssh-config This will output valid configuration for an SSH config file to SSH into the running Vagrant machine from ssh directly (instead of using vagrant ssh). OPTIONS --host NAME - Name of the host for the outputted configuration.
vagrant ,chef ,git を使いcakephpを立ち上げるまでの道のり。
OS X 10.8.5
vagrant 1.0.7
chef 11.6.0
knife-solo 0.3.0
git 1.8.3.4 (Apple Git-47)
vagrant up
$cd Sites/centos
$vagrant init
sshアクセスできるようにする
* ~/.ssh/configに
Host 192.168.50.*
IdentityFile~/.vagrant.d/insecure_private_key
User vagrant
もしくは
*vagrant ssh-config --host example >> ~/.ssh/config
chefレポジトリを作成
一緒にgit管理もはじめる
$knife solo init chef-repo
$cd chef-repo
$git init
$git add .
$git commit -m 'first commit'
knife solo prepare
$knife solo prepare okaki
$git add nodes/okaki.json
$git commit -m 'example'
クックブック作成 & レシピ編集
$knife cookbook create hello -o site-cookbooks
あとはレシピやjsonファイルを編集
Chef solo 実行
$knife solo cook okaki
失敗。。。
dot installのchefレッスンを一からやってみる。
続きを読む