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)
上一篇 2022年2月14日 上午10:00
下一篇 2022年2月14日 上午11:00


相关推荐

  • DejaGnu

    DejaGnu

    2021年8月21日
    58
  • 1024程序员节是什么意思(懂硬件的程序员多吗)

    你真的懂啥是1024吗?今天就是一年一度的1024节了!packagecom.ocnyang.app;/***程序员们,1024快乐。*/publicclassHello1024{publicstaticfinalStringPROGRAM_APES=”程序猿”;publicstaticfinalStringPROGRAM_GIRL

    2022年4月10日
    43
  • SECS/GEM开发介绍

    SECS/GEM开发介绍SECS GEM 是由国际半导体设备和材料 SEMI 协会成员制定的连接标准 本标准适用于设备和工厂管理系统之间的通信标准 介绍 SECS GEM 是指一套半导体行业标准 用于管理制造设备和工厂主机系统之间的通信 消息层标准 SEMIE5SECS II 定义了一个通用的消息结构和一个包含许多标准化消息的库 协议层标准 SEMIE37 高速消息服务 HSMS 定义了使用 TCP IP 传输 SECS II 消息的二进制结构 SEMIE30GEM 为一些 SECS II 消息定义了一组最低要求

    2026年3月19日
    2
  • 大数据Hbase 面试题「建议收藏」

    大数据Hbase 面试题「建议收藏」1.2hbase的特点是什么  (1)Hbase一个分布式的基于列式存储的数据库,基于Hadoop的hdfs存储,zookeeper进行管理。(2)Hbase适合存储半结构化或非结构化数据,对于数据结构字段不够确定或者杂乱无章很难按一个概念去抽取的数据。(3)Hbase为null的记录不会被存储.(4)基于的表包含rowkey,时间戳,和列族。新写入数

    2022年5月31日
    89
  • Spring Boot2.0迁移概括

    Spring Boot2.0迁移概括首先,SpringBoot2.0需要Java8或更高版本。不再支持Java6和7了。在SpringBoot2.0中,许多配置属性被重新命名/删除,开发人员需要更新application.properties/application.yml相应的配置。为了帮助你解决这一问题,SpringBoot发布了一个新spring-boot-properties-migr…

    2022年5月27日
    70
  • jenkinsfile docker_docker构建自己的镜像

    jenkinsfile docker_docker构建自己的镜像前言之前我们用docker手动安装了jenkins环境,在jenkins中又安装了python3环境和各种安装包,如果我们想要在其他3台机器上安装,又是重复操作,重复劳动,那会显得很low,这里可以

    2022年7月29日
    6

发表回复

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

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