1

“精神错乱:一遍又一遍地做同样的事情,却期待不同的结果。” - 艾尔伯特爱因斯坦

我有一个 vagrant + chef (w/chef-zero Berkshelf) 构建的盒子,可以运行很多程序,包括 zend-server-php、mongos 和 erlang。我正在使用由 Berkshelf 管理的流行食谱和一个基本的 CentOS 6 盒子(存储在我本地的 Mac 上)。第一次(在 a 之后vagrant destroy)启动此框通常需要多次尝试。上面列出的vagrant up程序之一将失败,我必须vagrant provision一遍又一遍地运行(有时多达 6 次)才能顺利完成整个构建。然而,在极少数情况下,星星会对齐,一切都会在第一次尝试时启动。

我看到的错误通常是明确的超时错误(尽管并非总是如此)。我通常从相当弱的办公室网络连接(<20 Mbps 下降)运行它,这可能解释了为什么在最大下载时会发生故障。

所以这是我的问题:首先,除了网络连接之外,还有其他一些变量可以解释为什么我必须这样做vagrant provision多次使用?如果是这样,我该如何测试和治疗它?其次,有没有办法让 vagrant 继续配置,直到它成功为止?我还没有找到这样做的记录标志/设置,但感觉可能有一个......

谢谢你的帮助。

更新:

这是一个 zend-server-php-5.4 失败的例子:

==> mongos-zend: Running triggers before provision...
the ffi-yajl and yajl-ruby gems have incompatible C libyajl libs and should not be loaded in the same Ruby VM
falling back to ffi which might work (or might not, no promises)
Loading cookbooks from chef-repo/cookbooks
Uploading Cookbook apt
Uploading Cookbook build-essential
Uploading Cookbook cb-platform
Uploading Cookbook chef-sugar
Uploading Cookbook erlang
Uploading Cookbook hostsfile
Uploading Cookbook mongodb
Uploading Cookbook mysql
Uploading Cookbook openssl
Uploading Cookbook percona
Uploading Cookbook postgresql
Uploading Cookbook python
Uploading Cookbook rabbitmq
Uploading Cookbook rbac
Uploading Cookbook resource-control
Uploading Cookbook role-mongodb-configserver
Uploading Cookbook role-mongodb-mongos
Uploading Cookbook role-mongodb-replicaset1
Uploading Cookbook role-mongodb-replicaset2
Uploading Cookbook role-mongodb-shard1
Uploading Cookbook role-mongodb-shard2
Uploading Cookbook role-rabbitmq
Uploading Cookbook role-sphinx
Uploading Cookbook role-twemcache
Uploading Cookbook role-zendserver
Uploading Cookbook runit
Uploading Cookbook smf
Uploading Cookbook sphinx
Uploading Cookbook yum
Uploading Cookbook yum-epel
Uploading Cookbook yum-erlang_solutions
Uploading Cookbook yum-mysql-community
Uploading Cookbook zendserver
==> mongos-zend: Chef 12.0.3 Omnibus package is already installed.
==> mongos-zend: Running provisioner: shell...
    mongos-zend: Running: inline script
==> mongos-zend: Running provisioner: chef_client...
==> mongos-zend: Creating folder to hold client key...
==> mongos-zend: Uploading chef client validation key...
Generating chef JSON and uploading...
==> mongos-zend: Running chef-client...
==> mongos-zend: [2015-01-20T10:46:10-06:00] INFO: Forking chef instance to converge...
==> mongos-zend: [2015-01-20T10:46:10-06:00] INFO: *** Chef 11.10.4 ***
==> mongos-zend: [2015-01-20T10:46:10-06:00] INFO: Chef-client pid: 13175
==> mongos-zend: [2015-01-20T10:46:11-06:00] INFO: Setting the run_list to ["recipe[role-mongodb-mongos::default]", "recipe[role-zendserver::default]", "recipe[role-rabbitmq::default]", "recipe[role-twemcache::default]", "recipe[role-sphinx::default]", "recipe[cb-platform::default]"] from JSON
==> mongos-zend: [2015-01-20T10:46:11-06:00] INFO: Run List is [recipe[role-mongodb-mongos::default], recipe[role-zendserver::default], recipe[role-rabbitmq::default], recipe[role-twemcache::default], recipe[role-sphinx::default], recipe[cb-platform::default]]
==> mongos-zend: [2015-01-20T10:46:11-06:00] INFO: Run List expands to [role-mongodb-mongos::default, role-zendserver::default, role-rabbitmq::default, role-twemcache::default, role-sphinx::default, cb-platform::default]
==> mongos-zend: [2015-01-20T10:46:11-06:00] INFO: Starting Chef Run for mongos-zend
==> mongos-zend: [2015-01-20T10:46:11-06:00] INFO: Running start handlers
==> mongos-zend: [2015-01-20T10:46:11-06:00] INFO: Start handlers complete.
==> mongos-zend: [2015-01-20T10:46:11-06:00] INFO: HTTP Request Returned 404 Not Found : Object not found: /reports/nodes/mongos-zend/runs
==> mongos-zend: [2015-01-20T10:46:11-06:00] INFO: Loading cookbooks [apt, build-essential, cb-platform, chef-sugar, erlang, hostsfile, mongodb, mysql, openssl, percona, postgresql, python, rabbitmq, rbac, role-mongodb-mongos, role-rabbitmq, role-sphinx, role-twemcache, role-zendserver, runit, smf, sphinx, yum, yum-epel, yum-erlang_solutions, yum-mysql-community, zendserver]
==> mongos-zend: [2015-01-20T10:46:11-06:00] WARN: CentOS doesn't provide mongodb, forcing use of mongodb-org repo
==> mongos-zend: [2015-01-20T10:46:11-06:00] WARN: 10gen_repo is deprecated, use mongodb_org_repo
==> mongos-zend: [2015-01-20T10:46:11-06:00] WARN: Cloning resource attributes for package[mongo-10gen-server] from prior resource (CHEF-3694)
==> mongos-zend: [2015-01-20T10:46:11-06:00] WARN: Previous package[mongo-10gen-server]: /var/chef/cache/cookbooks/role-mongodb-mongos/recipes/default.rb:15:in `block in from_file'
==> mongos-zend: [2015-01-20T10:46:11-06:00] WARN: Current  package[mongo-10gen-server]: /var/chef/cache/cookbooks/mongodb/recipes/install.rb:65:in `from_file'
==> mongos-zend: [2015-01-20T10:46:13-06:00] WARN: Cloning resource attributes for template[/etc/mongodb.conf] from prior resource (CHEF-3694)
==> mongos-zend: [2015-01-20T10:46:13-06:00] WARN: Previous template[/etc/mongodb.conf]: /var/chef/cache/cookbooks/mongodb/recipes/install.rb:14:in `from_file'
==> mongos-zend: [2015-01-20T10:46:13-06:00] WARN: Current  template[/etc/mongodb.conf]: /var/chef/cache/cookbooks/mongodb/definitions/mongodb.rb:139:in `block in from_file'
==> mongos-zend: [2015-01-20T10:46:13-06:00] WARN: Cloning resource attributes for package[gcc] from prior resource (CHEF-3694)
==> mongos-zend: [2015-01-20T10:46:13-06:00] WARN: Previous package[gcc]: /var/chef/cache/cookbooks/mongodb/recipes/mongo_gem.rb:3:in `from_file'
==> mongos-zend: [2015-01-20T10:46:13-06:00] WARN: Current  package[gcc]: /var/chef/cache/cookbooks/role-zendserver/recipes/default.rb:34:in `block in from_file'
==> mongos-zend: [2015-01-20T10:46:14-06:00] INFO: hostsfile_entry[33.33.33.42] content already matches - nothing to do.
==> mongos-zend: [2015-01-20T10:46:14-06:00] INFO: hostsfile_entry[33.33.33.43] content already matches - nothing to do.
==> mongos-zend: [2015-01-20T10:46:14-06:00] INFO: Starting install for package zend-server-php-5.4
==> mongos-zend: [2015-01-20T10:30:22-06:00] INFO: package[zend-server-php-5.4] installing zend-server-php-5.4-6.2.0-2002 from zend-server repository
==> mongos-zend: 
==> mongos-zend: ================================================================================
==> mongos-zend: Error executing action `install` on resource 'package[zend-server-php-5.4]'
==> mongos-zend: ================================================================================
==> mongos-zend: 
==> mongos-zend: 
==> mongos-zend: Chef::Exceptions::Exec
==> mongos-zend: 
==> mongos-zend: ----------------------
==> mongos-zend:  returned 1, expected 0
==> mongos-zend: 
==> mongos-zend: 
==> mongos-zend: Resource Declaration:
==> mongos-zend: ---------------------
==> mongos-zend: # In /var/chef/cache/cookbooks/zendserver/recipes/default.rb
==> mongos-zend: 
==> mongos-zend:  65: package package_name do
==> mongos-zend:  66:   :install
==> mongos-zend:  67:   notifies :restart, 'service[zend-server]', :immediate 
==> mongos-zend:  68: end
==> mongos-zend:  69: 
==> mongos-zend: 
==> mongos-zend: 
==> mongos-zend: 
==> mongos-zend: Compiled Resource:
==> mongos-zend: ------------------
==> mongos-zend: # Declared in /var/chef/cache/cookbooks/zendserver/recipes/default.rb:65:in `from_file'
==> mongos-zend: 
==> mongos-zend: package("zend-server-php-5.4") do
==> mongos-zend:   action :install
==> mongos-zend:   retries 0
==> mongos-zend:   retry_delay 2
==> mongos-zend:   package_name "zend-server-php-5.4"
==> mongos-zend:   version "6.2.0-2002"
==> mongos-zend:   cookbook_name "zendserver"
==> mongos-zend:   recipe_name "default"
==> mongos-zend: end
4

1 回答 1

2

带宽、CPU、I/O、错误,所有这些都可能会增加资源收敛时间,这可能会导致超时。尝试增加 VM 的资源(CPU、RAM),如果可能的话,在主机上使用 SSD 等。

至于运行vagrant provision直到成功,您可能只需将其包装在一个 while 循环中:

false; while [ "$?" -ne "0" ]; do vagrant provision; done
于 2015-01-20T13:23:04.143 回答