1

I have created a centos machine and installed nexus service over it. Nexus service is running on 8081 port which i have opened from the vagrant file using below command inside the vagrant file.

    machine1.vm.network "private_network", ip: "192.168.33.x"
    machine1.vm.network "forwarded_port", guest: 80, host: 80
    machine1.vm.network "forwarded_port", guest: 8080, host: 8080
    machine1.vm.network "forwarded_port", guest: 8081, host: 8081

The nexus service is running fine on the centos machine but the telnet to the port from the same server as well as server from its network is failing. The port is not reachable from the host windows machine as well.

The server IP is reachable from its network machines, here all 3 network machines are created from vagrant file

I have tried to see and confirm the nexus service is actually running on 8081 port, and its running

I have tried to open a port 8081 to ensure firewall is not blocking using below command

iptables -A INPUT -p tcp -m tcp --dport 8081 -j ACCEPT

I have browsed through multiple forum to see if any solution works, I acknowledge this is very generic error even i have faced in past, but in this case not able to identify the root cause. I doubt if its related to vagrant specific configuration

Also, i tried to curl the service from centos server and host server, it doesnt work:

]$ curl http://localhost:8081
curl: (7) Failed connect to localhost:8081; Connection refused

netstat command doesnt give any result:

netstat -an|grep 8081
[vagrant@master1 bin]$

however the nexus service is up and running on the server with the same port

Here is vagrant file code

   config.vm.define "machine1" do |machine1|
    machine1.vm.provider "virtualbox" do |host|
      host.memory = "2048"
      host.cpus = 1
    end
    machine1.vm.hostname = "machine1"
    machine1.vm.network "private_network", ip: "192.168.33.x3"
    machine1.vm.network "forwarded_port", guest: 80, host: 80
    machine1.vm.network "forwarded_port", guest: 8080, host: 8080
    machine1.vm.network "forwarded_port", guest: 8081, host: 8081
    machine1.vm.synced_folder "../data", "/data"
   end


      config.vm.define "machine2" do |machine2|
              machine2.vm.provider "virtualbox" do |host|
      host.memory = "2048"
      host.cpus = 1
    end
    machine2.vm.hostname = "machine2"
    machine2.vm.box = "generic/ubuntu1804"
    machine2.vm.box_check_update = false
    machine2.vm.network "private_network", ip: "192.168.33.x2"
    machine2.vm.network "forwarded_port", guest: 80, host: 85
    machine2.vm.network "forwarded_port", guest: 8080, host: 8085
    machine2.vm.network "forwarded_port", guest: 8081, host: 8090
   end

   config.vm.define "master" do |master|
      master.vm.provider "virtualbox" do |hosts|
        hosts.memory = "2048"
        hosts.cpus = 2
      end
      master.vm.hostname = "master"
      master.vm.network "private_network", ip: "192.168.33.x1"
   end

end

As the nexus service is running on port 8081, i should be able to access the service from my host machine using http://localhost:8081.

Jagdish0886
  • 343
  • 1
  • 5
  • 20

2 Answers2

1

The issue is most likely the Vagrant networking as you guessed. If you just want to access the nexus service running on guest from the host, perhaps this can be useful. To workaround, you may try to make the Vagrant box available on public network and then access it using the public IP and for that, you will have to enable config.vm.network "public_network" in your Vagrant file and then just do a vagrant reload. Once done, try accessing http://public_IP_of_guest:8081

Please let me know how it goes.

st_rt_dl_8
  • 317
  • 2
  • 11
  • I tried the solution, but i am sorry it doesn't work – Jagdish0886 Sep 09 '19 at 05:38
  • Did you **disable** the port forwarding and try with: 1. Assigning an IP from your Host's IP range to the Vagrant box. 2. Assigning a Public IP by enabling `config.vm.network "public_network"` to the vagrant box and then accessing http://public_IP_of_guest:8081 I cant see any reason for it to not work provided your nexus service is running and listening on 8081 fine. Above all, try it with just one Vagrant box and share the results? – st_rt_dl_8 Sep 09 '19 at 06:02
  • Ok.. let me try with that option – Jagdish0886 Sep 09 '19 at 06:03
  • I run into some other issue while trying these things, where my machine1 and machine2 servers are not up with ssh, I am not able to establish a connection over ssh. However master machine works well. Neither i am able to establish ssh from master to machine1, which i was able to earlier. Error from vagrant reload log is : machine1: Warning: Connection aborted. Retrying... – Jagdish0886 Sep 09 '19 at 06:08
  • Okay, let me try with your Vagrant file. So you need to access Nexus service from another Vagrant box or from the host machine? – st_rt_dl_8 Sep 09 '19 at 06:12
  • want to access the service from host machine, i was testing the port from another vagrant box, to troubleshoot the connectivity issue – Jagdish0886 Sep 09 '19 at 06:13
  • 1
    Are you following these many steps (https://stackoverflow.com/a/57183786/10846194) steps to install Nexus? If there are only a few steps, it would be nice if you could post the commands so that I can put them in a shell script to bootstrap the Vagrant box. – st_rt_dl_8 Sep 09 '19 at 06:17
  • Yes these are fine.. except last step which mentions about the 8081 port.. also you can consider just two vagrant boxes 1 is master and other is machine1 and i am using config.vm.box = "bento/centos-7.3" configuration for the image – Jagdish0886 Sep 09 '19 at 06:23
  • In case you are trying to replicate, you can try with apache/httpd service just to reduce efforts, as issue is with port accessibility.. and thank you for your time to answer/help. – Jagdish0886 Sep 09 '19 at 06:38
  • I found the root cause and solution, i missed to assign proper permissions to the directories: $ sudo chown -R nexus:nexus /opt/nexus $ sudo chown -R nexus:nexus /opt/sonatype-work the above communication actually helped me to narrow down to the issue as the thread mentioned in above post has all the steps, i tried to replicate those steps in separate vagrant box and could come to conclusion with the solution – Jagdish0886 Sep 09 '19 at 10:37
  • Glad it worked! Reproducing this issue was on my TBD for today anyways :) – st_rt_dl_8 Sep 10 '19 at 03:34
  • Ok please let me know if you could replicate and whether you found any alternate solution and see any other problem there – Jagdish0886 Sep 10 '19 at 07:09
0

This may have many sources cause. In my case, I use vagrant fedora boxe. I tried:

  • First using the private_network that I attached to a host only adapter and launched httpd service to test the connection between guest and host

      config.vm.network "private_network", type: "dhcp", name: "vboxnet2"
      config.vm.network "forwarded_port", guest:80, host:7070
    

but I was not able to ping my guest machine from the host and could no telnet the httpd service opened

  • Second using public_network and launched httpd service to test connectivity

      config.vm.network "public_network", bridge: "en0: Wi-Fi (AirPort)", use_dhcp_assigned_default_route: true
    

I could ping my guest from my host but I could not telnet the httpd service.

For this two use case, the issue was that the port 80 on the fedora guest host was blocked by the firewall. Here is what fixed the issue and get all working for both privat_network and public_ntwork:

   firewall-cmd --permanent --add-port 80/tcp  #open the port permanently
   firewall-cmd --zone=public --permanent --add-service=http 
   firewall-cmd --list-port  # list to check if the port was opened   
   systemctl stop firewalld   # stop and open the firewall service
   systemctl start firewalld
onlyme
  • 3,776
  • 2
  • 23
  • 17