vagrant 入门3

建立第一个Vagrant虚拟环境以及工程(续集):

(8) Provisioning:html

      一般状况下Box只作最基本的设置,而不是一次到位的设置好全部的环境。Vagrant一般使用chef或者Puppet来作进一步的环境搭建。apache

      回到刚才建立的index.html,咱们须要安装Apache。咱们下面用Puppet来完成这一设置。浏览器

    1. 在项目的根目录下建立文件夹manifests,而后在该文件家中建立Puppet的配置文件default.pp,该文件内容以下:     ui

   
   
   
   
# Basic Puppet Apache manifestclass apache { exec { 'apt-get update': command => '/usr/bin/apt-get update' } package { "apache2": ensure => present, } service { "apache2": ensure => running, require => Package["apache2"], }}include apache
   2. 在Vagrantfile里添加对Puppet provisioning的支持:
    
    
    
    
Vagrant::Config.rundo|config| config.vm.box="base" # Enable the Puppet provisioner config.vm.provision:puppetend

(9) 运行Projectspa

        为了使puppet的配置生效,若是不重启虚机,则须要执行vagrant reload命令。vagrant

     
     
     
     
$ vagrant reload
        由于没有配置port forwarding,因此你还不能从本地浏览器查看Project的输出。只能SSH到虚拟机上查看127.0.0.1的输出:


(10) 进行端口映射code

        修改Vagrantfile, 添加本地端口和虚机端口的映射关系, 而后执行vagrant reload, 而后你就能够经过本地浏览器来访问:http://localhost:4567.  htm


      
      
      
      
Vagrant::Config.run do |config| # Forward guest port 80 to host port 4567 config.vm.forward_port 80, 4567 end





相关文章
相关标签/搜索