16
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

「Chef実践入門」トラブルシューティング

Posted at

以前、技術評論社のWEB+DB PRESS plusシリーズ「Chef実践入門」の書籍でサーバ自動構築のノウハウを勉強しました。
度々その内容やその後の操作でエラーが出てたので、その内容と対策などをメモしておきます。

1.berks install --path ./cookbooks で怒られる。

コミュニティクックブックを管理するためにberksを使用するが、
berks2と3のバージョン差分で、コマンドなどが若干変わっているらしい。

例として書籍の記述の通りnginxのコミュニティクックブックなどの取得してみる。
Berksfileを以下の通りに記述。

site :opscode

cookbook "yum-epel"
cookbook "nginx", path: "./site-cookbooks/nginx"

そしてコミュニティクックブックの取得を実行。

$ bundle exec berks install --path ./cookbooks
DEPRECATED: `berks install --path [PATH}` has been replaced by `berks vendor`.
DEPRECATED: Re-run your command as `berks vendor [PATH]` or see `berks help vendor`.

berksコマンドのバージョンアップでコマンドが置き換わったらしい。
指示されたコマンドに変更して実行してみる。

bash
$ bundle exec berks vendor ./cookbooks
DEPRECATED: Your Berksfile contains a site location pointing to the Opscode Community Site (site :opscode). Site locations have been replaced by the source location. Change this to: 'source "https://supermarket.getchef.com"' to remove this warning. For more information visit https://github.com/berkshelf/berkshelf/wiki/deprecated-locations
destination already exists /Users/inodev/vagrant_work/6.dev-app/cookbooks. Delete it and try again or use a different filepath.

どうやらソース取得先の指定の仕方が古いらしい。
指示通りberksファイルを編集。

source "https://supermarket.getchef.com"

cookbook "yum-epel"
cookbook "nginx", path: "./site-cookbooks/nginx"

実行。

$ bundle exec berks vendor ./cookbooks
destination already exists /Users/inodev/vagrant_work/6.dev-app/cookbooks. Delete it and try again or use a different filepath.

既に存在しているから無理…?
cookbookをディレクトリごと消して再度実行。

$ rm -r cookbooks
$ bundle exec berks vendor ./cookbooks
Resolving cookbook dependencies...
Fetching 'nginx' from source at site-cookbooks/nginx
Using yum-epel (0.5.1)
Using nginx (0.1.0) from source at site-cookbooks/nginx
Using yum (3.3.2)
Vendoring nginx (0.1.0) to /Users/inodev/vagrant_work/6.dev-app/cookbooks/nginx
Vendoring yum (3.3.2) to /Users/inodev/vagrant_work/6.dev-app/cookbooks/yum
Vendoring yum-epel (0.5.1) to /Users/inodev/vagrant_work/6.dev-app/cookbooks/yum-epel

取りあえず入れられた。

2.bootstrap実行時にエラーになる。

サーバ側のchefのインストールからcookbookの適用までを自動的に行うbootstrapコマンド。
しかし、パッケージの取得(及びchef-soloの実行)に失敗してしまう。

bash
$ knife solo bootstrap webdb
Bootstrapping Chef...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 16519  100 16519    0     0  17167      0 --:--:-- --:--:-- --:--:-- 49458
Downloading Chef 12.0.0.alpha.2 for el...
downloading https://www.opscode.com/chef/metadata?v=12.0.0.alpha.2&prerelease=false&nightlies=false&p=el&pv=6&m=x86_64
  to file /tmp/install.sh.1728/metadata.txt
trying wget...
trying curl...
ERROR 404
Unable to retrieve a valid package!
Please file a bug report at http://tickets.opscode.com
Project: Chef
Component: Packages
Label: Omnibus
Version: 12.0.0.alpha.2

Please detail your operating system type, version and any other relevant details
Metadata URL: https://www.opscode.com/chef/metadata?v=12.0.0.alpha.2&prerelease=false&nightlies=false&p=el&pv=6&m=x86_64

# 〜中略〜

Uploading the kitchen...
Generating solo config...
Running Chef...
sudo: chef-solo: コマンドが見つかりません
ERROR: RuntimeError: chef-solo failed. See output above.

調べてみたらchef-soloのVersion: 12.0.0.alpha.2がだと失敗するとからしい・・・?

bash
$ chef-solo -v
Chef: 12.0.0.alpha.2

対策として、boostrap実行に 前のバージョンを指定すると成功する

bash
$ vagrant destroy -f
$ vagrant up
$ knife solo bootstrap webdb --bootstrap-version 11.16.0
Bootstrapping Chef...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 16519  100 16519    0     0  14500      0  0:00:01  0:00:01 --:--:-- 32200
Downloading Chef 11.16.0 for el...
downloading https://www.opscode.com/chef/metadata?v=11.16.0&prerelease=false&nightlies=false&p=el&pv=6&m=x86_64
  to file /tmp/install.sh.1724/metadata.txt
trying wget...
url	https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-11.16.0-1.el6.x86_64.rpm
md5	5c8cfdbab2684148e2bb859b736b6827
sha256	e4d0236cc495d080f8e7a01704e2ef554e12088687e4fe946ee8027b79871bbb
downloaded metadata file looks valid...
downloading https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-11.16.0-1.el6.x86_64.rpm
  to file /tmp/install.sh.1724/chef-11.16.0-1.el6.x86_64.rpm

# 〜中略〜

Running handlers:
Running handlers complete
Chef Client finished, 13/13 resources updated in 60.858639896 seconds

うーん、なんだこりゃ。

番外編1.ゲストOSをBox化して追加した後にエラーになる。

ローカルPC
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

ARPCHECK=no /sbin/ifup eth1 2> /dev/null

Stdout from the command:

Device eth1 does not seem to be present, delaying initialization.


Stderr from the command:


MACアドレスとのマッピングを削除してからBox化すると良いとのこと。

ゲストOS
$ vagrant ssh
$ sudo ln -s -f /dev/null /etc/udev/rules.d/70-persistent-net.rules
$ exit
ローカルPC
$ vagrant package --output hoge.box
$ vagrant box add hoge.box

番外編2.すでに別のVMが立ち上がっていてローカルのポートが競合

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
Vagrant cannot forward the specified ports on this VM, since they
would collide with some other application that is already listening
on these ports. The forwarded port to 8080 is already in use
on the host machine.

To fix this, modify your current projects Vagrantfile to use another
port. Example, where '1234' would be replaced by a unique host port:

  config.vm.network :forwarded_port, guest: 80, host: 1234

Sometimes, Vagrant will attempt to auto-correct this for you. In this
case, Vagrant was unable to. This is usually because the guest machine
is in a state which doesn't allow modifying port forwarding.

VitrualBox立ち上げていらない奴を消せばOK。
複数定義して競合していたらVagrantfileのconfig.vm.networkでずらして設定しておく。
取り敢えず変な挙動をしたらGUIのVirtualBoxを起動して色々見たら大体治ることは分かった。

16
16
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?