6
respostas

Falha ao configurar public_network

Boa tarde, pessoal!

Tentei configurar o ambiente para rede pública, mas sem sucesso D= localhost funciona corretamente, no virtualbox aparece normalmente o segundo adaptador de rede em modo bridge, mas quando tento acessar o endereço de ip no navegador nada carrega. Tentei tanto usar reload quanto destroy. Estou sem saber o que fazer T_T Segue o log ao fazer reload:

==> default: Attempting graceful shutdown of VM...
==> default: Checking if box 'ubuntu/bionic64' version '20210415.0.0' is up to date...==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Available bridged network interfaces:
1) Realtek PCIe GbE Family Controller
2) Hyper-V Virtual Ethernet Adapter
==> default: When choosing an interface, it is usually the one that is
==> default: being used to connect to the internet.
==> default:
    default: Which interface should the network bridge to? 2
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: bridged
==> default: Forwarding ports...
    default: 80 (guest) => 8080 (host) (adapter 1)
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection reset. Retrying...
    default: Warning: Connection aborted. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see  
    default: shared folder errors, please make sure the guest additions within the    
    default: virtual machine match the version of VirtualBox you have installed on    
    default: your host and reload your VM.
    default:
    default: Guest Additions Version: 5.2.42
    default: VirtualBox Version: 6.1
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => D:/03_Estudos/Alura/DevOps/Vagrant/bionic
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still 
run.

OBS: Já tentei nas duas opções de bridge network também. Qual seria a diferença entre elas?

6 respostas

A "Realtek PCIe GbE Family Controller" seria a tua placa de rede física e a "Hyper-V Virtual Ethernet Adapter" seria o adaptador de rede criada por padrão na quando foi habilitado o Hyper-V no Windows. Por padrão, ao habilitar o Hyper-V é criada esta virtual ethernet automaticamente e ela passa a receber o endereçamento IP da máquina, enquanto a inteface física (a Realtek) ficaria atuando somente como uma bridge mesmo.

Ao subir a configuração do Vagrant, por padrão selecione o adaptador que estiver recebendo o IP. Caso esteja em dúvida ou queira confirmar, você pode verificar isso na "Central de Redes e Compartilhamento" do Windows.

Por via das dúvidas, confirme qual é a interface a ser utilizada, dê um 'vagrant destroy -f' e suba o ambiente novamente, assim garantindo que as VMs sejam criadas totalmente do zero.

Raquel, posta também seu vagrantfile.

default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key

Pelo log acima pode ter alguma estrutura incorreta no arquivo de configuração do Vegrant file. Poderia postar?

Olá, pessoal.

Desculpem a demora. Como terminei o curso sem consertar essa parte, meu Vangrantfile está grande... não reparem na bagunça, por favor. Removi a parte relacionada a criação de outras máquinas e deixei só uma como exemplo.

Obrigada pela atenção!

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/bionic64"

  config.vm.define "mysqldb" do |mysql|
    mysql.vm.network "forwarded_port", guest: 80, host:8080
    mysql.vm.network "private_network", type: "dhcp"
    # mysql.vm.network "public_network", ip: "192.168.1.66"
    mysql.vm.synced_folder "./config", "/config"
    mysql.vm.synced_folder ".", "/vagrant", disabled: true
    mysql.vm.provision "shell",
      inline: "cat /config/id_bionic.pub >> .ssh/authorized_keys"
    mysql.vm.provision "shell",
      inline: $mysql_server_installation
    mysql.vm.provision "shell",
      inline: "cat /config/mysqld.cnf > /etc/mysql/mysql.conf.d/mysqld.cnf"
    mysql.vm.provision "shell",
      inline: "service mysql restart"
  end
end

Raquel, vc verificou essa linha:

mysql.vm.network "private_network", type: "dhcp"

Segundo a sua dificuldade, vc queria colocar rede public (via dhcp). Mas aqui vc está configurando uma rede privada.

Altere para:

mysql.vm.network "public_network", type: "dhcp"

Essa linha que você mencionou está funcionando perfeitamente, inclusive foi apenas com ela que consegui fazer completar o curso. Nessa aula, o prof está configurando a rede pública para tornar a vm acessível para todos na rede com acesso a esse endereço de IP e com a chave pública. A que está comentada é a que dá problema - nela é configurada a public network mesmo. Não impede o funcionamento, mas também não consigo acessar do endereço especificado que seria o 192.168.1.66. Ele não está sendo usado por nenhum dispositivo na minha rede, então creio o problema não seja esse.

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software