How To: Vagrant - erste Schritte

mastercad
21.04.2014 23:42:12
Heute möchte ich mit einer kleinen Reihe über Vagrant beginnen, da ich derzeit meinen Media Server neu aufgesetzt habe und mich während dessen dazu entschieden habe, jeden Zuständigkeitsbereich des Servers in einzelne Virtuelle Server zu kapseln um das System im allgemeinen Stabiler zu machen und jedem Server seine Aufgabe zukommen zu lassen ohne die anderen Funktionalitäten des Servers zu kompromittieren.

Beginnen wir mit einem Problem, was ich auf meinem Server mit dem OS Ubuntu 12.04 i686 LTS hatte.

Wir installieren zu erst Vagrant aus dem Ubuntu Repo:


BASH code

  1. sudo apt-get install vagrant

nach der installation versuchte ich eine box anzulegen:


BASH code

  1. vagrant init hashicorp/precise32
  2. A `Vagrantfile` has been placed in this directory. You are now
  3. ready to `vagrant up` your first virtual environment! Please read
  4. the comments in the Vagrantfile as well as documentation on
  5. `vagrantup.com` for more information on using Vagrant.



diese Meldung besagt eigentlich nichts, außer das ein Vagrantfile angelegt wurde mit den eben getätigten angaben.

mit einem beherzten vagrant up kam folgendes:


BASH code

  1. vagrant up
  2. There was a problem with the configuration of Vagrant. The error message(s)
  3. are printed below:
  4.  
  5. vm:
  6. * The box 'hashicorp/precise32' could not be found.


ich habe danach noch einige weitere Schritte unternommen um zu versuchen, precise32 zu installieren, erfolglos. Rückblickend sehe ich gerade beim durchsehen der Logs, das ich scheinbar auch bei weiteren versuchen einem Syntaxfehler unterlag. Fakt ist, ein einfaches


BASH code

  1. vagrant init precise32
  2. ...
  3. vagrant up


tat es einfach nicht und das stellte mich nicht zufrieden, im Internet las ich in diversen Foren, das es in der Version 1.0.x Probleme bei diesem vorgehen gab, da ich in der Hinsicht ziemlich schmerzbefreit bin, war ich natürlich sofort bereit mich von dieser Version zu trennen, zumal es mittlerweile Version 1.5.3 gibt...

meine aktuelle version:


BASH code

  1. vagrant -v
  2. Vagrant version 1.0.3


also nix wie runter ...


BASH code

  1. sudo apt-get remove --purge vagrant


dann habe ich unter folgendem Link das Ubuntu *.deb Paket geladen, es ist einmal als 32bit und als 64bit Version verfügbar.


BASH code

  1. cd ~/Downloads
  2. wget https://dl.bintray.com/mitchellh/vagrant/vagrant_1.5.3_i686.deb
  3. --2014-04-21 19:46:43-- https://dl.bintray.com/mitchellh/vagrant/vagrant_1.5.3_i686.deb
  4. Resolving dl.bintray.com (dl.bintray.com)... 5.153.24.114
  5. Connecting to dl.bintray.com (dl.bintray.com)
    5.153.24.114
    :443... connected.
  6. HTTP request sent, awaiting response... 200 OK
  7. Length: 54110140 (52M) [application/octet-stream]
  8. Saving to: `vagrant_1.5.3_i686.deb`
  9.  
  10. 100%[===================================================================>] 54,110,140 1.80M/s in 33s
  11.  
  12. Last-modified header invalid -- time-stamp ignored.
  13. 2014-04-21 19:47:18 (1.55 MB/s) - `vagrant_1.5.3_i686.deb` saved [54110140/54110140]

danach installieren wir erst einmal das neue Paket


BASH code

  1. sudo dpkg -i ~/Downloads/vagrant_1.5.3_i686.deb

und sind damit bereit für unsere ersten wirklichen Gehversuche ohne ein hoffnungslos veraltetes Vagrant.

An die Übersicht aller möglichen Befehle von Vagrant kommt man mit folgendem Aufruf:


BASH code

  1. vagrant -h
  2. Usage: vagrant [options] <command> [<args>]
  3.  
  4. -v, --version Print the version and exit.
  5. -h, --help Print this help.
  6.  
  7. Common commands:
  8. box manages boxes: installation, removal, etc.
  9. connect connect to a remotely shared Vagrant environment
  10. destroy stops and deletes all traces of the vagrant machine
  11. halt stops the vagrant machine
  12. help shows the help for a subcommand
  13. init
  14. initializes a new Vagrant environment by creating a Vagrantfile
  15. login log in to Vagrant Cloud
  16. package packages a running vagrant environment into a box
  17. plugin manages plugins: install, uninstall, update, etc.
  18. provision provisions the vagrant machine
  19. reload restarts vagrant machine, loads new Vagrantfile configuration
  20. resume resume a suspended vagrant machine
  21. share share your Vagrant environment with anyone in the world
  22. ssh connects to machine via SSH
  23. ssh-config outputs OpenSSH valid configuration to connect to the machine
  24. status outputs status of the vagrant machine
  25. suspend suspends the machine
  26. up starts and provisions the vagrant environment
  27.  
  28. For help on any individual command run `vagrant COMMAND -h`
  29.  
  30. Additional subcommands are available, but are either more advanced
  31. or not commonly used. To see all subcommands, run the command
  32. `vagrant list-commands`.


Also erneut der Versuch ein erstes Image bereit zu stellen und eine erste Box aufzusetzen:


BASH code

  1. vagrant box add precise32 http://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-i386-vagrant-disk1.box
  2. ==> box: Adding box 'precise32' (v0) for provider:
  3. box: Downloading: http://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-i386-vagrant-disk1.box
  4. ==> box: Successfully added box 'precise32' (v0) for 'virtualbox'!


Voila, es ist vollbracht, wir haben hiermit unser erstes Image gezogen und es unter unserem aktuellen User für alle weiteren Vagrant Inits zur Verfügung gestellt. Es wurde abgelegt unter ~/.vagrant.d/boxes/precise32/0/virtualbox/. In diesem Ordner befinden sich jetzt folgende Dateien:


BASH code

  1. ls -lisa ~/.vagrant.d/boxes/precise32/0/virtualbox/
  2. total 342924
  3. 2906811 4 drwxrwxr-x 2 xbmc xbmc 4096 Apr 21 20:09 .
  4. 2906810 4 drwxrwxr-x 3 xbmc xbmc 4096 Apr 21 20:09 ..
  5. 2906806 342896 -rw------- 1 xbmc xbmc 351124992 Apr 21 20:09 box-disk1.vmdk
  6. 2906804 12 -rw------- 1 xbmc xbmc 10506 Apr 21 20:09 box.ovf
  7. 2906808 4 -rw-rw-r-- 1 xbmc xbmc 25 Apr 21 20:09 metadata.json
  8. 2906805 4 -rw-r--r-- 1 xbmc xbmc 505 Apr 21 20:09 Vagrantfile

löschen läßt sich so ein Image übrigens mit:


BASH code

  1. vagrant destroy precise32
  2. Removing box 'precise32' (v0) with provider 'virtualbox'...

Aber nicht so voreilig ..., wir können nun damit unsere erste Box erstellen:


BASH code

  1. vagrant init precise32
  2. A `Vagrantfile` has been placed in this directory. You are now
  3. ready to `vagrant up` your first virtual environment! Please read
  4. the comments in the Vagrantfile as well as documentation on
  5. `vagrantup.com` for more information on using Vagrant.

danach können wir sie direkt starten:


BASH code

  1. Bringing machine 'default' up with 'virtualbox' provider...
  2. ==> default: Clearing any previously set forwarded ports...
  3. ==> default: Clearing any previously set network interfaces...
  4. ==> default: Preparing network interfaces based on configuration...
  5. default: Adapter 1: nat
  6. ==> default: Forwarding ports...
  7. default: 22 => 2222 (adapter 1)
  8. ==> default: Booting VM...
  9. ==> default: Waiting for machine to boot. This may take a few minutes...
  10. default: SSH address: 127.0.0.1:2222
  11. default: SSH username: vagrant
  12. default: SSH auth method: private key
  13. default: Warning: Connection timeout. Retrying...
  14. default: Warning: Connection timeout. Retrying...
  15. default: Warning: Connection timeout. Retrying...
  16. default: Warning: Connection timeout. Retrying...
  17. default: Warning: Connection timeout. Retrying...
  18. default: Warning: Remote connection disconnect. Retrying...
  19. default: Warning: Remote connection disconnect. Retrying...
  20. default: Warning: Remote connection disconnect. Retrying...
  21. default: Warning: Remote connection disconnect. Retrying...
  22. default: Warning: Remote
  23. connection disconnect. Retrying...
  24. default: Warning: Remote connection disconnect. Retrying...
  25. ==> default: Machine booted and ready!
  26. ==> default: Checking for guest additions in VM...
  27. ==> default: Mounting shared folders...


das verbinden dauerte bei mir ungewöhnlich lang, nachdem die Box aber beim 2. Versuch, sie zu starten, auch lief, gab es keine weiteren Probleme.

Dieser Beitrag wird im Laufe der nächsten Zeit durch weitere ergänzt, unter anderem, wie man einen LDAP Server aufsetzt, einen Git und SVN Server, wie man einen FTP aufsetzt, wie man XBMC Frodo und Gotham installiert und wie man diese ganzen Vagrant Boxen parallel auf einem Rechner laufen läßt und diese Multiboxen managed.

Seid gespannt... ;)