Advertisement
asanchez75

vagrant

Aug 30th, 2012
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.10 KB | None | 0 0
  1. Links
  2. http://www.vagrantbox.es/
  3. http://unfoldthat.com/2011/05/06/using-vagrant-for-your-django-development.html
  4. http://paperairoplane.net/?p=240
  5. http://blog.mozilla.org/webdev/2011/10/04/developing-with-vagrant-puppet-and-playdoh/
  6. http://blog.smalleycreative.com/tutorials/setup-a-django-vm-with-vagrant-virtualbox-and-chef/
  7. http://www.djangobook.com/en/2.0/
  8. http://css.dzone.com/articles/creating-virtual-server
  9.  
  10. Vagrant es un programa escrito en Ruby que permite configurar varias máquinas virtuales y ejecutarlas transparentemente en la máquina host.
  11.  
  12. Se instala por apt-get install vagrant
  13.  
  14. 1. Usa un box por cada máquina virtual. El box se descarga usando un comando como
  15.  
  16. vagrant box add lucid32 http://files.vagrantup.com/lucid32.box
  17.  
  18. que es almacenado en la ruta /home/asanchez75/.vagrant.d/boxes
  19.  
  20. 2. Uno puede crear varios máquinas virtuales basadas en un solo box. De allí que es mejor crear una carpeta en
  21.  
  22. /home/asanchez75/Vagrant
  23.  
  24. y dentro de alli crear una carpeta por cada máquina Vagrant que creemos, por ejemplo para una llamada ubuntu sería
  25. /home/asanchez75/Vagrant/ubuntu
  26.  
  27. 3. Dentro de la carpeta
  28. /home/asanchez75/Vagrant/ubuntu
  29. ejecutamos el comando
  30.  
  31. vagrant init lucid32
  32.  
  33. Eso creará un archivo de configuración dentro de esta carpeta llamado Vagrantfile que será el que editemos para descargar los paquetes que necesitará mi máquina virtual vagrant.
  34. Hay dos grandes repositorios para descargar estos paquetes, uno es Puppet y el otro es Chef.
  35. Nosotros usaremos Puppet para este ejemplo.
  36. Para ello creamos una carpeta dentro de '/home/asanchez75/Vagrant/ubuntu' llamada 'manifests' y dentro de esa carpeta creamos un archivo llamado 'lucid32.pp' con el siguiente contenido
  37.  
  38. =================================================================
  39. class lucid32 {
  40. exec { "apt_update":
  41. command => "apt-get update",
  42. path => "/usr/bin"
  43. }
  44.  
  45. package { "php5":
  46. ensure => present,
  47. }
  48.  
  49. package { "libapache2-mod-php5":
  50. ensure => present,
  51. }
  52.  
  53. package { "apache2":
  54. ensure => present,
  55. }
  56.  
  57. service { "apache2":
  58. ensure => running,
  59. require => Package["apache2"],
  60. }
  61. }
  62.  
  63. include lucid32
  64. =================================================================
  65. Después, editamos el archivo de configuración 'Vagrantfile', que quedaría así
  66. ==================================================================================
  67. # -*- mode: ruby -*-
  68. # vi: set ft=ruby :
  69.  
  70. Vagrant::Config.run do |config|
  71. # All Vagrant configuration is done here. The most common configuration
  72. # options are documented and commented below. For a complete reference,
  73. # please see the online documentation at vagrantup.com.
  74.  
  75. # Every Vagrant virtual environment requires a box to build off of.
  76. config.vm.box = "lucid32"
  77.  
  78. # The url from where the 'config.vm.box' box will be fetched if it
  79. # doesn't already exist on the user's system.
  80. # config.vm.box_url = "http://domain.com/path/to/above.box"
  81.  
  82. # Boot with a GUI so you can see the screen. (Default is headless)
  83. # config.vm.boot_mode = :gui
  84.  
  85. # Assign this VM to a host-only network IP, allowing you to access it
  86. # via the IP. Host-only networks can talk to the host machine as well as
  87. # any other machines on the same network, but cannot be accessed (through this
  88. # network interface) by any external networks.
  89. # config.vm.network :hostonly, "33.33.33.10"
  90.  
  91. # Assign this VM to a bridged network, allowing you to connect directly to a
  92. # network using the host's network device. This makes the VM appear as another
  93. # physical device on your network.
  94. # config.vm.network :bridged
  95.  
  96. # Forward a port from the guest to the host, which allows for outside
  97. # computers to access the VM, whereas host only networking does not.
  98. config.vm.forward_port 80, 4567
  99.  
  100. # Share an additional folder to the guest VM. The first argument is
  101. # an identifier, the second is the path on the guest to mount the
  102. # folder, and the third is the path on the host to the actual folder.
  103. # config.vm.share_folder "v-data", "/vagrant_data", "../data"
  104.  
  105. # Enable provisioning with Puppet stand alone. Puppet manifests
  106. # are contained in a directory path relative to this Vagrantfile.
  107. # You will need to create the manifests directory and a manifest in
  108. # the file lucid32.pp in the manifests_path directory.
  109. #
  110. # An example Puppet manifest to provision the message of the day:
  111. #
  112. # # group { "puppet":
  113. # # ensure => "present",
  114. # # }
  115. # #
  116. # # File { owner => 0, group => 0, mode => 0644 }
  117. # #
  118. # # file { '/etc/motd':
  119. # # content => "Welcome to your Vagrant-built virtual machine!
  120. # # Managed by Puppet.\n"
  121. # # }
  122. #
  123. config.vm.provision :puppet do |puppet|
  124. puppet.manifests_path = "manifests"
  125. puppet.manifest_file = "lucid32.pp"
  126. end
  127.  
  128. # Enable provisioning with chef solo, specifying a cookbooks path (relative
  129. # to this Vagrantfile), and adding some recipes and/or roles.
  130. #
  131. # config.vm.provision :chef_solo do |chef|
  132. # chef.cookbooks_path = "cookbooks"
  133. # chef.add_recipe "mysql"
  134. # chef.add_role "web"
  135. #
  136. # # You may also specify custom JSON attributes:
  137. # chef.json = { :mysql_password => "foo" }
  138. # end
  139.  
  140. # Enable provisioning with chef server, specifying the chef server URL,
  141. # and the path to the validation key (relative to this Vagrantfile).
  142. #
  143. # The Opscode Platform uses HTTPS. Substitute your organization for
  144. # ORGNAME in the URL and validation key.
  145. #
  146. # If you have your own Chef Server, use the appropriate URL, which may be
  147. # HTTP instead of HTTPS depending on your configuration. Also change the
  148. # validation key to validation.pem.
  149. #
  150. # config.vm.provision :chef_client do |chef|
  151. # chef.chef_server_url = "https://api.opscode.com/organizations/ORGNAME"
  152. # chef.validation_key_path = "ORGNAME-validator.pem"
  153. # end
  154. #
  155. # If you're using the Opscode platform, your validator client is
  156. # ORGNAME-validator, replacing ORGNAME with your organization name.
  157. #
  158. # IF you have your own Chef Server, the default validation client name is
  159. # chef-validator, unless you changed the configuration.
  160. #
  161. # chef.validation_client_name = "ORGNAME-validator"
  162. end
  163. ==================================================================================
  164. 4. Ejecutamos el comando
  165. vagrant up
  166. para inicializar nuestra máquina virtual
  167. 5. Nos logueamos por ssh usando el comando
  168. vagrant ssh
  169. 6. Dentro ya de nuestro servidor virtual reinicializamos el apache
  170. 7. Ubicamos las paginas que vayamos creando en nuestra maquina virtual usando
  171.  
  172. http://localhost:4567
  173.  
  174. 8. Para parar el servicio usar el comando
  175. vagrant halt
  176. 9. Si se desear borrar la máquina virtual y el box usar
  177. vagrant destroy
  178. Nota. Si el archivo 'Vagrantfile' contiene información sobre donde descargar el box y las demas configuraciones, entonces se puede borrar el box y cada vez que ejecutes
  179. vagrant up
  180. descargará el box y descargará los paquetes que hayas indicado.
  181. En conclusión, solo necesitas tener instalado el gem vagrant y un buen archivo de configuración Vagrantfile para tener tu VM en cualquier sitio :)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement