Arquivo da tag: Vagrant

Configurando o Ubuntu Linux para o Rails

Atualize o Sistema Operacional

$ sudo apt­get update 
$ sudo apt­get upgrade

Instale os seguintes pacotes

$ sudo apt­get install ­y build­essential autoconf bison libssl­dev libyaml­dev libreadline6­dev zlib1g­dev libncurses5­dev libffi­dev libgdbm­dev

Instale o Git

$ apt­get install git

Configure o Git

$ git config ­­global user.name '<seu nome>' 
$ git config ­­global user.email <seu email>

Confirme as configurac?o?es

$ git config ­l

Instale o CURL

$ sudo apt­get install curl

Instalando o RVM

$ gpg ­­keyserver hkp://keys.gnupg.net ­­recv­keys 409B6B1796C275462A1703113804BB82D39DC0E3 
$ curl ­sSL https://get.rvm.io | bash

Carregando o RVM a primeira vez

$ source /home/vagrant/.rvm/scripts/rvm

Listando as verso?es conhecidas do Ruby

$ rvm list known

Instalando a versa?o do Ruby desejada

$ rvm install 2.3

Verifique a versa?o instalada

$ rvm list

Use uma versa?o especi?fica e a torne padra?o

$ rvm use 2.3 ­­default

Instale o Rails

$ gem install rails ­v 4.2.5

Verifique se o Rails foi instalado

$ rails ­v

Instale o NodeJS

$ sudo apt­get install nodejs

Verifique se o NodeJS foi instalado

$ nodejs ­­version

Instale o MySQL

$ sudo apt­get install mysql­client mysql­server libmysqlclient­dev

Verifique se o MySQL foi instalado acessando sua CLI

$ mysql ­u root ­p

Instale o PostgreSQL

$ sudo apt­get install postgresql postgresql­contrib libpq­dev

Crie um usua?rio para acessar o PostgreSQL

$ sudo ­u postgres createuser ­rds vagrant

Crie um banco de dados com o mesmo nome de usua?rio

$ createdb vagrant

Acesse o PostgreSQL

$ psql

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 (https://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 (https://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:

http://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:

git clone <your_repo>
vagrant up

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

SSHKit::Command::Failed: bundle exit status: 137

Caso esse problema apareça basta fazer isso:

1.Instale o software htop de monitoramento de CPU para verificar o uso da CPU:

sudo apt-get install htop

2.Pare o processo do servidor:

ps aux | grep 'unicorn' | awk '{print $2}' | xargs sudo kill -9

3.Rode o htop para monitorar o uso da CPU.

Se você ficar monitorando, verá que o problema todo é a memória, basta aumentar a memória no Vagrantfile.

Referência