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





相關文章
相關標籤/搜索