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

举报
lxw1844912514 发表于 2022/03/28 00:32:17 2022/03/28
【摘要】 问题说明,在vagrant虚拟机中启动cii 框架项目的时候没问题,但在启动laravel项目的时候花费17S,这明显不符合常理吗? 造成此问题的原因,是虚拟机共享文件系统 IO 速度慢所导致的。而一个全新安装的 Laravel 应用响应一个请求时,需要读取 600+ 的文件,瓶颈尤为明显。 补充:以下亲测可行方法 1.本地M...

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

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

补充:以下亲测可行方法

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


  
  1. sudo rm /etc/exports
  2. sudo touch /etc/exports
  3. sudo chmod -R 777 exports #有权限问题的话加这一步
  4. sudo vagrant halt
  5. sudo vagrant up --provision #在启动过程中,会询问是否允许更改exports文件,直接允许就好
vagrant plugin uninstall vagrant-winnfsd  #卸载插件

 

2修改后: Vagrantfile 文件


  
  1. # -*- mode: ruby -*-
  2. # vi: set ft=ruby :
  3. # All Vagrant configuration is done below. The "2" in Vagrant.configure
  4. # configures the configuration version (we support older styles for
  5. # backwards compatibility). Please don't change it unless you know what
  6. # you're doing.
  7. Vagrant.configure("2") do |config|
  8. # The most common configuration options are documented and commented below.
  9. # For a complete reference, please see the online documentation at
  10. # https://docs.vagrantup.com.
  11. # Every Vagrant development environment requires a box. You can search for
  12. # boxes at https://vagrantcloud.com/search.
  13. config.vm.box = "centos"
  14. config.vm.boot_timeout = 360
  15. config.ssh.username = "vagrant"
  16. config.ssh.password = "vagrant"
  17. # Disable automatic box update checking. If you disable this, then
  18. # boxes will only be checked for updates when the user runs
  19. # `vagrant box outdated`. This is not recommended.
  20. # config.vm.box_check_update = false
  21. # config.vm.network "forwarded_port", guest: 82, host: 8082, host_ip: "127.0.0.1"
  22. # config.vm.network "forwarded_port", guest: 83, host: 8083, host_ip: "127.0.0.1"
  23. # config.vm.network "forwarded_port", guest: 84, host: 8084, host_ip: "127.0.0.1"
  24. # config.vm.network "forwarded_port", guest: 85, host: 8085, host_ip: "127.0.0.1"
  25. # config.vm.network "forwarded_port", guest: 86, host: 8086, host_ip: "127.0.0.1"
  26. # config.vm.network "forwarded_port", guest: 87, host: 8087, host_ip: "127.0.0.1"
  27. # config.vm.network "forwarded_port", guest: 3306, host: 33306, host_ip: "127.0.0.1"
  28. # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "localhost"
  29. # config.vm.network "forwarded_port", guest: 81, host: 8081, host_ip: "localhost"
  30. config.vm.synced_folder "../../../Users/liutao/Desktop/vagrant", "/home/wwwroot/default",nfs: true, nfs_udp: true
  31. # Create a forwarded port mapping which allows access to a specific port
  32. # within the machine from a port on the host machine. In the example below,
  33. # accessing "localhost:8080" will access port 80 on the guest machine.
  34. # NOTE: This will enable public access to the opened port
  35. # config.vm.network "forwarded_port", guest: 80, host: 8080
  36. # Create a forwarded port mapping which allows access to a specific port
  37. # within the machine from a port on the host machine and only allow access
  38. # via 127.0.0.1 to disable public access
  39. # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
  40. # Create a private network, which allows host-only access to the machine
  41. # using a specific IP.
  42. #私有网络
  43. config.vm.network "private_network", ip: "192.168.33.11"
  44. #端口转发
  45. #config.vm.network "forwarded_port", guest: 8080, host: 8080, auto_correct: true
  46. # Create a public network, which generally matched to bridged network.
  47. # Bridged networks make the machine appear as another physical device on
  48. # your network.
  49. # config.vm.network "public_network",ip: "192.168.33.10"
  50. # Share an additional folder to the guest VM. The first argument is
  51. # the path on the host to the actual folder. The second argument is
  52. # the path on the guest to mount the folder. And the optional third
  53. # argument is a set of non-required options.
  54. # config.vm.synced_folder "../data", "/vagrant_data"
  55. # Provider-specific configuration so you can fine-tune various
  56. # backing providers for Vagrant. These expose provider-specific options.
  57. # Example for VirtualBox:
  58. #
  59. config.vm.provider "virtualbox" do |vb|
  60. # # Display the VirtualBox GUI when booting the machine
  61. # vb.gui = true
  62. #
  63. # # Customize the amount of memory on the VM:
  64. vb.memory = "512"
  65. end
  66. #
  67. # View the documentation for the provider you are using for more
  68. # information on available options.
  69. # Enable provisioning with a shell script. Additional provisioners such as
  70. # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
  71. # documentation for more information about their specific syntax and use.
  72. # config.vm.provision "shell", inline: <<-SHELL
  73. # apt-get update
  74. # apt-get install -y apache2
  75. # SHELL
  76. end

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


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

成功启动后:

如果报错


  
  1. sudo rm /etc/exports
  2. sudo touch /etc/exports
  3. 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
 

卸载插件:Vagrant up problem: sh: netsh: command not found - Stack Overflow

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: 无法创建树对象
 

解决方案:成功提交文件


  
  1. 在客户端,我的是mac端
  2. sudo chmod 777 -R .git/objects
  3. 即可

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

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

使用 Homestead 在开发 Laravel 应用程序,经常会遇到网页响应速度缓慢,有时甚至十几秒甚至几十秒才返回响应,极大影响了开发体验:

造成此问题的原因,是虚拟机共享文件系统 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:


  
  1. folders:
  2.     - map: ~/code
  3.       to: /home/vagrant/code
  4.       type: "nfs"

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

$ vagrant reload --provision
 

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


  
  1. setp 1 :centos安装nfs
  2. yum install nfs-utils rpcbind
  3. setp 2MAC OS已经集成nfs,只需要修改/etc/exports文件,如果没有则新建
  4. setp 3Vagrantfile文件修改
  5. config.vm.synced_folder "~/www", "/data", type: “nfs"
  6. 注:~/www为mac机器的目录。/data为虚拟机的目录。
  7. 保存后,使用命令 vagrant reload 重启虚拟机后才会生效,期间会修改MAC OX的 /etc/exports 文件。会提示输入mac账号的密码。输入即可!
  8. 然后,你会发现mac上的~/www 目录和虚拟机上的/data目录是互通的。开始配置你的网站吧

window可参考:  vagrant 基本命令、标准配置文件,支持nfs_ghostyusheng 's blog-CSDN博客

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

mac vagrant 虚拟机nfs挂载点 - 懒牛拉车 - 博客园

文章来源: blog.csdn.net,作者:lxw1844912514,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/lxw1844912514/article/details/105163646

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。