我使用Vagrantfile创建了一个MongoDB GCE实例。然后使用控制台启用“允许HTTP流量”并添加protocol:port tcp:27017。一切正常,但我想避免使用控制台。 谁能帮助我启用“允许HTTP流量”并在Vagrantfile中添加“端口tcp:27017”?
这是我的Vagrantfile的一部分:
Vagrant.configure("2") do |config|
config.vm.box = "google/gce"
config.ssh.forward_agent = true
config.vm.provider :google do |google, override|
google.google_project_id = "projectxx"
google.google_client_email = "xx-compute@developer.gserviceaccount.com"
google.google_json_key_location = "~/gcp_service_keys/xx.json"
google.name = "namex"
google.zone = "us-central1-c"
google.image_family = 'ubuntu-1804-lts'
override.ssh.username = "me"
override.ssh.private_key_path = "~/.ssh/gce"
end
config.vm.provision :shell, path: "install.sh"
end
答案 0 :(得分:0)
您是否检查了流浪者documentation on forwarded ports?
应该是这样的:
Vagrant.configure("2") do |config|
config.vm.box = "google/gce"
config.vm.network "forwarded_port", guest: 80, host: 27017
#... rest of your config
end
答案 1 :(得分:0)
添加网络标签即可完成工作。
google.tags = ['http-server']
答案 2 :(得分:0)
您将必须添加防火墙规则并在其上添加“目标标记”,例如test-1,那么在您的流浪者文件上,您将必须使用以下行google.tags = ['test-1']
Vagrant.configure(“ 2”)做| config | config.vm.box =“ google / gce”
config.ssh.forward_agent = true
config.vm.provider :google do |google, override|
google.google_project_id = "projectxx"
google.google_client_email = "xx-compute@developer.gserviceaccount.com"
google.google_json_key_location = "~/gcp_service_keys/xx.json"
google.name = "namex"
google.zone = "us-central1-c"
google.image_family = 'ubuntu-1804-lts'
google.tags = ['test-1'] <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
override.ssh.username = "me"
override.ssh.private_key_path = "~/.ssh/gce"
end
config.vm.provision :shell, path: "install.sh"
结束