mac安装的vagrant访问laraval欢迎页面,执行时间15秒,安装nfs挂载点(亲测可行)「建议收藏」

mac安装的vagrant访问laraval欢迎页面,执行时间15秒,安装nfs挂载点(亲测可行)

大家好,又见面了,我是全栈君。

问题说明,在vagrant虚拟机中启动cii 框架项目的时候没问题,但在启动laravel项目的时候花费17S,这明显不符合常理吗?

造成此问题的原因,是虚拟机共享文件系统 IO 速度慢所导致的。而一个全新安装的 Laravel 应用响应一个请求时,需要读取 600+ 的文件,瓶颈尤为明显。

mac安装的vagrant访问laraval欢迎页面,执行时间15秒,安装nfs挂载点(亲测可行)「建议收藏」

补充:以下亲测可行方法

1.本地Mac系统不需要安装,我的是在不清楚的情况下安装了,每次报错,所以卸载就好

sudo rm /etc/exports
sudo touch /etc/exports

sudo chmod -R 777 exports  #有权限问题的话加这一步

sudo vagrant halt
sudo vagrant up --provision  #在启动过程中,会询问是否允许更改exports文件,直接允许就好
vagrant plugin uninstall vagrant-winnfsd  #卸载插件

2修改后: Vagrantfile 文件

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

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.

  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://vagrantcloud.com/search.
  config.vm.box = "centos"
  config.vm.boot_timeout = 360
  config.ssh.username = "vagrant"
  config.ssh.password = "vagrant"
  # Disable automatic box update checking. If you disable this, then
  # boxes will only be checked for updates when the user runs
  # `vagrant box outdated`. This is not recommended.
  # config.vm.box_check_update = false
  
# config.vm.network "forwarded_port", guest: 82, host: 8082, host_ip: "127.0.0.1"
 #  config.vm.network "forwarded_port", guest: 83, host: 8083, host_ip: "127.0.0.1"
  # config.vm.network "forwarded_port", guest: 84, host: 8084, host_ip: "127.0.0.1"
  # config.vm.network "forwarded_port", guest: 85, host: 8085, host_ip: "127.0.0.1"
  # config.vm.network "forwarded_port", guest: 86, host: 8086, host_ip: "127.0.0.1"
  # config.vm.network "forwarded_port", guest: 87, host: 8087, host_ip: "127.0.0.1"
  # config.vm.network "forwarded_port", guest: 3306, host: 33306, host_ip: "127.0.0.1"
  #  config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "localhost"
  # config.vm.network "forwarded_port", guest: 81, host: 8081, host_ip: "localhost"

config.vm.synced_folder "../../../Users/liutao/Desktop/vagrant", "/home/wwwroot/default",nfs: true,  nfs_udp: true
  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.
  # NOTE: This will enable public access to the opened port
  # config.vm.network "forwarded_port", guest: 80, host: 8080

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine and only allow access
  # via 127.0.0.1 to disable public access
  # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"

  # Create a private network, which allows host-only access to the machine
  # using a specific IP.

#私有网络   
config.vm.network "private_network", ip: "192.168.33.11"

#端口转发
#config.vm.network "forwarded_port", guest: 8080, host: 8080,   auto_correct: true

  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network.
  #  config.vm.network "public_network",ip: "192.168.33.10"

  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
  # config.vm.synced_folder "../data", "/vagrant_data"

  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:
  #
   config.vm.provider "virtualbox" do |vb|
  #   # Display the VirtualBox GUI when booting the machine
  #   vb.gui = true
  #
  #   # Customize the amount of memory on the VM:
     vb.memory = "512"
   end
  #
  # View the documentation for the provider you are using for more
  # information on available options.

  # Enable provisioning with a shell script. Additional provisioners such as
  # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
  # documentation for more information about their specific syntax and use.
  # config.vm.provision "shell", inline: <<-SHELL
  #   apt-get update
  #   apt-get install -y apache2
  # SHELL
end
 

修改后的/etc/exports 文件,这个是在vagrant up 启动过程中自动生成的

 

# VAGRANT-BEGIN: 0 528272d2-254a-4d20-a6cb-19671440688c
"/Users/liutao/Desktop/vagrant" 192.168.33.11 -alldirs -mapall=501:20
# VAGRANT-END: 0 528272d2-254a-4d20-a6cb-19671440688c
                                                      

成功启动后:

mac安装的vagrant访问laraval欢迎页面,执行时间15秒,安装nfs挂载点(亲测可行)「建议收藏」

如果报错

mac安装的vagrant访问laraval欢迎页面,执行时间15秒,安装nfs挂载点(亲测可行)「建议收藏」

sudo rm /etc/exports
sudo touch /etc/exports

sudo chmod -R 777 exports  #有权限问题的话加这一步

================以下仅供参考==============

Vagrant虚拟机系统:CentOS6.5

首先要把虚拟机的网络设置成 :private_network 模式。

1、虚拟机安装nfs服务:

centos 5 :

yum -y install nfs-utils portmap

centos 6 :

yum -y install nfs-utils rpcbind

2、MAC OS已经集成nfs,只需要修改/etc/eprots文件,如果没有则新建

sudo vi /etc/exports   保持空文件即可

3、Vagrantfile文件修改

config.vm.synced_folder ".", "/vagrant", type: "nfs"

保存后,使用命令 vagrant reload 重启虚拟机后才会生效,期间会修改MAC OX的 /etc/exports 文件。会提示输入mac账号的密码。输入即可!

2015-02-02最新更新:vagrant官方说明中发现了一段内同

        NFS synced folders have a set of options that can be specified that are unique to NFS. These are listed below. These options can be specified in the final part of theconfig.vm.synced_folder definition, along with the type option.

  • nfs_export (boolean) – If this is false, then Vagrant won’t modify your /etc/exportsautomatically and assumes you’ve done so already.
  • nfs_udp (boolean) – Whether or not to use UDP as the transport. UDP is faster but has some limitations (see the NFS documentation for more details). This defaults to true.
  • nfs_version (string | integer) – The NFS protocol version to use when mounting the folder on the guest. This defaults to 3.

可以设置 nfs_export的属性为true即可忽略文件的修改,会假设已经把文件设置好。

默认采用的是UDP协议。

NFS协议使用的版本:默认为3

 

 nfs   支持windows

vagrant plugin install vagrant-winnfsd
vagrant plugin list

卸载插件:https://stackoverflow.com/questions/54294057/vagrant-up-problem-sh-netsh-command-not-found

vagrant plugin uninstall vagrant-winnfsd

git commit 报错:

git pull 报错:error: insufficient permission for adding an object to repository database .git/objects

error: insufficient permission for adding an object to repository database .git/objects error: 无法创建树对象

解决方案:成功提交文件

在客户端,我的是mac端
sudo chmod 777 -R .git/objects

即可

mac安装的vagrant访问laraval欢迎页面,执行时间15秒,安装nfs挂载点(亲测可行)「建议收藏」

mac安装的vagrant访问laraval欢迎页面,执行时间15秒,安装nfs挂载点(亲测可行)「建议收藏」

mac安装的vagrant访问laraval欢迎页面,执行时间15秒,安装nfs挂载点(亲测可行)「建议收藏」

其他方式:可参考:NFS服务的用户身份映射  【NAS】NFS客户端挂载目录后无写入权限的解决方案

===================以下供参考,据说不太好使=====================

使用 Homestead 在开发 Laravel 应用程序,经常会遇到网页响应速度缓慢,有时甚至十几秒甚至几十秒才返回响应,极大影响了开发体验:mac安装的vagrant访问laraval欢迎页面,执行时间15秒,安装nfs挂载点(亲测可行)「建议收藏」

造成此问题的原因,是虚拟机共享文件系统 IO 速度慢所导致的。而一个全新安装的 Laravel 应用响应一个请求时,需要读取 600+ 的文件,瓶颈尤为明显。

解决问题
解决方案是让虚拟机使用 IO 效率更高的 NFS 挂载方式。

第一步、安装 NFS 服务
我们需要在主机的系统里安装 NFS 服务供虚拟机使用。

Mac 用户默认支持 NFS 挂载。

Windows 用户 需要安装 Vagrant WinNFSd ,在你的 Git Shell (或者其他 Windows Shell)里运行以下命令进行安装:

$ vagrant plugin install vagrant-winnfsd

Ubuntu 用户 可以使用以下命令安装 NFS 服务:

$ apt-get install nfs-kernel-server

第二步、修改配置
接下来修改 Homestead.yaml 文件里的 folders 文件挂载信息,指定挂载的 type 为 NFS:

folders:
    - map: ~/code
      to: /home/vagrant/code
      type: "nfs"

第三步、重启并应用虚拟机
因为我们修改了 Homestead.yaml ,需要 –provision 参数来应用虚拟机修改,并使用 reload 来重启虚拟机:

$ vagrant reload --provision

结语
以上配置成功后,一般情况下,你应该可以得到 1s 内的响应速度。
转自链接:https://learnku.com/laravel/wikis/2555

setp 1 :centos安装nfs

yum install nfs-utils rpcbind
setp 2 :MAC OS已经集成nfs,只需要修改/etc/exports文件,如果没有则新建

setp 3 : Vagrantfile文件修改

config.vm.synced_folder "~/www", "/data", type: “nfs"

注:~/www为mac机器的目录。/data为虚拟机的目录。
保存后,使用命令 vagrant reload 重启虚拟机后才会生效,期间会修改MAC OX的 /etc/exports 文件。会提示输入mac账号的密码。输入即可!

然后,你会发现mac上的~/www 目录和虚拟机上的/data目录是互通的。开始配置你的网站吧

window可参考:  https://blog.csdn.net/ghostyusheng/article/details/64923272

参考:https://gist.github.com/ikennaokpala/79f033880ecd38272a411350c6d573c0

https://www.cnblogs.com/qq917937712/p/5783984.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/111839.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • android布局文件详解

    android布局文件详解本文是我从DeclaringLayout翻译而来的文章,如果有不当之处请指出DeclaringLayout布局决定了Activity所展现的样子,他决定了布局的结构和控制着你展现给用户所有的元素,你可以通过两种方式来声明你的布局.①在xml文件中定义UI元素:android提供了与View类及其子类相关的简单易懂的标签。   ②在运行时期定义你的布局,即

    2022年6月2日
    53
  • React Native技术篇—自定义Toast弹窗「建议收藏」

    React Native技术篇—自定义Toast弹窗「建议收藏」注意:未经允许不可私自转载,违者必究ReactNative官方文档:https://reactnative.cn/docs/getting-started/项目GitHub地址:https://github.com/zhouwei1994/nativeCase.git在写自定义Toast弹窗之前我们要先创建一个ReactNative第二视图层。创建教程:https://b…

    2022年9月25日
    0
  • IDDR和ODDR使用

    IDDR和ODDR原语是针对7系列芯片使用,spand可以使用IDDR2和ODDR2IDDR三种模式OPPOSITE_EDGEMode传统的输入DDR解决方案或OPPOSITE_EDGE模式是通过ILOGIC模块中的单个输入实现的。数据在时钟的上升沿通过输出Q1提供给FPGA逻辑,在时钟的下降沿通过输出Q2提供给FPGA逻辑。该结构类似于Virtex-6FPGA实现。图1显示…

    2022年4月7日
    119
  • mac tensorboard

    mac tensorboard

    2021年5月27日
    106
  • 【全套完结】数字信号处理—-全套Matlab实验报告【建议保存】「建议收藏」

    目录实验一、熟悉MATLAB环境和基本信号的产生与运算实验一、熟悉MATLAB环境和基本信号的产生与运算实验一、熟悉MATLAB环境和基本信号的产生与运算

    2022年4月8日
    38
  • Windows编程(网络编程)

    Windows编程(网络编程)套接字类型与协议设置SOCK_STREAM[流套接字]TCP面向连接、可靠的数据传输适合传输大量的数据,不支持广播、多播SOCK_DGRAM[数据包套接字]

    2021年12月13日
    37

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号