Vagrant 流浪汉+;可分解超慢

Vagrant 流浪汉+;可分解超慢,vagrant,ansible,vagrantfile,Vagrant,Ansible,Vagrantfile,我使用Vagrant和Ansible创建了一个VM,当我尝试在启动后使用它时,我注意到它非常慢。我还在云中使用一个远程数据库,但这似乎不是响应速度慢的原因。我所说的慢响应是指大部分时间加载一个页面大约需要5秒 流浪汉档案 # -*- mode: ruby -*- # vi: set ft=ruby : # Vagrantfile API/syntax version. Don't touch unless you know what you're doing! VAGRANTFILE_API_

我使用Vagrant和Ansible创建了一个VM,当我尝试在启动后使用它时,我注意到它非常慢。我还在云中使用一个远程数据库,但这似乎不是响应速度慢的原因。我所说的慢响应是指大部分时间加载一个页面大约需要5秒

流浪汉档案

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
    # Set the box name and URL
    config.vm.box = "trusty-server"
    config.vm.box = "skeleton"
    config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box"

    # Hostmanager plugin config
    config.hostmanager.enabled           = true
    config.hostmanager.manage_host       = true
    config.hostmanager.ignore_private_ip = false
    config.hostmanager.include_offline   = true


    # Fix TTY problem
    config.ssh.shell = "bash -c 'BASH_ENV=/etc/profile exec bash'"

    # Basic box configuration
    config.vm.network "private_network", ip: "192.168.100.102"
    config.vm.hostname = "skeleton.ontherocks.dev"
    config.hostmanager.aliases = %w(en.skeleton.ontherocks.dev)
    config.vm.synced_folder ".", "/vagrant", :mount_options => ['dmode=777', 'fmode=777']

    # Provision using Ansible
    config.vm.provision "ansible" do |ansible|
        ansible.playbook = "provisioning/playbook.yml"
    end

    config.vm.provision :hostmanager
end
剧本

- hosts: default
  remote_user: vagrant
  sudo: true
  sudo_user: root

  tasks:
    ##
    # Update apt packages
    #
    - name: General | Update apt packages.
      apt: update_cache=yes

    ##
    # Apt package instalation of required software
    #
    - name: General | Install required packages.
      apt: pkg={{ item }} state=present
      with_items:
        - build-essential
        - php5
        - apache2
        - php5-mysql
        - sendmail
        - php5-mcrypt
        - php5-curl
        - php5-gd

    ##
    # Apache2 setup
    #
    - name: Apache | Enable required modules
      action: command a2enmod rewrite vhost_alias

    - name: Apache | Configuration file for our site
      action: template src=templates/etc-apache2-sites-available-website-conf.j2 dest=/etc/apache2/sites-available/website.conf

    - name: Apache | Disable the default site
      action: command a2dissite 000-default

    - name: Apache | Enable our new site
      action: command a2ensite website
      notify:
        - Restart Apache

    - name: PHP | Enable required modules
      action: command php5enmod mcrypt
      notify:
        - Restart Apache

    ##
    # Website setup
    #
    - name: Website | Set up file and directory permissions
      file: path=/vagrant/craft/storage/ mode=0777 recurse=yes state=directory
      sudo: yes

  ##
  # Restart services
  #
  handlers:
    - name: Restart Apache
      service: name=apache2 state=restarted

使用nfs加快共享文件夹的速度

 config.vm.synced_folder ".", "/vagrant", :nfs => { :mount_options => ["dmode=777","fmode=777"] }
加快虚拟机联网速度

 config.vm.provider "virtualbox" do |vb|
    vb.customize ["modifyvm", :id, "--nictype1", "virtio"]        
 end

这使我的网络容量增加了10-15倍。

您使用的是哪家提供商,即VirtualBox?你提供的东西会有很多磁盘IO吗?VirtualBox,当然不会有很多磁盘IO。主机不是问题所在,因为VM正在使用的任何计算机上都会发生这种情况。请尝试将该文件夹与rsync同步,并告诉我问题是否消失:`config.VM.synced_folder”“,“/vagrant”,键入:“rsync”``您也在Windows计算机上吗?主机是Ubuntu,VM也是。