256bitの殺人メニュー

インフラエンジニアだったソリューションアーキテクトなくわののブログ。こちらのBlogは個人の意見となっていて会社とは全く関係ありません。お約束です。[twitter:@kuwa_tw]めんどくさがりが重い腰を上げて何かをアウトプットすることにどれほどの意味があるのかを試してみたいブログでもある。

Cookbookの管理を楽にするBerkshelfの使い方( ー`дー´)キリッ とか。

子供が生まれたり、職場では人事改革が行われたり、@さんがスマートフォンアプリエンジニアになったりと、生活が激変しつつある今日この頃みなさまいかがお過ごしでしょうか。
はい、乙カレー様です。くわのです。


職場ではずっとchef-server 1本で来ていたわけなのですが、ちょっと前からchef solo+Berkshelfを使い始めたりしている私達がいます。
きっとみなさんchef-serverとか強がりやがってやっと素直になりやがったなと思っていることでしょう。
(Chef-serverも使い方で便利ですよ)


ドキュメント読んだらいいのかと思ったりもするんだけどBerkshelfのドキュメントがあんま綺麗じゃなくて困るというw
ちゅーことで、ざっくり使い方を整理しました。あ、Berkshelfのバージョンは3です。

Berkshelf

BerkshelfはCookbookの依存性を管理するためのソフトウェアです。
主な目的としては2つあり、

  • Cookbookの依存性の確保
  • Cookbookのバージョン管理

です。
例えば、Webサーバを構築するための[webserver]という、Cookbookがあったとして、[webserver]は、nginxを使用するために[nginx]のCookbookに依存しているような場合などです。
更にCookbookバージョンが変わることによる冪等性の確保のため、Cookbookのバージョン管理も行えます。

Berkshelfのインストール

割愛、、、bundleとかで。

$ cat Gemfile 
source 'https://rubygems.org'

gem "berkshelf"
$ bundle install

Berkshelf用のCookbookのひな形作成

Berkshelfを実行するためのCookbookのひな形作成

$ berks cookbook berks-cookbook

Berkshelfの設定

まずは基本的なBerkshelfの動作設定についてですが、これはconfig.jsonに設定します。
デフォルトだとワーキングディレクトリ ~/.berkshelf/ 以下の config.json にあります。


なくてもデフォルトで動きますが、Githubに繋ぎたい場合等は設定が入りますので指定してください。


ちなみに、berkshelfのワーキングディレクトリを変更したい場合は環境変数 BERKSHELF_PATH を指定します。

ex.)
export BERKSHELF_PATH=/usr/local/etc/berkshelf/
config.jsonの設定項目

こんなかんじです。

- chef.chef_server_url - Chefサーバの管理画面URL
- chef.node_name - ChefのClientNameの設定、デフォルトはknifeがあればそこから取得
- chef.client_key - clientキーの設定。
- chef.validation_client_name - validateキー(Chefにおけるrootみたいなもの)の設定
- chef.validation_key_path - validateキー(Chefにおけるrootみたいなもの)ファイルの場所
- vagrant.vm.box - Vagrantで使用するBoxの名前の指定(default: Berkshelf-CentOS-6.3-x86_64-minimal)
- vagrant.vm.box_url - VirtualBoxのBoxのあるURLの指定 (default: https://dl.dropbox.com/u/31081437/Berkshelf-CentOS-6.3-x86_64-minimal.box)
- vagrant.vm.forward_port - host->guestでforwardするportの設定
- vagrant.vm.provision - Chefのprovisionerの指定、chef_solo or chef_client. (default: chef_solo)
- ssl.verify - SSL接続を確認するかどうか。(default: true)
- cookbook.copyright - 新しいCookbookを生成する際に含めるコピーライト表示
- cookbook.email - 新しいcookbookが作成された時にメールを飛ばす先. デフォルトはknifeがあればそこから取得
- cookbook.license - 新しいcookbookで使用するライセンス。 デフォルトはknifeがあればそこから取得
- github - Github credentials 必要なcookbookをダウンロードするときに使うものをHashのArrayで入れる。

Berksfile

次に取得するCookbookを指定するためのBerksfileを設置。
Berksfileに記述するCookbookはコミュニティクックブック、Berks-API、Gitレポジトリ、LocalFilePathなどを指定する事ができます。

Berksfileの設定項目

Berksfileの記述ですが、下に例を貼りました。
コミュニティCookbook等のBerks-API経由のものに関してはバージョン指定が可能ですし、Gitレポジトリ管理しているものに関してはTag指定での取得が可能です。
一般的にコミュニティCookbookはバージョン=Tag指定になっているものが多いので自分たちで作る際もそれに習っておくのが良いね。うん。
berkshelfの公式のAPI指定は前まではapi.berkshelf.comだったんですが、Supermarketのリリースにともなってhttps://supermarket.getchef.comに変更になったようです。
また、自分たちでBerks-APIを立てることもできます。依存関係を一括管理する場合は自分たちのBerks-APIを立てるのがいいと思います。
その場合はひろせさんのこちらの記事が参考になります(ありがとうございます)

# Berks-API指定
# source "https://api.berkshelf.com"
source "https://supermarket.getchef.com"

# コミュニティクックブック
cookbook 'yum'

# コミュニティクックブック(バージョン指定)
cookbook 'yum-epel' , ">= 0.4.0"

# Gitレポジトリ
cookbook 'ca_sysctl', git: 'http://git.example.com/ca-cookbooks/ca_sysctl.git'

# Gitレポジトリ(tag指定)
cookbook 'ca_td-agent', git: 'http://git.example.com/ca-cookbooks/ca_td-agent.git' , tag: "1.0.0"

# LocalFilePath
cookbook 'webserver', path: '/Users/kuwano/cookbook/directory/somewhere/webserver'
cookbook 'nginx-test', path: '/Users/kuwano/cookbook/directory/somewhere/nginx-test'
cookbook 'apache-test', path: '/Users/kuwano/cookbook/directory/somewhere/apache-test'

主要なコマンドの使い方

berksコマンドの主要な使い方について。コマンドリファレンス的な物があんまり無いんだよね、、、なんでか、、、。

Berkshelfの使い方の流れ

Berkshelfでの作業の流れは大体このようになるかと思います。

  • Berkshelfのひな形作成(berks cookbook berks-cookbook)
  • Cookbookのインストール(berks install)
  • (Cookbook記述作業)
  • Cookbookのアップデート(berks update [Cookbook名])
  • Cookbookのインストール(以下繰り返し)
Berksfileのバージョン確認

berks versionコマンド。

$ berks version
3.1.1
Berksfileのひな形作成

上でもやったberks cookbookです。

$ berks cookbook berks-cookbook
      create  berks-cookbook/files/default
      create  berks-cookbook/templates/default
      create  berks-cookbook/attributes
      create  berks-cookbook/libraries
      create  berks-cookbook/providers
      create  berks-cookbook/recipes
      create  berks-cookbook/resources
      create  berks-cookbook/recipes/default.rb
      create  berks-cookbook/metadata.rb
      create  berks-cookbook/LICENSE
      create  berks-cookbook/README.md
      create  berks-cookbook/CHANGELOG.md
      create  berks-cookbook/Berksfile
      create  berks-cookbook/Thorfile
      create  berks-cookbook/chefignore
      create  berks-cookbook/.gitignore
         run  git init from "./berks-cookbook"
      create  berks-cookbook/Gemfile
      create  .kitchen.yml
      append  Thorfile
      create  test/integration/default
      append  .gitignore
      append  .gitignore
      append  Gemfile
      append  Gemfile
You must run `bundle install' to fetch any new gems.
      create  berks-cookbook/Vagrantfile
cookbookのインストール

まず、Cookbookをberkshelfのワーキングディレクトリへとインストールしましょう。
berks installコマンドを使用します。
ここでインストールしたCookbookが実際のchef soloで使用されるCookbookとなります。

Resolving cookbook dependencies...
Fetching 'webserver' from http://git.example.com/ca-cookbooks/webserver.git (at master)
Fetching 'nginx-test' from http://git.example.com/ca-cookbooks/nginx-test.git (at master)
Fetching 'apache-test' from http://git.example.com/ca-cookbooks/apache-test.git (at master)
Fetching cookbook index from https://supermarket.getchef.com...
Using 'webserver' from http://git.example.com/ca-cookbooks/webserver.git (at master)
Using 'nginx-test' from http://git.example.com/ca-cookbooks/nginx-test.git (at master)
Using 'apache-test' from http://git.example.com/ca-cookbooks/apache-test.git (at master)
Installing apt (2.4.0) from https://supermarket.getchef.com ([opscode] https://supermarket.getchef.com/api/v1)
Installing ark (0.8.2) from https://supermarket.getchef.com ([opscode] https://supermarket.getchef.com/api/v1)
Installing build-essential (2.0.4) from https://supermarket.getchef.com ([opscode] https://supermarket.getchef.com/api/v1)
Installing chef_handler (1.1.6) from https://supermarket.getchef.com ([opscode] https://supermarket.getchef.com/api/v1)
Installing consul (0.2.3) from https://supermarket.getchef.com ([opscode] https://supermarket.getchef.com/api/v1)
Installing cron (1.4.0) from https://supermarket.getchef.com ([opscode] https://supermarket.getchef.com/api/v1)
Installing erlang (1.5.4) from https://supermarket.getchef.com ([opscode] https://supermarket.getchef.com/api/v1)
Installing golang (1.3.0) from https://supermarket.getchef.com ([opscode] https://supermarket.getchef.com/api/v1)
Installing rabbitmq (3.2.2) from https://supermarket.getchef.com ([opscode] https://supermarket.getchef.com/api/v1)
Installing redisio (1.7.1) from https://supermarket.getchef.com ([opscode] https://supermarket.getchef.com/api/v1)
Installing rsyslog (1.12.2) from https://supermarket.getchef.com ([opscode] https://supermarket.getchef.com/api/v1)
Installing runit (1.5.10) from https://supermarket.getchef.com ([opscode] https://supermarket.getchef.com/api/v1)
Installing selinux (0.8.0) from https://supermarket.getchef.com ([opscode] https://supermarket.getchef.com/api/v1)
Installing sensu (1.0.0) from https://supermarket.getchef.com ([opscode] https://supermarket.getchef.com/api/v1)
Installing ulimit (0.3.2) from https://supermarket.getchef.com ([opscode] https://supermarket.getchef.com/api/v1)
Installing windows (1.31.0) from https://supermarket.getchef.com ([opscode] https://supermarket.getchef.com/api/v1)
Installing yum (3.2.0) from https://supermarket.getchef.com ([opscode] https://supermarket.getchef.com/api/v1)
Installing yum-epel (0.3.6) from https://supermarket.getchef.com ([opscode] https://supermarket.getchef.com/api/v1)
Installing yum-erlang_solutions (0.2.0) from https://supermarket.getchef.com ([opscode] https://supermarket.getchef.com/api/v1)
Installing yum-repoforge (0.3.0) from https://supermarket.getchef.com ([opscode] https://supermarket.getchef.com/api/v1)


このタイミングで作成される、Berksfile.lockにインストールされたCookbookのバージョンや、依存関係の情報が含まれています。
Berksfile.lockファイルが既に存在していればその記述バージョンのCookbookがインストールされます。

DEPENDENCIES
  apt
  consul
  cron
  selinux
  sensu
  webserver
    git: http://git.example.com/ca-cookbooks/webserver.git
    revision: 998d3e415e43c900e3f043513fa72bff6b1441c0
  yum
  yum-epel

GRAPH
  apt (2.4.0)
  ark (0.8.2)
  build-essential (2.0.4)
  chef_handler (1.1.6)
  consul (0.2.3)
    ark (~> 0.8.0)
    golang (~> 1.3.0)
    runit (>= 0.0.0)
    yum-repoforge (>= 0.0.0)
  cron (1.4.0)
  erlang (1.5.4)
    apt (>= 1.7.0)
    build-essential (>= 0.0.0)
    yum (~> 3.0)
    yum-epel (>= 0.0.0)
    yum-erlang_solutions (>= 0.0.0)
  golang (1.3.0)
  rabbitmq (3.2.2)
    erlang (>= 0.9.0)
  redisio (1.7.1)
    ulimit (>= 0.1.2)
  rsyslog (1.12.2)
  runit (1.5.10)
    build-essential (>= 0.0.0)
    yum (~> 3.0)
    yum-epel (>= 0.0.0)
  selinux (0.8.0)
  sensu (1.0.0)
    apt (>= 0.0.0)
    rabbitmq (>= 2.0.0)
    redisio (>= 1.7.0)
    windows (>= 1.8.8)
    yum (>= 0.0.0)
  ulimit (0.3.2)
  webserver (0.1.1)
    apt (>= 0.0.0)
    rsyslog (>= 0.0.0)
    selinux (>= 0.0.0)
    sensu (>= 0.0.0)
    yum (>= 0.0.0)
    yum-epel (>= 0.0.0)
  windows (1.31.0)
    chef_handler (>= 0.0.0)
  yum (3.2.0)
  yum-epel (0.3.6)
    yum (~> 3.0)
  yum-erlang_solutions (0.2.0)
    yum (~> 3.0)
  yum-repoforge (0.3.0)
    yum (~> 3.0)
    yum-epel (>= 0.0.0)
新しいバージョンのCookbookがないか確認

コミュニティクックブックはすごいスピードでリリースされるので、インストールしたタイミングから新しいCookbookが出てることも少なくありません。新しいCookbookの存在を確認するにはberks outdatedを使います。
もしCookbookの更新があればこのように出力されます。

$ berks outdated
The following cookbooks have newer versions:
  * ark (0.8.2 => 0.9.0) [https://supermarket.getchef.com]
  * consul (0.2.3 => 0.3.0) [https://supermarket.getchef.com]
  * erlang (1.5.4 => 1.5.6) [https://supermarket.getchef.com]
  * golang (1.3.0 => 1.4.0) [https://supermarket.getchef.com]
  * sensu (1.0.0 => 2.0.0) [https://supermarket.getchef.com]
  * windows (1.31.0 => 1.34.0) [https://supermarket.getchef.com]
  * yum (3.2.0 => 3.2.2) [https://supermarket.getchef.com]
  * yum-epel (0.3.6 => 0.4.0) [https://supermarket.getchef.com]
Cookbookを最新状態に更新

berks updateコマンドを使用する事でberks outdatedで示されたような変更を適用する事が出来ます。
berks updateを引数を指定しなければ、全Cookbookの強制アップデートになりますが、これを行うとCookbookの挙動が変わった場合に動作が意図したものでなくなる場合があるので、テストなどを行った上で実行しましょう。


実行時にBerksfile.lockが更新されます。


berks update [Cookbook名]
とすることで、Cookbook毎にアップデートが可能なので、アップデートが必要なCookbookのみアップデートするようにしましょう。

実行例としてはこのような感じになります。

$ berks update
Resolving cookbook dependencies...
Fetching 'webserver' from http://git.example.com/ca-cookbooks/webserver.git (at master)
Fetching 'nginx-test' from http://git.example.com/ca-cookbooks/nginx-test.git (at master)
Fetching 'apache-test' from http://git.example.com/ca-cookbooks/apache-test.git (at master)
Fetching cookbook index from https://supermarket.getchef.com...
Using 'webserver' from http://git.example.com/ca-cookbooks/webserver.git (at master)
Using 'nginx-test' from http://git.example.com/ca-cookbooks/nginx-test.git (at master)
Using 'apache-test' from http://git.example.com/ca-cookbooks/apache-test.git (at master)
Using apt (2.4.0)
Using ark (0.8.2)
Using build-essential (2.0.4)
Using chef_handler (1.1.6)
Installing consul (0.3.0) from https://supermarket.getchef.com ([opscode] https://supermarket.getchef.com/api/v1)
Using cron (1.4.0)
Installing erlang (1.5.6) from https://supermarket.getchef.com ([opscode] https://supermarket.getchef.com/api/v1)
Using golang (1.3.0)
Using rabbitmq (3.2.2)
Using redisio (1.7.1)
Using rsyslog (1.12.2)
Using runit (1.5.10)
Using selinux (0.8.0)
Installing sensu (2.0.0) from https://supermarket.getchef.com ([opscode] https://supermarket.getchef.com/api/v1)
Using ulimit (0.3.2)
Using webserver (0.1.1) from http://git.example.com/ca-cookbooks/webserver.git (at master)
Installing windows (1.34.0) from https://supermarket.getchef.com ([opscode] https://supermarket.getchef.com/api/v1)
Installing yum (3.2.2) from https://supermarket.getchef.com ([opscode] https://supermarket.getchef.com/api/v1)
Installing yum-epel (0.4.0) from https://supermarket.getchef.com ([opscode] https://supermarket.getchef.com/api/v1)
Using yum-erlang_solutions (0.2.0)
Using yum-repoforge (0.3.0)


個別に実行した場合はこのようになります。

$ berks update webserver
Resolving cookbook dependencies...
Fetching 'webserver' from http://git.example.com/ca-cookbooks/webserver.git (at master)
Fetching cookbook index from https://supermarket.getchef.com...
Using apt (2.4.0)
Using ark (0.8.2)
(snip)
Using webserver (0.1.1) from http://git.example.com/ca-cookbooks/webserver.git (at master)
Using windows (1.34.0)
Using yum (3.2.2)
Using yum-epel (0.4.0)
Using yum-erlang_solutions (0.2.0)
Using yum-repoforge (0.3.0)
現状使用されているCookbookを一括で出力

berkshelfで取得したCookbookを実行するための一般的な方法としてはknife soloが一般的だと思いますが。
各サーバにCookbookを直接配ったり、CI用途等でサーバにCookbookをおきたいときがあるかもしれません。


その場合にはberks vendorコマンドでCookbook群を出力します。
デフォルトではberkshelf実行ディレクトリ配下のberks-cookbook/ディレクトリに出力されます。

$ berks vendor
Resolving cookbook dependencies...
Using apt (2.4.0)
Using ark (0.8.2)
Using build-essential (2.0.4)
Using chef_handler (1.1.6)
Using consul (0.2.3)
Using cron (1.4.0)
Using erlang (1.5.4)
Using golang (1.3.0)
Using rabbitmq (3.2.2)
Using redisio (1.7.1)
Using rsyslog (1.12.2)
Using runit (1.5.10)
Using selinux (0.8.0)
Using sensu (1.0.0)
Using ulimit (0.3.2)
Using webserver (0.1.1) from http://git.example.com/ca-cookbooks/webserver.git (at master)
Using windows (1.31.0)
Using yum (3.2.0)
Using yum-epel (0.3.6)
Using yum-erlang_solutions (0.2.0)
Using yum-repoforge (0.3.0)
Vendoring apt (2.4.0) to /Users/akuwano/berksdir/berks-cookbooks/apt
Vendoring ark (0.8.2) to /Users/akuwano/berksdir/berks-cookbooks/ark
Vendoring build-essential (2.0.4) to /Users/akuwano/berksdir/berks-cookbooks/build-essential
Vendoring chef_handler (1.1.6) to /Users/akuwano/berksdir/berks-cookbooks/chef_handler
Vendoring consul (0.2.3) to /Users/akuwano/berksdir/berks-cookbooks/consul
Vendoring cron (1.4.0) to /Users/akuwano/berksdir/berks-cookbooks/cron
Vendoring erlang (1.5.4) to /Users/akuwano/berksdir/berks-cookbooks/erlang
Vendoring golang (1.3.0) to /Users/akuwano/berksdir/berks-cookbooks/golang
Vendoring rabbitmq (3.2.2) to /Users/akuwano/berksdir/berks-cookbooks/rabbitmq
Vendoring redisio (1.7.1) to /Users/akuwano/berksdir/berks-cookbooks/redisio
Vendoring rsyslog (1.12.2) to /Users/akuwano/berksdir/berks-cookbooks/rsyslog
Vendoring runit (1.5.10) to /Users/akuwano/berksdir/berks-cookbooks/runit
Vendoring selinux (0.8.0) to /Users/akuwano/berksdir/berks-cookbooks/selinux
Vendoring sensu (1.0.0) to /Users/akuwano/berksdir/berks-cookbooks/sensu
Vendoring ulimit (0.3.2) to /Users/akuwano/berksdir/berks-cookbooks/ulimit
Vendoring webserver (0.1.1) to /Users/akuwano/berksdir/berks-cookbooks/webserver
Vendoring windows (1.31.0) to /Users/akuwano/berksdir/berks-cookbooks/windows
Vendoring yum (3.2.0) to /Users/akuwano/berksdir/berks-cookbooks/yum
Vendoring yum-epel (0.3.6) to /Users/akuwano/berksdir/berks-cookbooks/yum-epel
Vendoring yum-erlang_solutions (0.2.0) to /Users/akuwano/berksdir/berks-cookbooks/yum-erlang_solutions
Vendoring yum-repoforge (0.3.0) to /Users/akuwano/berksdir/berks-cookbooks/yum-repoforge


tar.gz形式で出力したい場合はberks packageコマンドを使います。

$ berks package
Cookbook(s) packaged to /Users/akuwano/berksdir/cookbooks-1407290309.tar.gz


これらを実行したいサーバ等に持って行くことで単体での実行を行うことができます。

あるCookbookが他のどのCookbookから使われているか表示

berks contingent で調べることが出来ます。

$ berks contingent yum
Cookbooks in this Berksfile contingent upon 'yum':
  * sensu (1.0.0)
  * webserver (0.1.1)
  * yum-epel (0.3.6)

この場合、Cookbook[yum]は、webserverと、yum-epel, sensuから使われている事がわかります。

Cookbookのメタ情報表示

Cookbookのメタ情報を表示するコマンドはberks info [Cookbook名]です。

$ berks info yum
        Name: yum
     Version: 3.2.0
 Description: Configures various yum components on Red Hat-like systems
      Author: Chef
       Email: cookbooks@getchef.com
     License: Apache 2.0
   Platforms: redhat (>= 0.0.0)
              centos (>= 0.0.0)
              scientific (>= 0.0.0)
              amazon (>= 0.0.0)
              fedora (>= 0.0.0)
インストールされてるCookbook表示

現在インストールされてるCookbookを表示するのはberks listです。

$ berks list
Cookbooks installed by your Berksfile:
  * webserver (0.1.1) from http://git.example.com/ca-cookbooks/webserver.git (at master)
  * apt (2.4.0)
  * ark (0.8.2)
  * build-essential (2.0.4)
  * chef_handler (1.1.6)
(snip)
  * yum-epel (0.3.6)
  * yum-erlang_solutions (0.2.0)
  * yum-repoforge (0.3.0)
Cookbookの検索

berks search [Cookbook名で]コミュニティクックブックを検索できます。

$ berks search redis
php-redis (0.1.1)
redis (3.0.4)
redis-package (1.0.0)
redis-test (0.2.0)
redis2 (0.5.0)
redis_2_cookbook (0.3.3)
redisio (1.7.1)
現在使っているCookbookの実際のサーバ上での位置を表示する

Berkshelfを使っていると、~/.berkshelf/cookbooks/に同じような名前のCookbook(hoge-22a4059e11eab1f727ddf38f1160e04285e26cf9
hoge-33a4059e11eab1f727ddf38f1160e04285e26cc9 とか)が増えてきて、どっちが使ってる奴だよ、みたいになることがたまーにあるんですが、berks show 使うと今使っているCookbookが出力されます。

$ berks show hoge
/Users/akuwano/.berkshelf/cookbooks/hoge-22a4059e11eab1f727ddf38f1160e04285e26cf9


ということで、hoge-33a4059e11eab1f727ddf38f1160e04285e26cc9 は消しても問題ないわけですね。( ´∀`)つ ミ● <-[hoge-33a4059e11eab1f727ddf38f1160e04285e26cc9]

おまけ1:CookbookのChef Serverへのアップロード

もし、Berkshelfで使ったCookbookをChef-serverにアップロードしたい場合はberks uploadコマンドを使います。
Cookbookの管理にBerkshelfを使って、実行はchef client経由でしたい。バージョン管理はChef-server側で行いたい、等の場合はberks uploadしましょう。

$ berks upload
おまけ2:Cookbookの依存関係を画像出力

berks vizコマンドを使用すると管理しているCookbookの依存関係を図示したものが生成されます。
graphvizをインストール(brew等が簡単)してから実行してください。


こんなん↓

つかれた

最後の方ちょっと(ちょっと?)雑になってんなと思った方。それは正しい。
Berkshelfをこれから使う方にちょっとでも役に立てばいいなーとか思ったり思わなかったりします。


ではではー三(卍 〓ω〓))卍


Chef実践入門 ~コードによるインフラ構成の自動化 (WEB+DB PRESS plus)

Chef実践入門 ~コードによるインフラ構成の自動化 (WEB+DB PRESS plus)

boot2dockerのバージョンアップ時にハマった事やら

はい、どもども乙カレー様でつ。

boot2dockerをバージョンアップしたらちょっとハマった事をいくつかメモ。

もともと。前提。

もともとは1,2ヶ月前位に入れたboot2dockerで、入れ方は当時homebrewで入る物が若干古かったかなんかでGithubからwgetしてれる方法で。

mkdir -p ~/boot2docker
cd ~/boot2docker
wget https://github.com/boot2docker/boot2docker-cli/releases/download/v0.11.1-pre1/boot2docker-v0.11.1-pre1-darwin-amd64 -O boot2docker
chmod +x boot2docker

あんまり覚えてないけどこんな感じだった気がする。
これはこれで使えてはいたけど、久々に見たらhomebrewでの提供が新しくなってたので一回まっさらにして入れなおした。
時の話。

brewでのインストール

brew install docker boot2docker

これだけ、簡単ですね。

ClientとServerのAPIバージョンがあってない問題

kuwanombp% docker version
Client version: 1.0.1
Client API version: 1.12
Go version (client): go1.3
Git commit (client): 990021a
2014/06/30 20:14:39 Error response from daemon: client and server don't have same version (client : 1.12, server: 1.11)

と、APIバージョンが違うので動かない事案が(´;ω;`)ブワッ


この場合は、boot2docker側のDockerServerが最新じゃないことが問題なので、以下コマンドで、boot2dockerのimageを最新にしてあげることで解決出来ます。

# boot2docker VM 停止
kuwanombp% boot2docker stop
# boot2docker VM 削除
kuwanombp% boot2docker delete
# 最新のboot2docker VM のiso imageを取得
kuwanombp% boot2docker download
# boot2docker VM 作成
kuwanombp% boot2docker init

DockerのPort変わってる問題

はー、これで動くわ−って思って実行するんですが、、、。

kuwanombp%  docker version
Client version: 1.0.1
Client API version: 1.12
Go version (client): go1.3
Git commit (client): 990021a
2014/06/30 20:18:30 Get http://localhost:4243/v1.12/version: EOF

ん、、、?EOF?確かにDockerAPIにつながらねぇって言って実行出来ない。
っていうのはここのISSUEのやりとりであるみたいに他にPortかぶってるからIANAからちゃんと取得しなおしたらしい。


ちゅーわけで、VirtualBox側でNAT設定変更が必要。


VirtualBoxの画面開いて、ゲストポートを4243->2375に変更しましょう。


はい、

kuwanombp%  docker version
Client version: 1.0.1
Client API version: 1.12
Go version (client): go1.3
Git commit (client): 990021a
Server version: 1.0.1
Server API version: 1.12
Go version (server): go1.2.1
Git commit (server): 990021a

これでOK

おまけ:名前解決について

仕事場で作業してて、時間かかる作業は家でやろうと、docker pull centosとかを家でやろうとしても動かない場合に

kuwanombp% docker pull centos
Pulling repository centos
2014/06/30 22:40:33 Get https://index.docker.io/v1/repositories/centos/images: dial tcp: lookup index.docker.io on 172.17.241.37:53: no answer from server

てなる場合はDNSの設定が職場のままで、boot2docker VMのresolv.conf書き換わってないっつー事なので、boot2docker restartでDHCP取り直してくださいねw
当たり前ですけどw恥ずかしいw


ではでは!₍₍ ᕕ(´ ω` )ᕗ⁾⁾



ここではない、どこかへ

ここではない、どこかへ

『Chef実践入門』で、今風なChefの使い方を料理してやるぜ(ベタ

乙カレー様です。

書評ばっかりしてる人みたいになっててやなのでマジブログ更新しよう(嗚咽


今年の年末年始にご縁があって『Chef実践入門』のレビューをさせていただきましたということで、献本頂いた(ありがとうございますm(_ _)m)ので改めて読んでみました。



Chef実践入門 ~コードによるインフラ構成の自動化 (WEB+DB PRESS plus)

Chef実践入門 ~コードによるインフラ構成の自動化 (WEB+DB PRESS plus)

内容

期せずしてChef活用ガイドという本もでていて、Chefの本が充実してきている昨今なのですが、Chef活用ガイドの方はChefそのものに対する詳しい説明、という感じで、Chefの内部構造やら、どのように動いているか、と言った部分にフォーカスしている様に感じました。こちらの本はChefそのものについて知るのにいい本です。


対してこの本は「今現在のChefの使い方を教える」本だと思います。
Chefの基本的な概念や、構築方法という部分はもちろんですが、VagrantやBerkshelf、Serverspecを使用した今のChefを使った運用はこうやっている、と言う事が考え方からわかる、一線でサービスを運用されているエンジニアの方々が書いただけあって構築から運用まで目を向けた本になっています。


この本で主にとりあげられているのはChef Soloとしての使い方ですが、Chef Serverの活用シーンの章もあり、Chefの現状を知るのに良いと思います。
加えて、Appendixにある、各種チートシートが運用時にリファレンス的に使えて地味に効く、長く使える本になっているなーという印象。

まとめ

Ansibleも流行りはじめ、どっちを選択したらいいんだろうといった所に悩んでいる方もいる昨今では有るかと思いますが、機能の充実、特に周辺アプリケーションはChefは充実しています。その部分の充実はAnsible->Sinatra, Chef->RoRという対比で良く表されますが、大規模な環境になればなるほど恩恵を受けられることになるかと思います。
今のモダン(かつ、常識になりつつある)なChef環境を知る上でこの本を手にとって見てはいかがでしょうか!


ザ・シェフ 1巻

ザ・シェフ 1巻

Chef実践入門 ~コードによるインフラ構成の自動化 (WEB+DB PRESS plus)

Chef実践入門 ~コードによるインフラ構成の自動化 (WEB+DB PRESS plus)

『開発効率をUPする Git逆引き入門』はGitの情報の洪水に飲まれないための浮き輪みたいなものだね。

「Git管理しているファイルをあとから除外対象に設定したい」はい?どうやります?


Gitって最初とっつきにくいですよねぇえええ。
Git使い始めた時は概念がよくわかんなくて、これなんなの?どういうことなの?って思いながら使ってました。(今も使えてないけど)
その頃は書籍もそんなに無いしWebの情報とDocumentみたり、聞いたりでやってた記憶があります。


開発効率をUPする Git逆引き入門』を献本頂いたので読んだのですが、非常によく出来たGitの書籍だったので紹介させていただこうとこの記事を書いております。



開発効率をUPする Git逆引き入門

開発効率をUPする Git逆引き入門

  • 作者: 松下雅和,船ヶ山慶,平木聡,土橋林太郎,三上丈晴
  • 出版社/メーカー: シーアンドアール研究所
  • 発売日: 2014/04/09
  • メディア: 単行本(ソフトカバー)
  • この商品を含むブログ (6件) を見る

内容

まず最初に、装丁がカッコイイw


とw
最近Gitの本がいっぱい出ていて、Gitが流行ってるんだなぁ(今更何を)なんて思いましたが、どれみてもほとんどの本が、”Gitについて網羅的に説明している本”だなぁという印象でした。
前述しましたが、元々Gitの概念からわかりやすく紹介した本ってあんまりなくって、すっげーとっつきにくい印象があります。もちろんそういった本もいい本なのですが、最初の最初に読むと、Gitって難しいって思っちゃう人も多いんじゃないかと思います。


そんな中、@さんが社内勉強会で発表されていた、「いつやるの?Git入門」はすごくわかりやすく概念の説明をしていて目からウロコでした。


開発効率をUPする Git逆引き入門』は@さんをはじめ、弊社の開発の中心になっている人たちになって”Gitの機能の逆引き”をテーマに書かれた本です。
1章では基本的なGitの説明を、前述の資料をかかれた@さんが書かれています。Gitの本なのに図解が多い説明は直感的にGitのアーキテクチャを理解できる良い説明でした。


そして、逆引き。
「ブランチをマージしたい」という、基本的な操作から、冒頭にあったような「Git管理しているファイルをあとから除外対象に設定したい」「Git管理していないファイルだけ削除したい」というちょっとアレって思うようなものまでいろんな機能を逆引きして確認することができます。


そりゃ調べたらわかるんだけど、、、これかな、、、これじゃねーな、、、あーこれか、、、違うな、、、(´;ω;`)
みたいな疑問に答えてくれるわけです。


あ、SourceTreeでの操作も一緒に説明*1しているので、おれはGUI派だっていう方や、ずっとCUIでやってたけど、GUIでやりたいというかたの移行するのに使うのもいいなと思いました。

まとめ

@さん献本いただきましてありがとうございました。
手前味噌ながら弊社のエンジニアの方々で書かれた本なのですが、そういうのを抜きにしてもいい本だと思いますのでGit始めたいという方をはじめ、リファレンス的に机に1冊あるとこれどうやんだっけ、と言う時に役に立つと思います。


デハデハ━━━( ´∀`)・ω・) ゚Д゚)゚∀゚)・∀・) ̄ー ̄)´_ゝ`)−_)゚∋゚)´Д`)゚ー゚)━━━!!!!

リンク

@さんの書いているこの本についてのブログエントリです。


開発効率をUPする Git逆引き入門

開発効率をUPする Git逆引き入門

  • 作者: 松下雅和,船ヶ山慶,平木聡,土橋林太郎,三上丈晴
  • 出版社/メーカー: シーアンドアール研究所
  • 発売日: 2014/04/09
  • メディア: 単行本(ソフトカバー)
  • この商品を含むブログ (6件) を見る


*1:しかも図解入りで!

vagrant-berkshelf(非推奨)を無理やりインストールする

はい、乙カレー様です。桑野です。
最近喉がイガイガ、鼻がムズムズ、身体は重い、これなーんだ(10点)


と、vagrant-berkshelfって非推奨になってしまったんですね。。。気付かずに入れようとしてたメモをなんとなくもったいないので書いとくw

インストール時エラー

$ vagrant plugin install vagrant-berkshelf
The plugin(s) can't be installed due to the version conflicts below.
This means that the plugins depend on a library version that conflicts
with other plugins or Vagrant itself, creating an impossible situation
where Vagrant wouldn't be able to load the plugins.

You can fix the issue by either removing a conflicting plugin or
by contacting a plugin author to see if they can address the conflict.

Vagrant could not find compatible versions for gem "celluloid":
  In Gemfile:
    vagrant-berkshelf (>= 0) ruby depends on
      celluloid (~> 0.13.0) ruby

    vagrant (= 1.5.0) ruby depends on
      celluloid (0.15.2)


 Ah, there you go. The conflict is a real issue. I haven't tried since updating the Vagrant dependencies. Unfortunately, that is not a dependency I can change.



Perhaps vagrant-berkshelf can have its dependencies updated... I'll open a ticket there.

なんかcelluloidのバージョン依存がvagrantvagrant-berkshelfで違うよーっていわれてインストール出来ないと。vagrant側がGEM管理から抜けてしまった影響ですね。

インストール手順

で、インストールどうやんのかな、と思って調べてたらvagrant-berkshelfのgithubのIssueにあった
で、やってみた


手順としてはGistにある。

berkshelf build
$ cd /tmp/dir
$ git clone https://github.com/berkshelf/berkshelf.git
$ cd berkshelf
$  gem build berkshelf.gemspec

ってやると

rbenv: version `2.0.0-p451' is not installed
rbenv: version `2.0.0-p451' is not installed

って出るのですが、これ ./.ruby-versionが残ってるからですね。
このバージョンじゃないとダメだっていってんのかもしれないですが、とりあえず2.1.0でやってみます。

$ rbenv local 2.1.0
# gemsetsを管理してる場合はこれも
$ echo >.rbenv-gemsets testgemsets
$ gem build berkshelf.gemspec

そしたらVagrantの管理してるGemにインストール

gem install berkshelf-*.gem --conservative --no-ri --no-rdoc --install-dir $HOME/.vagrant.d/gems
vagrant-berkshelf build

次は vagrant-berkshelf

$ cd /tmp/dir
$ git clone https://github.com/berkshelf/vagrant-berkshelf.git
$ cd vagrant-berkshelf
# gemsetsを管理してる場合はこれも
$ echo >.rbenv-gemsets testgemsets
$ gem build vagrant-berkshelf.gemspec


できたらgemファイル指定してvagrant plugin installで終わり。

$ vagrant plugin install vagrant-berkshelf-*.gem

インストールされたか確認

$ vagrant plugin list
vagrant-berkshelf (1.4.0.dev1)
vagrant-login (1.0.1, system)
vagrant-omnibus (1.3.1)

まあ、非推奨なんで

これからVagrant使う方はvagrant-berkshelf使わないほうがいいと思いますw
生Berkshelfを活用する方向にしましょうw(なんなんだ)


ではでは(◉◞౪◟◉`) 三 (´◉◞౪◟◉)ヒュンヒュン

追記

入れても上手く動かなかったんでやっぱ非推奨のものをつかうもんじゃないんや!って思ったんで忘れましょう。はいw

実践 Vagrant

実践 Vagrant

DENIX(デニックス) シェリフバッヂ ゴールド [113/L]

DENIX(デニックス) シェリフバッヂ ゴールド [113/L]

Vagrant起動時にVagrantfileの場所を切り替える

はい、乙カレー様です。桑野です。



ということだったんで、やってみた。
結果やりたいこととなんか違う気がするけどメモ書きとして入れておくw

やってみた

ドキュメント見ると環境変数VAGRANT_CWDでVagrantfileの検索パスの変更が出来るということなんで、やってみる。

テスト用のディレクトリ作成
$ mkdir test1 test2
テスト用のディレクトリにそれぞれVagrantfile作成
$ cat <<'EOF' > test1/Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :

VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "centos-65-x86_64"
  config.vm.network :private_network, ip: "192.168.33.10"
  config.vm.hostname = "test1"

  config.vm.provider :virtualbox do |vb|
    vb.gui = false
    vb.customize ["modifyvm", :id, "--memory", "1024"]
  end
end
EOF


$ cat <<'EOF' > test2/Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :

VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "centos-65-x86_64"
  config.vm.network :private_network, ip: "192.168.33.10"
  config.vm.hostname = "test2"

  config.vm.provider :virtualbox do |vb|
    vb.gui = false
    vb.customize ["modifyvm", :id, "--memory", "1024"]
  end
end
EOF
テスト用のディレクトリに作ったVagrantfileをみるようにvagrant 起動テスト
$ export VAGRANT_CWD=./test1/
$ vagrant up
$ vagrant ssh
[vagrant@test1 ~]$
$ vagrant destroy default


$ export VAGRANT_CWD=./test2/
$ vagrant up
$ vagrant ssh
[vagrant@test2 ~]$

で、とりあえずいけた様な、、、。

とりあえず切り替えられるけど、Vagarntfileを簡単に切り替えられる方法ってもっとスマートな方法ないんだろうかw
だれか知ってたら教えて下しあw
(☝ ՞ਊ ՞)=☞)՞ਊ ՞)<それでは!

実践 Vagrant

実践 Vagrant


神星記ヴァグランツ (1)

神星記ヴァグランツ (1)

〜さよなら自作サーバ〜 自作サーバ同窓会に参加&発表してきました

どうも乙カレーさまです。桑野です。


自作サーバカンファレンスをやってもう4、5年近く経つんだなぁと思って感慨深いです。
思えば大きな発表をしたのは自作サーバカンファレンスが初めてに近いですし、@さんにお誘い頂いて発表できた事で色々得るものがあったなー、と思っています。
それだけに@ さんが今回来られなかったのは残念でした(´;ω;`)ウッ…


そして、その自作サーバですが、ぼくもうちの自作サーバはガチの自作サーバはもうやっていないよ、という卒業生としての立場で参加しました。

自作サーバカンファレンスの資料

こちらは前回の自作サーバカンファレンスの資料です。


自作サーバ同窓会の資料

こちら今回の資料、テイストを合わせてみましたw



たまにお話聞いても大体の所で自作をやる事に対しては無い、または限定的、という感じの所が多いなぁと思っていましたが、そのままな話がほとんどでした。ただ、一部の方々が「たわませて!つめこむ!」「レベルを上げて物理で殴る」等、突き抜けてて凄かったですw


この5年で変わったこととして、クラウドサービスの席捲があります。
自分たちの事業を伸ばす事、サービスを安定的に運営する為に必要な事は自作サーバを作る事ではなく、それを行うときに何を選択するか、そのためにクラウドサービスを積極的に使う事はまったくもって正しいと思います。


自分は資料にもありますが、自作サーバでやる意義、メリットを見出しやすい2009年時期にやっておいてよかったなぁと思っています。
が、myfinderさんが兵站で表現されていましたが、自作サーバは茨の道でした。サーバが壊れてはDCへいき部材交換、在庫管理の煩雑さ、部材のスペック不整合をどうするか、大量確保の問題、性能比(世代間格差)をどう吸収するか、などなど規模感が増すに従って加速度的に運用は大変になりました。
# 撤去の時はなみかわさんが大変苦労したので感謝しきりですm(_ _)m


会後の懇親会でも話がでていましたが、IaaSでもハードウェア上で動いているわけで、ハードウェア、ネットワーク、必要な知識ではあると思います。
でもそれはそれを知るために自作サーバをやる、やらせる、と言うのはおかしい訳で、ただそういったことを意識しましょう、というだけの事です。自分も含めて、今後も自作サーバをやる機会があるならあればそれがどのようなベネフィットを生むのかどうかが明確にあるかの再確認が無いといけないのではないかと思っています。


だからもし自作サーバをやることでその会社のエンジニアのスキルを底上げし、オンプレで最適環境のサーバを整えられて、DC運用も、、、兵站を揃えられるのだったらやる価値は有るかもしれません。しかし楽しいから、やりたいからやる、自作PCの延長線でやるならやらない方がいいと思います。(あ、もちろんこの辺も規模感とか、そういう要素は絡んでくると思うのでこれが絶対正しい訳ではないと思います)


同窓会をやるにあたって昔のことを思いだしました。
自作サーバを実際やってみて色々わかることがありました。
それを色々な人に伝えて行くのが自分のやりたい事の一つではあるかなと思ったのでこう言う会がやれた事は非常に良かったですし、ひとつの区切りに出来たと思っています。(最初はただの飲み会だと思っていたのがこんなに大きなイベントになるとはおもっていませんでしたwww)

最後にお礼

発案者のはてなの @ さん
会場提供、懇親会などやっていただいたフリークアウトの @ さんはじめスタッフのみなさま。
来ていただいた皆様。
Ustreamみていただいた皆様。


ありがとうございました!

追記

そうだ一応。
サーバ売られるの流れありましたが、こちらデータ削除等はちゃんとされているものだったので何か損害がでている訳ではないです。単純にパーツ売りされてた形がアレすぎ...ということですねw

追記2

自作サーバ同窓会のについて言及したツイートをまとめました。
自作サーバ同窓会とげった


Dynatron P199 1U ソケット 775 CPUクーラー[P199]

Dynatron P199 1U ソケット 775 CPUクーラー[P199]