Uživatelské nástroje

Nástroje pro tento web


vagrant

Vagrant

Create and configure lightweight, reproducible, and portable development environments.

Homepage: https://www.vagrantup.com/
Documentation: https://docs.vagrantup.com/v2/

Instalace na Windows 7

VirtualBox instaluji, protože nechci použít Hyper-v.

Oracle VM VirtualBox version: 5.0.20
Vagrant version: 1.8.1

První spuštění

# vagrant init hashicorp/precise32
# vagrant up

Na Windows 7 to vypadá následovně.

PS C:\HashiCorp\Vagrant\test> vagrant init hashicorp/precise32
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
PS C:\HashiCorp\Vagrant\test> vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'hashicorp/precise32' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
==> default: Loading metadata for box 'hashicorp/precise32'
    default: URL: https://atlas.hashicorp.com/hashicorp/precise32
==> default: Adding box 'hashicorp/precise32' (v1.0.0) for provider: virtualbox
    default: Downloading: https://vagrantcloud.com/hashicorp/boxes/precise32/versions/1.0.0/providers/virtualbox.box
    default: Progress: 100% (Rate: 446k/s, Estimated time remaining: --:--:--)
==> default: Successfully added box 'hashicorp/precise32' (v1.0.0) for 'virtualbox'!
==> default: Importing base box 'hashicorp/precise32'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'hashicorp/precise32' is up to date...
==> default: Setting the name of the VM: test_default_1425998687541_86834
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 => 2222 (adapter 1)
==> 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:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if its present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> 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: 4.2.0
    default: VirtualBox Version: 4.3
==> default: Mounting shared folders...
    default: /vagrant => C:/HashiCorp/Vagrant/test
PS C:\HashiCorp\Vagrant\test>

Help

Usage: vagrant [options] <command> [<args>]

    -v, --version                    Print the version and exit.
    -h, --help                       Print this help.

Common commands:
     box             manages boxes: installation, removal, etc.
     connect         connect to a remotely shared Vagrant environment
     destroy         stops and deletes all traces of the vagrant machine
     global-status   outputs status Vagrant environments for this user
     halt            stops the vagrant machine
     help            shows the help for a subcommand
     init            initializes a new Vagrant environment by creating a Vagrantfile
     login           log in to HashiCorp's Atlas
     package         packages a running vagrant environment into a box
     plugin          manages plugins: install, uninstall, update, etc.
     provision       provisions the vagrant machine
     push            deploys code in this environment to a configured destination
     rdp             connects to machine via RDP
     reload          restarts vagrant machine, loads new Vagrantfile configuration
     resume          resume a suspended vagrant machine
     share           share your Vagrant environment with anyone in the world
     ssh             connects to machine via SSH
     ssh-config      outputs OpenSSH valid configuration to connect to the machine
     status          outputs status of the vagrant machine
     suspend         suspends the machine
     up              starts and provisions the vagrant environment
     version         prints current and latest Vagrant version

For help on any individual command run `vagrant COMMAND -h`

Additional subcommands are available, but are either more advanced
or not commonly used. To see all subcommands, run the command
`vagrant list-commands`.

Vagrant boxes online

Vlastní Vagrant Box

Lze najít desítky důvodů, proč si vytvořit vlastní Vagrant Box. Pro mě je to specifické nastavení a SW pro projekty v JAVA EE.

Následující návod popisuje vytvoření základního Vagrant Boxu:

  • distribuce GNU/Linux CentOS 7.0 x64 minimal

1. Download CentOS

Stáhnout CentOS 7.0 Minimal iso obraz.

2. Run and config VirtualBox

Vytvořit virtuální server s následujícím nastavením:

  • Name: CentOS-7-minimal
  • Type: Linux
  • Version: Red Hat (64bit)
  • Memory size: 1 GB
  • Hard drive file type: VMDK (Virtual Machine Disk)
  • Hard drive size: 40 GB

V nastavení vytvořeného vyrtuálního serveru (Settings):

  • Audio: disable
  • USB: disable
  • Network
    • Adapter 1: Nat, Advanced: Port Forwarding
    • Port Forwarding Rules
      • Name: SSH
      • Protocol: TCP
      • Host IP: -
      • Host Port: 2222
      • Guest IP: -
      • Guest Port: 22

3. Install CentOS

Základní instalace CentOS do virtuálního stroje. Nastavit si lokalizaci a automatickou detekci sítě, jinak je možné vše ponechat ve výchozím stavu.

4. Settings CentOS

Změnit heslo správce systému root na vagrant.

# passwd

Přidat uživatele vagrant s heslem vagrant.

# adduser vagrant
# passwd vagrant

Nastavit pro uživatele vagrant sudo pro vše.

# visudo

Vložit řádek.

vagrant ALL=(ALL) NOPASSWD: ALL

Zakomentovat řádek.

#Defaults requiretty

Vyzkoušíme si dostupnost sítě.

# ping cesnet.cz

Provedeme aktualizaci systému.

# yum update

Nainstalovat Guest Tools

Vybrat v menu DevicesInsert Guest Additions CD image …

# yum groupinstall "Development Tools"
# yum install kernel-devel kernel-devel-3.10.0-123.el7.x86_64 wget
# mkdir /media/cdrom
# mount /dev/cdrom /media/cdrom
# cd /media/cdrom
# ./VBoxLinuxAdditions.run
# cd; umount /media/cdrom
# yum clean all

Kontrola instalace Guest Tools

# lsmod | grep vbox

Nastavení SSH pro uživatele vagrant.

# mkdir /home/vagrant/.ssh
# wget --no-check-certificate https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub -O /home/vagrant/.ssh/authorized_keys
# chmod 0700 /home/vagrant/.ssh
# chmod 0600 /home/vagrant/.ssh/authorized_keys
# chown -R vagrant:vagrant /home/vagrant/.ssh

Vypnout

# shutdown -h now

4. Sestavení Vagrant Boxu

  • base = název z Oracle VM VirtualBox
  • output = název boxu
vagrant package --base CentOS-7-minimal --output CentOS-7-minimal.box
$ vagrant package --base CentOS-7-minimal --output CentOS-7-minimal.box
==> CentOS-7-minimal: Exporting VM...
==> CentOS-7-minimal: Compressing package to: c:/install/vagrant-boxes/CentOS-7-minimal.box

5. Test

vagrant package --base CentOS-7-minimal --output CentOS-7-minimal.box
vagrant box add testbox C:\install\vagrant-boxes\CentOS-7-minimal.box
vagrant init testbox
vagrant up

Přihlášení přes SSH

Host: localhost
Port: 2222
Uživatel: root
Heslo: vagrant

Vagrant Boxes

Vagrant Boxy vycházející z vlastního Vagrant Boxu.

* CentOS 7.0 x64 minimal

Plan

  • CentOS 7.0 x64 JAVA EE
  • CentOS 7.0 x64 PosgtreSQL
  • CentOS 7.0 x64 Puppet

Ansible Vagrant Box

vagrant package --base CentOS-7-minimal --output ansible.box
vagrant box add app C:\install\vagrant-boxes\ansible.box
vagrant box add app /c/install/vagrant-boxes/ansible.box
vagrant init app
vagrant up

JAVA EE Vagrant Box

vagrant package --base CentOS-7-minimal --output javaee.box
vagrant box add app C:\install\vagrant-boxes\javaee.box
vagrant box add app /c/install/vagrant-boxes/javaee.box
vagrant init app
vagrant up

Port Forward

WildFly

Vagrantfile
config.vm.network "forwarded_port", guest: 8080, host: 8080

PostgreSQL

Vagrantfile
config.vm.network "forwarded_port", guest: 5432, host: 5432

MySQL

Vagrantfile
config.vm.network "forwarded_port", guest: 3306, host: 3306
vagrant.txt · Poslední úprava: 2016/07/20 15:05 autor: blazek