2013年7月11日木曜日

knife-solo 0.3.0をインストールする方法(仮)


http://matschaffer.github.io/knife-solo/
knife-soloとは、ホストサーバからリモートサーバのchef-soloを実行するためのアプリケーションです。
これを使うことによって、リモートサーバにいちいちログインすることなく、ソフトウェアのセットアップをすることができるようになります。
入門Chef Solo』を読んでいて、knife-soloのインストールでちょっと詰まったので、インストールメモを書いておきます。


環境

# cat /etc/redhat-release
CentOS release 6.4 (Final)

yumライブラリをインストール
# yum install libxslt-devel
# yum install git
# yum install openssl-devel


ruby2.0とopensslライブラリをインストール

# wget ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p247.tar.gz
# tar xvzf ruby-2.0.0-p247.tar.gz
# cd ruby-2.0.0-p247
# ./configure --prefix=/usr
# make
# make install
# cd ext/openssl
# ruby extconf.rb
# make install

# which ruby                                                                          
/usr/bin/ruby

# ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]

# gem -v
2.0.3

bundlerをインストール
# gem install bundler

gitからknife-soloをコピーして、インストール
# cd
# git clone git://github.com/matschaffer/knife-solo.git
# cd knife-solo/
# git submodule update --init
# bundle && bundle exec rake install

ヘルプを表示してみましょう
# knife -h
Usage: knife sub-command (options)
    -s, --server-url URL             Chef Server URL
    -k, --key KEY                    API Client Key
        --[no-]color                 Use colored output, defaults to enabled
    -c, --config CONFIG              The configuration file to use
        --defaults                   Accept default values for all questions
    -d, --disable-editing            Do not open EDITOR, just accept the data as is
    -e, --editor EDITOR              Set the editor to use for interactive commands
    -E, --environment ENVIRONMENT    Set the Chef environment
    -F, --format FORMAT              Which format to use for output
    -u, --user USER                  API Client Username
        --print-after                Show the data after a destructive operation
    -V, --verbose                    More verbose output. Use twice for max verbosity
    -v, --version                    Show chef version
    -y, --yes                        Say yes to all prompts for confirmation
    -h, --help                       Show this message

Available subcommands: (for details, knife SUB-COMMAND --help)

** BOOTSTRAP COMMANDS **
knife bootstrap FQDN (options)

** CLIENT COMMANDS **
knife client create CLIENT (options)
knife client delete CLIENT (options)
knife client bulk delete REGEX (options)
knife client list (options)
knife client show CLIENT (options)
knife client edit CLIENT (options)
knife client reregister CLIENT (options)

** CONFIGURE COMMANDS **
knife configure client DIRECTORY
knife configure (options)

** COOK COMMANDS **
`knife cook` is deprecated! Please use:
  knife solo cook [USER@]HOSTNAME [JSON] (options)

** COOKBOOK COMMANDS **
knife cookbook metadata COOKBOOK (options)
knife cookbook show COOKBOOK [VERSION] [PART] [FILENAME] (options)
knife cookbook upload [COOKBOOKS...] (options)
knife cookbook test [COOKBOOKS...] (options)
knife cookbook download COOKBOOK [VERSION] (options)
knife cookbook list (options)
knife cookbook bulk delete REGEX (options)
knife cookbook metadata from FILE (options)
knife cookbook create COOKBOOK (options)
knife cookbook delete COOKBOOK VERSION (options)

** COOKBOOK SITE COMMANDS **
knife cookbook site unshare COOKBOOK
knife cookbook site install COOKBOOK [VERSION] (options)
knife cookbook site share COOKBOOK CATEGORY (options)
knife cookbook site download COOKBOOK [VERSION] (options)
knife cookbook site search QUERY (options)
knife cookbook site list (options)
knife cookbook site show COOKBOOK [VERSION] (options)

** DATA BAG COMMANDS **
knife data bag delete BAG [ITEM] (options)
knife data bag from file BAG FILE|FOLDER [FILE|FOLDER..] (options)
knife data bag create BAG [ITEM] (options)
knife data bag show BAG [ITEM] (options)
knife data bag list (options)
knife data bag edit BAG ITEM (options)

** DELETE COMMANDS **
knife delete [PATTERN1 ... PATTERNn]

** DIFF COMMANDS **
knife diff PATTERNS

** DOWNLOAD COMMANDS **
knife download PATTERNS

** ENVIRONMENT COMMANDS **
knife environment edit ENVIRONMENT (options)
knife environment delete ENVIRONMENT (options)
knife environment create ENVIRONMENT (options)
knife environment show ENVIRONMENT (options)
knife environment list (options)
knife environment from file FILE [FILE..] (options)

** EXEC COMMANDS **
knife exec [SCRIPT] (options)

** HELP COMMANDS **
knife help [list|TOPIC]

** INDEX COMMANDS **
knife index rebuild (options)

** KITCHEN COMMANDS **
`knife kitchen` is deprecated! Please use:
  knife solo init DIRECTORY

** KNIFE COMMANDS **
Usage: /usr/bin/knife (options)

** LIST COMMANDS **
knife list [-dR] [PATTERN1 ... PATTERNn]

** NODE COMMANDS **
knife node edit NODE (options)
knife node show NODE (options)
knife node from file FILE (options)
knife node run_list add [NODE] [ENTRY[,ENTRY]] (options)
knife node run_list remove [NODE] [ENTRIES] (options)
knife node delete NODE (options)
knife node create NODE (options)
knife node bulk delete REGEX (options)
knife node list (options)

** PREPARE COMMANDS **
`knife prepare` is deprecated! Please use:
  knife solo prepare [USER@]HOSTNAME [JSON] (options)

** RAW COMMANDS **
knife raw REQUEST_PATH

** RECIPE COMMANDS **
knife recipe list [PATTERN]

** ROLE COMMANDS **
knife role create ROLE (options)
knife role from file FILE [FILE..] (options)
knife role bulk delete REGEX (options)
knife role show ROLE (options)
knife role list (options)
knife role delete ROLE (options)
knife role edit ROLE (options)

** SEARCH COMMANDS **
knife search INDEX QUERY (options)

** SHOW COMMANDS **
knife show [PATTERN1 ... PATTERNn]

** SOLO COMMANDS **
knife solo clean [USER@]HOSTNAME
knife solo cook [USER@]HOSTNAME [JSON] (options)
knife solo prepare [USER@]HOSTNAME [JSON] (options)
knife solo bootstrap [USER@]HOSTNAME [JSON] (options)
knife solo init DIRECTORY

** SSH COMMANDS **
knife ssh QUERY COMMAND (options)

** STATUS COMMANDS **
knife status QUERY (options)

** TAG COMMANDS **
knife tag create NODE TAG ...
knife tag list NODE
knife tag delete NODE TAG ...

** UPLOAD COMMANDS **
knife upload PATTERNS

** USER COMMANDS **
knife user edit USER (options)
knife user delete USER (options)
knife user create USER (options)
knife user reregister USER (options)
knife user show USER (options)
knife user list (options)

** WASH COMMANDS **
`knife wash up` is deprecated! Please use:
  knife solo clean [USER@]HOSTNAME



ちゃんと、knife soloコマンドがありますか?
# knife | grep solo
  knife solo cook [USER@]HOSTNAME [JSON] (options)
  knife solo init DIRECTORY
  knife solo prepare [USER@]HOSTNAME [JSON] (options)
knife solo clean [USER@]HOSTNAME
knife solo cook [USER@]HOSTNAME [JSON] (options)
knife solo prepare [USER@]HOSTNAME [JSON] (options)
knife solo bootstrap [USER@]HOSTNAME [JSON] (options)
knife solo init DIRECTORY
  knife solo clean [USER@]HOSTNAME



knife-soloを使ってリモートサーバにChef Soloをインストールしてみます。


ホストサーバ
公開鍵作成
# cd
# ssh-keygen -t rsa
# cat .ssh/id_rsa.pub
# ssh-rsa AAAAB********************************************************

リモートサーバ
鍵を設置
# cd
# mkdir -p .ssh
# vi .ssh/authorized_keys
# ssh-rsa AAAAB********************************************************
# chmod -R 700 .ssh


ホストサーバからリモートサーバにsshログインできることを確認
# ssh root@192.168.17.141

ホストサーバ
knifeを使って、リモートサーバにChef Soloをインストール。
# knife solo prepare root@192.168.17.141

WARNING: No knife configuration file found
Bootstrapping Chef...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  6510  100  6510    0     0   8206      0 --:--:-- --:--:-- --:--:-- 35769
Downloading Chef 11.4.4 for el...
Installing Chef 11.4.4
warning: /tmp/tmp.t5p75n9d/chef-11.4.4.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 83ef826a: NOKEY
Preparing...                ########################################### [100%]
   1:chef                   ########################################### [100%]
Thank you for installing Chef!
Generating node config 'nodes/192.168.17.141.json'...

うまくいきました。
レシピを作ってサーバをセットアップしまくりたいですね。