我如何增加内存和设置主机只在流浪者网络?

我想增加内存至少1 GB,我想配置“主机只”网络使用“199.188.44.20”。

这是我的 Vagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :


Vagrant::Config.run do |config|


config.vm.customize ["modifyvm", :id, "--memory", 1024]


config.vm.network :hostonly, "199.188.44.20"


config.vm.define :web do |web_config|
web_config.vm.box = "lucid32"
web_config.vm.forward_port 80, 8080


web_config.vm.provision :puppet do |puppet|
puppet.manifests_path = "manifests"
puppet.manifest_file = "lucid32.pp"
end
end


config.vm.define :web2 do |web2_config|
web2_config.vm.box = "lucid32"
web2_config.vm.forward_port 80, 8081


web2_config.vm.provision :puppet do |puppet|
puppet.manifests_path = "manifests"
puppet.manifest_file = "myweb.pp"
end
end
end

然而,当我运行 vagrant up时,我得到:

VM 在试图引导时未能保持“运行”状态。这通常是由于配置错误或主机系统不兼容造成的。请打开 VirtualBoxGUI 并尝试手动启动虚拟机以获取更多信息性错误消息

并且,当我尝试登录到 VM 时,我得到了一个 connection refuse错误。

108225 次浏览

You can modify various VM properties by adding the following configuration (see the Vagrant docs for a bit more info):

  # Configure VM Ram usage
config.vm.customize [
"modifyvm", :id,
"--name", "Test_Environment",
"--memory", "1024"
]

You can obtain the properties that you want to change from the documents for VirtualBox command-line options:

The vagrant documentation has the section on how to change IP address:

Vagrant::Config.run do |config|
config.vm.network :hostonly, "192.168.50.4"
end

Also you can restructure the configuration like this, ending is do with end without nesting it. This is simpler.

config.vm.define :web do |web_config|
web_config.vm.box = "lucid32"
web_config.vm.forward_port 80, 8080
end
web_config.vm.provision :puppet do |puppet|
puppet.manifests_path = "manifests"
puppet.manifest_file = "lucid32.pp"
end

Since Vagrant 1.1 customize option is getting VirtualBox-specific.

The modern way to do it is:

config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "256"]
end

I could not get any of these answers to work. Here's what I ended up putting at the very top of my Vagrantfile, before the Vagrant::Config.run do block:

Vagrant.configure("2") do |config|
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", "1024"]
end
end

I noticed that the shortcut accessor style, "vb.memory = 1024", didn't seem to work.

To increase the memory or CPU count when using Vagrant 2, add this to your Vagrantfile

Vagrant.configure("2") do |config|
# usual vagrant config here


config.vm.provider "virtualbox" do |v|
v.memory = 1024
v.cpus = 2
end
end

You can easily increase your VM's RAM by modifying the memory property of config.vm.provider section in your vagrant file.

config.vm.provider "virtualbox" do |vb|
vb.memory = "4096"
end

This allocates about 4GB of RAM to your VM. You can change this according to your requirement. For example, following setting would allocate 2GB of RAM to your VM.

config.vm.provider "virtualbox" do |vb|
vb.memory = "2048"
end

Try removing the config.vm.customize ["modifyvm", :id, "--memory", 1024] in your file, and adding the above code.

For the network configuration, try modifying the config.vm.network :hostonly, "199.188.44.20" in your file toconfig.vm.network "private_network", ip: "199.188.44.20"