Chef 教程在 chef_gem[mysql] 安装失败

Chef tutorial fails at chef_gem[mysql] install

我正在关注以下厨师教程:

http://gettingstartedwithchef.com/first-steps-with-chef.html

在 "Attributes" 部分之前一切正常。在创建节点 ['phpapp']['database'] 条目和 运行 chef-solo 之后,我得到以下信息。有任何想法吗?一般来说,我不熟悉 ruby,所以我很难自己调试它。

root@chef-solo:~/chef-repo# chef-solo -c solo.rb -j web.json 
Starting Chef Client, version 11.8.2
Compiling Cookbooks...
/root/chef-repo/cookbooks/homebrew/libraries/homebrew_package.rb:26: warning: toplevel constant Homebrew referenced by Chef::Provider::Package::Homebrew
[2015-03-15T19:08:58+00:00] WARN: Cloning resource attributes for directory[/var/cache/local/preseeding] from prior resource (CHEF-3694)
[2015-03-15T19:08:58+00:00] WARN: Previous directory[/var/cache/local/preseeding]: /root/chef-repo/cookbooks/apt/recipes/default.rb:91:in `block in from_file'
[2015-03-15T19:08:58+00:00] WARN: Current  directory[/var/cache/local/preseeding]: /root/chef-repo/cookbooks/mysql/recipes/_server_debian.rb:4:in `from_file'
[2015-03-15T19:08:58+00:00] WARN: Cloning resource attributes for directory[/var/lib/mysql] from prior resource (CHEF-3694)
[2015-03-15T19:08:58+00:00] WARN: Previous directory[/var/lib/mysql]: /root/chef-repo/cookbooks/mysql/recipes/_server_debian.rb:34:in `block in from_file'
[2015-03-15T19:08:58+00:00] WARN: Current  directory[/var/lib/mysql]: /root/chef-repo/cookbooks/mysql/recipes/_server_debian.rb:78:in `from_file'
[2015-03-15T19:08:58+00:00] WARN: apache2::mod_php5 generally is expected to be run under a non-threaded MPM, such as prefork
[2015-03-15T19:08:58+00:00] WARN: See http://php.net/manual/en/faq.installation.php#faq.installation.apache2
[2015-03-15T19:08:58+00:00] WARN: Currently the apache2 cookbook is configured to use the 'event' MPM
[2015-03-15T19:08:58+00:00] WARN: node['build_essential'] has been changed to node['build-essential'] to match the
cookbook name and community standards. I have gracefully converted the attribute
for you, but this warning and conversion will be removed in the next major
release of the build-essential cookbook.

[2015-03-15T19:08:58+00:00] WARN: node['build-essential']['compiletime'] has been deprecated. Please use
node['build-essential']['compile_time'] instead. I have gracefully converted the
attribute for you, but this warning and converstion will be removed in the next
major release of the build-essential cookbook.

Recipe: build-essential::_debian
  * package[autoconf] action install (up to date)
  * package[binutils-doc] action install (up to date)
  * package[bison] action install (up to date)
  * package[build-essential] action install (up to date)
  * package[flex] action install (up to date)
  * package[gettext] action install (up to date)
  * package[ncurses-dev] action install (up to date)
Recipe: mysql::client
  * package[mysql-client] action install (up to date)
  * package[libmysqlclient-dev] action install (up to date)
Recipe: mysql::ruby
  * chef_gem[mysql] action install
================================================================================
Error executing action `install` on resource 'chef_gem[mysql]'
================================================================================


Gem::Installer::ExtensionBuildError
-----------------------------------
ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.9.1 extconf.rb
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from extconf.rb:5:in `<main>'


Gem files will remain installed in /var/lib/gems/1.9.1/gems/mysql-2.9.1 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/mysql-2.9.1/ext/mysql_api/gem_make.out



Cookbook Trace:
---------------
/root/chef-repo/cookbooks/mysql/recipes/ruby.rb:47:in `from_file'
/root/chef-repo/cookbooks/phpapp/recipes/default.rb:16:in `from_file'


Resource Declaration:
---------------------
# In /root/chef-repo/cookbooks/mysql/recipes/ruby.rb

 47: chef_gem 'mysql'



Compiled Resource:
------------------
# Declared in /root/chef-repo/cookbooks/mysql/recipes/ruby.rb:47:in `from_file'

chef_gem("mysql") do
  provider Chef::Provider::Package::Rubygems
  action :install
  retries 0
  retry_delay 2
  package_name "mysql"
  version "2.9.1"
  cookbook_name :mysql
  recipe_name "ruby"
end




================================================================================
Recipe Compile Error in /root/chef-repo/cookbooks/phpapp/recipes/default.rb
================================================================================


Gem::Installer::ExtensionBuildError
-----------------------------------
chef_gem[mysql] (mysql::ruby line 47) had an error: Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.9.1 extconf.rb
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from extconf.rb:5:in `<main>'


Gem files will remain installed in /var/lib/gems/1.9.1/gems/mysql-2.9.1 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/mysql-2.9.1/ext/mysql_api/gem_make.out



Cookbook Trace:
---------------
  /root/chef-repo/cookbooks/mysql/recipes/ruby.rb:47:in `from_file'
  /root/chef-repo/cookbooks/phpapp/recipes/default.rb:16:in `from_file'


Relevant File Content:
----------------------
/root/chef-repo/cookbooks/mysql/recipes/ruby.rb:

 40:    end
 41:  end
 42:  
 43:  node['mysql']['client']['packages'].each do |name|
 44:    resources("package[#{name}]").run_action(:install)
 45:  end
 46:  
 47>> chef_gem 'mysql'
 48:  


[2015-03-15T19:09:00+00:00] ERROR: Running exception handlers
[2015-03-15T19:09:00+00:00] ERROR: Exception handlers complete
[2015-03-15T19:09:00+00:00] FATAL: Stacktrace dumped to /root/chef-solo/chef-stacktrace.out
Chef Client failed. 0 resources updated
[2015-03-15T19:09:00+00:00] ERROR: chef_gem[mysql] (mysql::ruby line 47) had an error: Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.9.1 extconf.rb
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from extconf.rb:5:in `<main>'


Gem files will remain installed in /var/lib/gems/1.9.1/gems/mysql-2.9.1 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/mysql-2.9.1/ext/mysql_api/gem_make.out

[2015-03-15T19:09:00+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
root@chef-solo:~/chef-repo# 

您似乎缺少为 ruby 构建 mysql gem 所需的一些预期 ruby-dev 工具。 chef_gem 通常将 gems 安装到 chef 附带的嵌入式版本 Ruby 中。鉴于您的输出是指 /var/lib/gems/1.9.1/usr/bin/ruby1.9.1,我猜您有一个正在调用的系统 ruby 而不是 chef 嵌入式系统(通常在 /opt/chef/embedded/ruby .

我建议清理您的 shell 环境并重新安装 Chef。您也可以通过调用 chef ruby 的 gem 命令并以这种方式安装 mysql gem 来手动尝试解决此问题(/opt/chef/embedded/bin/gem install mysql -- 不是当然在那个路径上,但是你正在 /opt/chef).

下寻找 gem 二进制文件

好吧,我结束了 "hacking" 它一点点。

apt-get install ruby-all-dev

这解决了 ruby gem 问题。然后我有一个错误,它抱怨与 mysql2 有关的事情,所以:

gem install mysql2

我的厨师 运行 现在完成了。谢谢大家的帮助。