I created a MongoDB GCE instance using Vagrantfile. Then enabled 'Allow HTTP traffic' and added protocol:port tcp:27017 using the console. Everything works fine, but I want to avoid using the console. Can anyone help me enable 'Allow HTTP traffic' and add 'port tcp:27017' with Vagrantfile?
Here is part of my 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
Did you check the vagrant documentation on forwarded ports ?
Should be something like:
Vagrant.configure("2") do |config|
config.vm.box = "google/gce"
config.vm.network "forwarded_port", guest: 80, host: 27017
#... rest of your config
end
添加网络标签就可以了。
google.tags = ['http-server']
you will have to add a firewall rule and add a "target tag" on it eg test-1, then on your vagrant file you will have to use this line google.tags = ['test-1']
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'
google.tags = ['test-1'] <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
override.ssh.username = "me"
override.ssh.private_key_path = "~/.ssh/gce"
end
config.vm.provision :shell, path: "install.sh"
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.