Arquivo da categoria: Vagrant

Tutorial Vagrant

– Vagrant init:

vagrant init bento/ubuntu-16.04-i386

– Editando o arquivo Vagrant:
[code type=txt]
VAGRANTFILE_API_VERSION = ‘2’

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = ‘/
config.ssh.insert_key = false # linha obrigatória para Windows

config.vm.network :forwarded_port, guest: 3000, host: 3000 # rails
config.vm.network :forwarded_port, guest: 9292, host: 9292 # rack
config.vm.network :forwarded_port, guest: 4567, host: 4567 # sinatra
config.vm.network :forwarded_port, guest: 1080, host: 1080 # mailcatcher
config.vm.network :forwarded_port, guest: 8888, host: 8888 # jasmine
config.vm.network :forwarded_port, guest: 3306, host: 3306 # mysql
config.vm.network :forwarded_port, guest: 1234, host: 1234 # node
config.vm.network :forwarded_port, guest: 5432, host: 5432 # postgresql
config.vm.network :forwarded_port, guest: 6379, host: 6379 # redis
config.vm.network :forwarded_port, guest: 9200, host: 9200 # elasticsearch
config.vm.network :forwarded_port, guest: 27017, host: 27017 # mongodb
config.vm.network :forwarded_port, guest: 80, host: 8080 # apache/nginx
end

– Inicie a nova máquina virtual:

vagrant up --provide virtualbox

– Acesando:

vagrant ssh

Instalando e configurando o Vagrant

1)  Baixe e instale o VirtualBox ( virtualbox.org )

2)  Baixe e instale o Vagrant ( vagrantup.com )

3)  Acesse o vagrandcloud.com e escolha sua box base

4)  Adicione a box ao vagrant ( vagrant box add <sua>/<box> )

5)  Caso esteja usando o Windows configure o puTTY

a) Baixe o puTTY e o puTTYgen (putty.org)

b) Baixe a chave privada (//raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant )
c) Abra o puTTYgen, clique em ” LOAD ” e informe a chave privada que você baixou.

d) Ainda no puTTYgen, clique no bota?o ” SAVE PRIVATE KEY “, clique em ” YES ” para confirmar que na?o quer password.

e) Salve o arquivo com o nome ” vagrant.ppk ” na mesma pasta do arquivo ” insecure_private_key ” (geralmente c:\users\<seu_usuario>\.vagrant.d )

6)  Inicie a configurações de uma nova máquina virtual ( vagrant init bento/ubuntu­16.04 )

7)  Adicione o plugin vbguest ( vagrant plugin install vagrant­vbguest )

8)  Ajuste o arquivo Vagrantfile (//gist.github.com/jacksonpires/403ac7e61dfd70e302b1da281decbe15 )
[code type=txt]
VAGRANTFILE_API_VERSION = ‘2’

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = ‘/
config.ssh.insert_key = false # linha obrigatória para Windows

config.vm.network :forwarded_port, guest: 3000, host: 3000 # rails
config.vm.network :forwarded_port, guest: 9292, host: 9292 # rack
config.vm.network :forwarded_port, guest: 4567, host: 4567 # sinatra
config.vm.network :forwarded_port, guest: 1080, host: 1080 # mailcatcher
config.vm.network :forwarded_port, guest: 8888, host: 8888 # jasmine
config.vm.network :forwarded_port, guest: 3306, host: 3306 # mysql
config.vm.network :forwarded_port, guest: 1234, host: 1234 # node
config.vm.network :forwarded_port, guest: 5432, host: 5432 # postgresql
config.vm.network :forwarded_port, guest: 6379, host: 6379 # redis
config.vm.network :forwarded_port, guest: 9200, host: 9200 # elasticsearch
config.vm.network :forwarded_port, guest: 27017, host: 27017 # mongodb
config.vm.network :forwarded_port, guest: 80, host: 8080 # apache/nginx
end

9)  Inicie a nova ma?quina virtual ( vagrant up ­­provider virtualbox )

10)Acesse a nova ma?quina via SSH

a) Para Mac/Linux use vagrant ssh b) Para Windows configure o puTTY

i)  Abra o PuTTY e use o endereço de conexão vagrant@127.0.0.1 e use a porta 2222 .

ii)  Selecione a seção “Connection > SSH > Auth”.

iii)  Clique no botão “Browse” e selecione o arquivo “vagrant.ppk” salvo em c:\users\<seu_usuario>\.vagrant.d\vagrant.ppk .

iv)  Volte ate? a seção “Session”, digite um nome no campo “Saved Sessions” e clique no botão “Save”.

v)  Para iniciar a conexão, clique no botão “Open”, presente na seção “Session” . Se tudo der certo pode aparecer uma janela perguntando se quer conectar no servidor. Clique no botão “Yes”.

How to export a Vagrant virtual machine to transfer it

You have two ways to do this, I’ll call it dirty way and clean way:

1. The dirty way

Create a box from your current virtual environment, using vagrant package command:

//docs.vagrantup.com/v2/cli/package.html

Then copy the box to the other pc, add it using vagrant box add and run it using vagrant up as usual.

Keep in mind that files in your working directory (the one with the Vagrantfile) are shared when the virtual machine boots, so you need to copy it to the other pc as well.

2. The clean way

Theoretically it should never be necessary to do export/import with Vagrant. If you have the foresight to use provisioning for configuring the virtual environment (chef, puppet, ansible), and a version control system like git for your working directory, copying an environment would be at this point simple as running:

<code>git clone &lt;your_repo&gt;
vagrant up
</code>

//stackoverflow.com/questions/20679054/how-to-export-a-vagrant-virtual-machine-to-transfer-it