简体   繁体   English

虚拟机 (VM) 中 NFS 上的文件修改监视(Webpack、Guard...)问题

[英]File modification watch (Webpack, Guard...) issue over NFS in Virtual Machine (VM)

I know there are multiple threads discussing NFS mounted volumes and file modification watch issues.我知道有多个线程在讨论NFS挂载卷和文件修改监视问题。 Since most of the discussions are old, some from 8 years ago, my goal here is to compile some and bring them up again to check what are the most recent solutions you guys have been using to handle those issues.由于大多数讨论都是旧的,有些是 8 年前的,我的目标是整理一些并再次提出来检查你们用来处理这些问题的最新解决方案是什么。

The core problem核心问题
Linux relies on inotify , a kernel subsystem, to generate events when files are modified (changed/deleted) and those events are most often used by developer tools to watch files to trigger some task. Linux 依赖于inotify ,一个 kernel 子系统,在文件被修改(更改/删除)时生成事件,开发人员工具最常使用这些事件来监视文件以触发某些任务。 The core issue is that when you have a volume/folder shared via NFS protocol, it doesn't generate the events, and therefore the tools need to use polling methods instead of trigger based on events.核心问题是当您通过 NFS 协议共享卷/文件夹时,它不会生成事件,因此工具需要使用轮询方法而不是基于事件触发。

Polling methods often create multiple issues such as high CPU usage, delay to trigger tasks over file alterations, and so on.轮询方法通常会产生多个问题,例如高 CPU 使用率、因文件更改而延迟触发任务等。

Some of the watching tools:一些观看工具:

Popular threads热门话题

Nice solution attempts不错的解决方案尝试

My current challenge我目前的挑战
We run our dev env using macOS as host, Vagrant (provider Virtualbox) with Alpine Linux as the guest, and Docker containers for the services (Node, NGINX...), the setup is running smoothly for everything aside from when the frontend developers need to watch file modifications using webpack watch feature.我们使用 macOS 作为主机运行我们的开发环境,Vagrant(提供者 Virtualbox)以 Alpine Linux 作为来宾,Docker 容器用于服务(节点,NGINX ...),除了前端开发人员之外的所有设置都运行顺利需要使用 webpack 监视功能监视文件修改。 It works with polling but with a delay of 3-10 seconds.它适用于轮询,但有 3-10 秒的延迟。

Any updates or any recommendations on how you solve this problem?关于如何解决此问题的任何更新或建议?

I've been able to work around this issue by setting the actimeo NFS option to 1. This reduces the length of time that NFS caches the file system attributes which seems to keep the host and guest in near sync.我已经能够通过将actimeo NFS 选项设置为 1 来解决这个问题。这减少了 NFS 缓存文件系统属性的时间长度,这似乎使主机和来宾保持接近同步。 Webpack watch now picks up changes for me almost immediately. Webpack watch now 几乎立即为我获取更改。

Here is the VagrantFile setting I use to implement this NFS share.这是我用来实现此 NFS 共享的 VagrantFile 设置。 Note the mount_options setting注意mount_options设置

config.vm.synced_folder "./my_host_syncd_folder", "/guest/path", type: 'nfs', mount_options: ['actimeo=1']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Docker Machine Virtual Box驱动程序问题 - Docker Machine Virtual Box Driver Issue 在虚拟docker-machine中运行NodeJS服务器-无法访问正在运行的VM应用 - Running NodeJS server in virtual docker-machine - Cannot access running VM app 从 Windows 主机上的虚拟机打开文件 - opening file from virtual machine on Windows host machine Grails 监视文件在 Vagrant 虚拟机内运行的 Docker 容器内不起作用 - Grails watch files doesn't work inside Docker container running inside a Vagrant virtual machine 如何将文件从 docker 虚拟机复制到 OS X 上的主机? - How to copy file from docker virtual machine to the host on OS X? 如何在本地虚拟机内复制文件或如何在本地虚拟机内编辑 yml 文件? (码头工人栈) - How to copy files inside a local virtual machine or how to edit a yml file inside a local virtual machine? (docker stack) 在Linux上通过NFS触发inotify事件? - trigger inotify event over NFS on Linux? Docker nfs 卷 - 没有这样的文件或目录 - Docker nfs volume - no such file or directory 如果docker使用虚拟机在mac上运行那么它比vagrant有什么优势呢? - If docker uses virtual machine to run on a mac then what is its advantage over vagrant? Docker 对比虚拟机 - Docker vs Virtual Machine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM