【问题标题】:Chef MongoDB Replication with sc-mongodb使用 sc-mongodb 进行厨师 MongoDB 复制
【发布时间】:2018-05-31 03:53:45
【问题描述】:

我是新来的厨师,我正在使用sc-mongodb,但我无法让它工作。有没有更好的方法来使用 Chef 为 MongoDB 进行复制?

我能够让默认配方正常工作

include_recipe "sc-mongodb::default"

但是当我尝试为 mongo 进行复制时,我开始遇到一些奇怪的错误。

include_recipe "sc-mongodb::replicaset"

错误:

 ================================================================================
   Recipe Compile Error in /tmp/kitchen/cache/cookbooks/c_mongo/recipes/default.rb
   ================================================================================

   Net::HTTPServerException
   ------------------------
   400 "Bad Request"

   Cookbook Trace:
   ---------------
     /tmp/kitchen/cache/cookbooks/sc-mongodb/definitions/mongodb.rb:236:in `block in from_file'
     /tmp/kitchen/cache/cookbooks/sc-mongodb/recipes/replicaset.rb:36:in `from_file'
     /tmp/kitchen/cache/cookbooks/c_mongo/recipes/default.rb:54:in `from_file'

   Relevant File Content:
   ----------------------
   /tmp/kitchen/cache/cookbooks/sc-mongodb/definitions/mongodb.rb:

   229:      notifies :run, 'ruby_block[config_sharding]', :immediately if new_resource.is_mongos && new_resource.auto_configure_sharding
   230:      # we don't care about a running mongodb service in these cases, all we need is stopping it
   231:      ignore_failure true if new_resource.name == 'mongodb'
   232:    end
   233:
   234:    # replicaset
   235:    if new_resource.is_replicaset && new_resource.auto_configure_replicaset
   236>>     rs_nodes = search(
   237:        :node,
   238:        "mongodb_cluster_name:#{new_resource.cluster_name} AND "\
   239:        'mongodb_is_replicaset:true AND '\
   240:        "mongodb_config_mongod_replication_replSetName:#{new_resource.replicaset_name} AND "\
   241:        "chef_environment:#{node.chef_environment}"
   242:      )
   243:
   244:      ruby_block 'config_replicaset' do
   245:        block do

   System Info:
   ------------
   chef_version=13.8.5
   platform=centos
   platform_version=7.4.1708
   ruby=ruby 2.4.3p205 (2017-12-14 revision 61247) [x86_64-linux]
   program_name=chef-client worker: ppid=28997;start=00:31:33;
   executable=/opt/chef/bin/chef-client


   Running handlers:
   [2018-03-27T00:31:35+00:00] ERROR: Running exception handlers
   Running handlers complete
   [2018-03-27T00:31:35+00:00] ERROR: Exception handlers complete
   Chef Client failed. 0 resources updated in 01 seconds
   [2018-03-27T00:31:35+00:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
   [2018-03-27T00:31:35+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
   [2018-03-27T00:31:35+00:00] ERROR: 400 "Bad Request"
   [2018-03-27T00:31:35+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

我已经尝试了很多方法来解决这个问题,查看 github 存储库中的 issues。从错误来看,似乎没有设置属性,所以人们手动设置它们。 :

# attempt1------------

#node.default['mongodb']['config']['replSet'] = true
#node.default[:mongodb][:cluster_name] = "repl-name"
#include_recipe "sc-mongodb::replicaset"

# attempt2----------

#node.normal['mongodb']['install_method'] = 'mongodb-org'
#node.normal['mongodb']['config']['bind_ip'] = '0.0.0.0'
#node.normal['mongodb']['dbconfig_file'] = '/etc/mongod.conf'
#node.normal['mongodb']['config']['replSet'] = true
#node.normal['mongodb']['is_replicaset'] = true
#node.normal['mongodb']['cluster_name'] = 'scribe'
#node.normal['mongodb']['replSet'] = 'scribe'
#node.normal['mongodb']['is_shard'] = false
#include_recipe "sc-mongodb::replicaset"

#attempt3------------
#node.default[:mongodb][:cluster_name] = "cluster_name"
#include_recipe "sc-mongodb::replicaset"

#attempt4------------

#if node['mongodb']['config']['replSet'].nil?
#  node.default['mongodb']['config']['replSet'] = "repl-name"
#end
#include_recipe "sc-mongodb::replicaset"

#attempt5-------------

#https://github.com/sous-chefs/mongodb/issues/167
#node.default['mongodb']['config']['mongod']['replication']['replSetName'] = "rs-name"
#include_recipe "sc-mongodb::replicaset"

这个给了我一个不同的错误:

#attempt6-----------
node.default['mongodb']['config']['mongod']['replication']['replSetName']= 'rs_default'
node.default['mongodb']['cluster_name'] = 'cluster'
node.default['mongodb']['auto_configure']['replicaset'] = true
include_recipe "sc-mongodb::replicaset"

堆栈跟踪:

           ================================================================================
       Error executing action `run` on resource 'ruby_block[config_replicaset]'
       ================================================================================

       NoMethodError
       -------------
       undefined method `[]' for nil:NilClass

       Cookbook Trace:
       ---------------
       /tmp/kitchen/cache/cookbooks/sc-mongodb/libraries/mongodb.rb:74:in `configure_replicaset'
       /tmp/kitchen/cache/cookbooks/sc-mongodb/definitions/mongodb.rb:246:in `block (3 levels) in from_file'

       Resource Declaration:
       ---------------------
       # In /tmp/kitchen/cache/cookbooks/sc-mongodb/definitions/mongodb.rb

       244:     ruby_block 'config_replicaset' do
       245:       block do
       246:         MongoDB.configure_replicaset(node, replicaset_name, rs_nodes) unless new_resource.replicaset.nil?
       247:       end
       248:       action :nothing
       249:     end
       250:

       Compiled Resource:
       ------------------
       # Declared in /tmp/kitchen/cache/cookbooks/sc-mongodb/definitions/mongodb.rb:244:in `block in from_file'

       ruby_block("config_replicaset") do
         params {:mongodb_type=>"mongod", :action=>[:enable, :start], :logpath=>"/var/log/mongodb/mongod.log", :configservers=>[], :replicaset=>true, :notifies=>[], :not_if=>[], :name=>"mongod"}
         action [:nothing]
         retries 0
         retry_delay 2
         default_guard_interpreter :default
         block_name "config_replicaset"
         declared_type :ruby_block
         cookbook_name "sc-mongodb"
         recipe_name "replicaset"
         block #<Proc:0x00000003ebdec8@/tmp/kitchen/cache/cookbooks/sc-mongodb/definitions/mongodb.rb:245>
       end

       Platform:
       ---------
       x86_64-linux

【问题讨论】:

    标签: mongodb chef-infra cookbook


    【解决方案1】:

    这本食谱给我带来了很多麻烦,你并不孤单。

    根据我收集到的信息,您需要多次运行此说明书和/或以不同的配置运行,具体取决于您要达到的目标或节点所处的状态。例如,我认为 auto_configure 属性应该只在其他节点被设置为 false 之后,为集合中的最后一个节点设置。同样对于他们的用户配方,mongodb 只允许在主节点上进行 admin coll 操作,因此您应确保此配方在指定的主节点上执行。

    不幸的是,文档不清楚,对于像我这样的 Chef 和 Ruby 新手来说,src 和错误很难解释。我还在整理这本食谱,如果我有具体的东西可以给你报告,你能在你的帖子里完成这个工作吗?抱歉,我无法提供更多帮助,您必须尝试使用​​测试厨房 VM 进行配置。

    【讨论】:

    • 不幸的是,自从这篇文章以来我没有让它工作。我尝试根据人们在 github repo 中发布的问题配置 test-kitchen 中的属性。复制会很高兴,以后有时间可能会再次访问它。
    • 我决定不使用它并自己制作一个简单得多的食谱。我会尽快更新我的帖子,因为我现在只有一个独立的部署配方。
    • 看看这个,看看你的想法:gist.github.com/7opf/…我认为可以相对容易地扩展复制(见gist.github.com/7opf/2e2f391ab1b70271b9701584e95cfc4a
    猜你喜欢
    • 1970-01-01
    • 2013-12-14
    • 1970-01-01
    • 1970-01-01
    • 2014-03-17
    • 2021-11-18
    • 1970-01-01
    • 2011-06-22
    • 1970-01-01
    相关资源
    最近更新 更多