I started a consul agent in dev mode by using the following inside a VM using Vagrant. The command I used is consul agent -dev
I confirmed that the UI is working fine by doing a curl on 8500. curl http://localhost:8500/ui
However when I am testing from the host machine using curl http://172.28.128.3:8500/ui I get the following error.
curl: (7) Failed to connect to 172.28.128.3 port 8500: Connection refused
What could be the error. Following is my VagrantFile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/bionic64"
config.vm.network "private_network", type: "dhcp"
end
I can see the following when I do vagrant ssh.
System load: 0.07 Processes: 99
Usage of /: 13.5% of 9.63GB Users logged in: 0
Memory usage: 12% IP address for enp0s3: 10.0.2.15
Swap usage: 0% IP address for enp0s8: 172.28.128.3
When I do the following nc -vz 172.28.128.3 8500 on my host mac I get the error
nc: connectx to 172.28.128.3 port 8500 (tcp) failed: Connection refused
There are a number of ways you can expose the running Consul agent UI in the box to the host.
Configure running service port to be forwarded to the host.
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/bionic64"
config.vm.network "private_network", type: "dhcp"
config.vm.network "forwarded_port", guest: 8500, host: 8500
end
The service would be available at http://localhost:8500/ui.
Configure a public network.
Tread with care as this exposes the entire box to the host.
Vagrant.configure("2") do |config|
config.vm.network "public_network", ip: "192.168.0.17"
end
Use vagrant connect command
vagrant connect
The resulting Static IP can be used together with the service port.
Related
I am working on a chef project which is running in Vagrant. I have installed chef server on my local machine and I need to connect it from vagrant instance. I am getting a connection refused. I have added port-forwarding, but vagrant wont let me forward port-443 as it's already occupied. My chef server is running on https i.e port-443.
Error log :
[2019-05-03T10:21:00+00:00] INFO: Client key /etc/chef/client.pem is not present - registering
[2019-05-03T10:21:00+00:00] ERROR: Connection refused connecting to https://my-system-product-name/organizations/internetdevelopment/clients, retry 1/5
[2019-05-03T10:21:05+00:00] ERROR: Connection refused connecting to https://my-system-product-name/organizations/internetdevelopment/clients, retry 2/5
VagrantFile :
Vagrant.configure("2") do |config|
config.vm.network "forwarded_port", guest: 443, host: 8443
config.vm.network "forwarded_port", guest: 80, host: 8080
i would offer you to assign a static ip address to your vagrant virtual machine (vm) rather than use a port forwarding.
You can also specify a static IP address for the machine. This lets you access the Vagrant managed machine using a static, known IP. The Vagrantfile for a static IP looks like this:
Vagrant.configure("2") do |config|
config.vm.network "private_network", ip: "192.168.50.4"
end
It is up to the users to make sure that the static IP does not collide with any other machines on the same network.
While you can choose any IP you would like, you should use an IP from the reserved private address space. These IPs are guaranteed to never be publicly routable, and most routers actually block traffic from going to them from the outside world.
I'm using a vagrant trusty64 box with nginx, flask, gunicorn and port forwarding is not working as expected
In the vagrant file, I have:
config.vm.network "forwarded_port", guest: 8090, host: 3100
config.vm.network "private_network", ip: "10.10.1.10"
On the box, I have run:
gunicorn myprj:app -b 10.10.1.10:8090
find nothing on host machine with http://10.10.1.10:3100
trying curl -v http://10.10.1.10:3100 gives the following output:
connect to 10.10.1.10 port 3100 failed: Connection refused
Reachable with guest port on host machine http://10.10.1.10:8090
I am new to the vagrant, did I miss/mess to Vagrant file.
Complete Vagrant file:
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.box_check_update = false
config.vm.network "forwarded_port", guest: 8090, host: 3100
config.vm.network "private_network", ip: "10.10.1.10"
config.vm.synced_folder ".", "/vagrant_data"
config.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
vb.name = "lopamudra_dev"
end
config.vm.provision "shell", inline: <<-SHELL
# Upgrading the environment
apt-get update
apt-get upgrade
# Installing nginx + uwsgi + flask
apt-get install -y python-pip python-dev nginx
pip install uwsgi flask gunicorn
SHELL
end
You are forwarding container 8090 to hostIP:3100 (localhost:3100)
At the same time you are creating a IP to access your container with 10.10.1.10 and you container has 8090 exposed, thats why you can acces it on 10.10.1.10:8090
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# NOTE: This will enable public access to the opened port
config.vm.network "forwarded_port", guest: 8090, host: 3100
# Create a private network, which allows host-only access to the machine
# using a specific IP.
config.vm.network "private_network", ip: "10.10.1.10"
I'm trying to set up CouchDB (and ultimately use PouchDB) on a Scotch Box VM. The VM runs fine, and includes port forwarding for port 5849 by including the code below:
Vagrant.configure("2") do |config|
config.vm.box = "scotch/box-pro"
config.vm.hostname = "scotchbox"
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.network "forwarded_port", guest: 5984, host: 5984
config.vm.network "forwarded_port", guest: 3000, host: 3000
config.vm.network "private_network", ip: "192.168.33.10"
The VM runs fine. localhost:8080 will load the PHP home page, and localhost:3000 will load a node script if I have the node server running, but localhost:5984 only returns an empty response when loaded from the browser or from the host machine command line using curl curl: (52) Empty reply from server.
When I have used vagrant ssh to access the VM, I can use curl localhost:5984 to obtain {"couchdb":"Welcome","uuid":"9cabeb8f66947adabe9443594aa7f69c","version":"1.6.0","vendor":{"version":"15.10","name":"Ubuntu"}} as expected.
Here is the guide I've been referring to: https://pouchdb.com/guides/setup-couchdb.html
Additional info: When I go to 192.168.33.10:5984 (instead of using the localhost port forwarding), the result is a refused connection.
Any suggestions as to what my issue might be? I had thought it was a forwarding issue, but the ports 8080 and 3000 work fine, and going to the IP:5984 doesn't work so it makes me wonder. I also thought maybe the service isn't running, but doing ssh on the VM and running curl seems to indicate that it is in fact running.
Thanks!
By default CouchDB bound to a localhost address 127.0.0.1 and you need to re-bind it to 0.0.0.0 to get it accessible from outside of Vagrant box. To do that you need to change parameter bind_address in [httpd] section of default.ini config file or add the same as override in local.ini config file.
Now, i have 2 vm machine
First vm running api server.
Second vm acting like client that perform request to the api endpoint.
The api server name is http://api.dev
The client server name is http://client.dev
Here is vagrant file for the api server:
Vagrant.configure(2) do |config|
config.vm.box = "lemp.dev"
config.vm.network "private_network", ip: "192.168.10.10"
config.vm.synced_folder "www", "/var/www/html"
end
Here is vagrant file for the client:
Vagrant.configure(2) do |config|
config.vm.box = "lemp.dev"
config.vm.network "private_network", ip: "192.168.10.11"
config.vm.synced_folder "www", "/var/www/html"
end
Here is host file on my host machine:
192.168.10.11 client.dev
192.168.10.10 api.dev
I can access the http://api.dev from my host machine.
Problem is, i cant access the http://api.dev from my client machine.When i run curl api.dev i got 404 page
What i want is to be able to access to the http://api.dev from another vm instance( the second vm ).
You would need to update the hosts file on the Guests (192.168.10.11 and 192.168.10.10) with the same thing you put on your Host, or you could just use the IPs and not have to worry about doing that.
I've been trying to change the mapping for a domain and forward it to a Vagrant machine that I've forwarded a port to.
The config in Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.network :forwarded_port, host: 4567, guest: 80
end
I've updated /etc/hosts on my Mac OSX with the following:
127.0.0.1:4567 example.com
Yet when I access from my browser example.com nothing changes, I have also tried to map example.com to go to the Google IP without any luck.
What am I overlooking?
I would just add a static ip, or try removing the port number:
Vagrant.configure("2") do |config|
config.vm.network "private_network", ip: "192.168.50.4"
end
Then in your hosts file change it to read:
192.168.50.4 example.com
More info is available here:
https://docs.vagrantup.com/v2/networking/private_network.html