如何使用 Chef 安装 Redis?

如何使用 Chef 安装 Redis?

我正在尝试使用 Chef 安装 Redis。我认为这很容易,因为我只想使用默认配置。

因此,我向 Berksfile 中添加以下内容:

网站:opscode

食谱‘apt’
食谱‘节点’
食谱'rvm',:git => "https://github.com/fnichol/chef-rvm"
食谱‘runit’
食谱“redis”

然后,我运行:vagrant provision

但我明白这一点:

2013-12-11T21:18:23+00:00] DEBUG:chef_gem[rvm] 已安装 - 无需执行任何操作
[2013-12-11T21:18:23+00:00] 调试:通过 include_recipe 加载配方 rvm::vagrant
[2013-12-11T21:18:23+00:00] 调试:在 cookbook rvm 中发现食谱 vagrant
[2013-12-11T21:18:23+00:00] 警告:从先前资源克隆组 [rvm] 的资源属性 (CHEF-3694)
[2013-12-11T21:18:23 + 00:00] 警告:上一组 [rvm]:/tmp/vagrant-chef-1/chef-solo-1/cookbooks/rvm/recipes/system.rb:33:in `from_file'
[2013-12-11T21:18:23 + 00:00] 警告:当前组[rvm]:/tmp/vagrant-chef-1/chef-solo-1/cookbooks/rvm/recipes/vagrant.rb:34:在“from_file”中
[2013-12-11T21:18:23+00:00] 调试:通过 include_recipe 加载 Recipe redis
[2013-12-11T21:18:23+00:00] 调试:在 Redis 菜谱中发现默认菜谱
[2013-12-11T21:18:23+00:00] 调试:通过 include_recipe 加载配方 metachef
[2013-12-11T21:18:23+00:00] 调试:在食谱 metachef 中发现默认食谱
[2013-12-11T21:18:23+00:00] 调试:通过 include_recipe 加载配方 redis::server
[2013-12-11T21:18:23+00:00] 调试:在食谱 redis 中找到食谱服务器
[2013-12-11T21:18:23+00:00] 调试:通过include_recipe 加载配方运行
[2013-12-11T21:18:23+00:00] 调试:在运行的菜谱中发现默认菜谱
[2013-12-11T21:18:23+00:00] 调试:通过 include_recipe 加载配方 metachef
[2013-12-11T21:18:23+00:00] DEBUG:我没有加载 metachef,因为我已经看到它了。
[2013-12-11T21:18:23+00:00] 调试:通过 include_recipe 加载配方 redis::default
[2013-12-11T21:18:23 + 00:00] DEBUG:我没有加载redis :: default,因为我已经看到它了。
[2013-12-11T21:18:23+00:00] 警告:从先前的资源克隆目录 [/etc/redis] 的资源属性 (CHEF-3694)
[2013-12-11T21:18:23 + 00:00] 警告:上一个目录 [/etc/redis]:/tmp/vagrant-chef-1/chef-solo-1/cookbooks/metachef/definitions/standard_dirs.rb:44:在 from_file 中的“块(3 级)”中
[2013-12-11T21:18:23 + 00:00] 警告:当前目录[/etc/redis]:/tmp/vagrant-chef-1/chef-solo-1/cookbooks/metachef/definitions/standard_dirs.rb:44:在 from_file 中的“块(3 级)”中
[2013-12-11T21:18:23 + 00:00] DEBUG:编译错误的过滤回溯:/tmp/vagrant-chef-1/chef-solo-1/cookbooks/redis/recipes/server.rb:37:在'block in from_file'中,/tmp/vagrant-chef-1/chef-solo-1/cookbooks/redis/recipes/server.rb:36:在'from_file'中
[2013-12-11T21:18:23 + 00:00] DEBUG:编译错误的过滤回溯:/tmp/vagrant-chef-1/chef-solo-1/cookbooks/redis/recipes/server.rb:37:在'block in from_file'中,/tmp/vagrant-chef-1/chef-solo-1/cookbooks/redis/recipes/server.rb:36:在'from_file'中
[2013-12-11T21:18:23 + 00:00] DEBUG:编译错误的回溯条目:'/tmp/vagrant-chef-1/chef-solo-1/cookbooks/redis/recipes/server.rb:37:in'block in from_file''
[2013-12-11T21:18:23+00:00] DEBUG:编译错误行号:'37'
[2013-12-11T21:18:23+00:00] 调试:重新引发异常:NoMethodError - Chef::Resource::RunitService 未定义方法“run_state”
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/resource.rb:294:in `method_missing'
  /tmp/vagrant-chef-1/chef-solo-1/cookbooks/redis/recipes/server.rb:37:in`从文件中阻止'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/dsl/recipe.rb:71:in`instance_eval'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/dsl/recipe.rb:71:in `method_missing'
  /tmp/vagrant-chef-1/chef-solo-1/cookbooks/redis/recipes/server.rb:36:in`from_file'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/mixin/from_file.rb:30:in`instance_eval'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/mixin/from_file.rb:30:in`from_file'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/cookbook_version.rb:237:in`load_recipe'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/run_context.rb:151:in`load_recipe'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/run_context/cookbook_compiler.rb:139:in`在 compile_recipes 中阻止'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/run_context/cookbook_compiler.rb:137:in `each'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/run_context/cookbook_compiler.rb:137:in`compile_recipes'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/run_context/cookbook_compiler.rb:74:in`编译'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/run_context.rb:86:in`加载'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/client.rb:250:in`setup_run_context'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/client.rb:498:in`do_run'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/client.rb:199:in`运行中阻止'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/client.rb:193:in`fork'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/client.rb:193:in`运行'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/application.rb:208:in`run_chef_client'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/application/solo.rb:221:in `在 run_application 中阻止'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/application/solo.rb:213:in `循环'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/application/solo.rb:213:in`run_application'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/application.rb:66:in`运行'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/bin/chef-solo:25:in `'
  /opt/chef/bin/chef-solo:23:in`加载'
  /opt/chef/bin/chef-solo:23:in `'
[2013-12-11T21:18:23+00:00] 错误:正在运行异常处理程序
[2013-12-11T21:18:23+00:00] 错误:异常处理程序完成
[2013-12-11T21:18:23+00:00] 严重:堆栈跟踪已转储至 /var/chef/cache/chef-stacktrace.out
[2013-12-11T21:18:23 + 00:00] DEBUG:NoMethodError:未定义 Chef::Resource::RunitService 的方法“run_state”
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/resource.rb:294:in `method_missing'
/tmp/vagrant-chef-1/chef-solo-1/cookbooks/redis/recipes/server.rb:37:in`从文件中阻止'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/dsl/recipe.rb:71:in`instance_eval'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/dsl/recipe.rb:71:in `method_missing'
/tmp/vagrant-chef-1/chef-solo-1/cookbooks/redis/recipes/server.rb:36:in`from_file'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/mixin/from_file.rb:30:in`instance_eval'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/mixin/from_file.rb:30:in`from_file'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/cookbook_version.rb:237:in`load_recipe'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/run_context.rb:151:in`load_recipe'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/run_context/cookbook_compiler.rb:139:in`在 compile_recipes 中阻止'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/run_context/cookbook_compiler.rb:137:in `each'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/run_context/cookbook_compiler.rb:137:in`compile_recipes'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/run_context/cookbook_compiler.rb:74:in`编译'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/run_context.rb:86:in`加载'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/client.rb:250:in`setup_run_context'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/client.rb:498:in`do_run'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/client.rb:199:in`运行中阻止'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/client.rb:193:in`fork'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/client.rb:193:in`运行'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/application.rb:208:in`run_chef_client'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/application/solo.rb:221:in `在 run_application 中阻止'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/application/solo.rb:213:in `循环'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/application/solo.rb:213:in`run_application'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/application.rb:66:in`运行'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/bin/chef-solo:25:in `'
/opt/chef/bin/chef-solo:23:in`加载'
/opt/chef/bin/chef-solo:23:in `'
[2013-12-11T21:18:23+00:00] 错误:Chef::Resource::RunitService 未定义方法‘run_state’

================================================================================
/tmp/vagrant-chef-1/chef-solo-1/cookbooks/redis/recipes/server.rb 中的配方编译错误
================================================================================


无方法错误
-------------
Chef::Resource::RunitService 未定义方法‘run_state’


菜谱追踪:
---------------
  /tmp/vagrant-chef-1/chef-solo-1/cookbooks/redis/recipes/server.rb:37:in`从文件中阻止'
  /tmp/vagrant-chef-1/chef-solo-1/cookbooks/redis/recipes/server.rb:36:in`from_file'


相关文件内容:
----------------------
/tmp/vagrant-chef-1/chef-solo-1/cookbooks/redis/recipes/server.rb:

 30:standard_dirs('redis.server')执行
 31:目录:conf_dir,:log_dir,:data_dir
 32:结束
 33:
 34:kill_old_service('redis-server'){only_if{File.exists?(“/etc/init.d/redis-server”)}}
 35:
 36:运行redis_server服务
 37>> run_state 节点[:redis][:服务器][:run_state]
 38:选项节点[:redis]
 39:结束
 40:
 41:宣布(:redis,:服务器,
 42::port => 节点[:redis][:服务器][:端口])
 43:


[2013-12-11T21:18:21 + 00:00] 信息:分叉厨师实例以融合......
[2013-12-11T21:18:21+00:00] DEBUG:分叉成功。正在等待新的 chef pid:28235
[2013-12-11T21:18:23 + 00:00] 严重:Chef::Exceptions::ChildConvergeError:Chef 运行过程退出失败(退出代码 1)

编辑 -

这是运行列表:

  config.vm.provision:chef_solo 执行 |chef|
    chef.cookbooks_path = “./cookbooks”
    #chef.roles_path = “../my-recipes/roles”
    #chef.data_bags_path = “../my-recipes/data_bags”
    chef.add_recipe“runit”
    chef.add_recipe“rvm::system”
    chef.add_recipe“rvm::vagrant”
    chef.add_recipe“redis::install_from_release”
    chef.add_recipe“redis::客户端”
    # chef.add_recipe “节点”
    # chef.add_role“web”

    # 您还可以指定自定义 JSON 属性:
    chef.json = {
      'rvm' => {
         'rubies' => ["2.0.0-p353"],
         'default_ruby' => "2.0.0-p353",
         :vagrant => { :system_chef_solo => “/opt/chef/bin/chef-solo” }
      }
    }

    chef.log_level = :debug
  结尾


答案1

将“runit”食谱放在运行列表的顶部,然后重试。

答案2

通过调查食谱,我发现:

配方“redis::default”,“redis 的基本配置”
配方“redis::install_from_package”,“从 Ubuntu 软件包安装 - 简单但版本滞后”
配方“redis :: install_from_release”,“从发布版本安装”
配方“redis :: server”,“带有 runit 服务的 Redis 服务器”
配方“redis::client”,  

当使用:redis::install_from_package 时我得到了一些工作

答案3

这似乎是“runit”食谱的问题。我遇到了同样的问题,甚至将“runit”放在我的运行列表顶部。

一个快速的解决方法是改用“redis::install_from_package”。

PS:如果使用 install_from_package 时遇到任何异常,请尝试清理 redis(因为它可能是由您之前的尝试生成的):

sudo apt-get purge  redis-server
rm -rf /etc/redis

相关内容