Linux NFS 缓存清理命令?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8311710/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
NFS cache-cleaning command?
提问by Tomoya Kabe
I have a trouble with NFS client-side attribute caching. I'm using some servers, one is an NFS server and the others are NFS client servers.
我在 NFS 客户端属性缓存方面遇到了麻烦。我正在使用一些服务器,一个是 NFS 服务器,其他是 NFS 客户端服务器。
All servers are Debian(lenny, 2.6.26-2-amd64 of Linux) and versions are following.
所有服务器都是 Debian(lenny,Linux 的 2.6.26-2-amd64),版本如下。
% dpkg -l | grep nfs
ii libnfsidmap2 0.20-1 An nfs idmapping library
ii nfs-common 1:1.1.2-6lenny1 NFS support files common to client and server
ii nfs-kernel-server 1:1.1.2-6lenny1 support for NFS kernel server
In the NFS server, /etc/exports is written as following:
在 NFS 服务器中,/etc/exports 是这样写的:
/export-path 192.168.0.0/255.255.255.0(async,rw,no_subtree_check)
In the NFS clients, /etc/fstab is written as following:
在 NFS 客户端中,/etc/fstab 的写法如下:
server:/export-path /mountpoint nfs rw,hard,intr,rsize=8192,async 0 0
As you can see, "async" option is used for multi-clients access performance. However, sometimes this can cause false-caching errors.
如您所见,“async”选项用于多客户端访问性能。但是,有时这会导致错误缓存错误。
Since I am maintaining many servers (and I have not so strong permission to change the mount options), I don't want to modify /etc/exports nor /etc/fstab. I think it is sufficient if I have a command-line tool that "cleans" NFS client-side attribute cache with a user permission.
由于我维护了许多服务器(并且我没有更改挂载选项的强权限),因此我不想修改 /etc/exports 或 /etc/fstab。我认为如果我有一个命令行工具可以“清理”具有用户权限的 NFS 客户端属性缓存就足够了。
Please let me know if there such commands.
请让我知道是否有这样的命令。
Thanks,
谢谢,
(附加)
I mean by "false-caching errors",
我的意思是“错误缓存错误”,
% ls -l /data/1/kabe/foo
ls: cannot access /data/1/kabe/foo: No such file or directory
% ssh another-server 'touch /data/1/kabe/foo'
% ls -l /data/1/kabe/foo
ls: cannot access /data/1/kabe/foo: No such file or directory
Sometimes such cases happen. The problem is not a file content but file attributes(=dentries information) since NFS says it guarantees Close-to-Open consistency.
有时会发生这样的情况。问题不在于文件内容,而在于文件属性(= dentries 信息),因为 NFS 表示它保证关闭到打开的一致性。
采纳答案by JimB
Depending on what you mean by "false-caching errors", running sync
may get you what you need. This will flush all filesystem buffers.
根据您所说的“错误缓存错误”的含义,运行sync
可能会满足您的需求。这将刷新所有文件系统缓冲区。
If needed, you can also clear out the VM caches in the kernel using /proc/sys/vm/drop_caches
.
如果需要,您还可以使用/proc/sys/vm/drop_caches
.
# To free pagecache
echo 1 > /proc/sys/vm/drop_caches
# To free dentries and inodes
echo 2 > /proc/sys/vm/drop_caches
# To free pagecache, dentries and inodes
echo 3 > /proc/sys/vm/drop_caches
回答by Bin
clear /var/lib/nfs/rmtab file on nfs server.
清除 nfs 服务器上的 /var/lib/nfs/rmtab 文件。
The below commands are used to clear memory related problems. and it is very dangerous too. soem times it will crash ur application hosted on the box
以下命令用于清除内存相关问题。而且也很危险。有时它会使托管在盒子上的应用程序崩溃
# sync
# To free pagecache
echo 1 > /proc/sys/vm/drop_caches
# To free dentries and inodes
echo 2 > /proc/sys/vm/drop_caches
# To free pagecache, dentries and inodes
echo 3 > /proc/sys/vm/drop_caches
回答by ArtemGr
AFAIK, the sync
and async
options aren't the source of attribute caching. Async
allows the server to delay saving data to server filesystem, e.g. it affects the write durability in case of NFS server failures, but if the NFS server is stable then async
does not affect the NFS clients.
AFAIK,sync
和async
选项不是属性缓存的来源。Async
允许服务器延迟将数据保存到服务器文件系统,例如,它会在 NFS 服务器故障的情况下影响写入持久性,但如果 NFS 服务器稳定,则async
不会影响 NFS 客户端。
There is a lookupcache=positive
NFS mount option that might be used to prevent negative lookup caching, e.g. the NFS returning "No such file or directory" when the file actually exists on the server. See Directory entry caching
in man nfs
.
有一个lookupcache=positive
NFS 挂载选项可用于防止负查找缓存,例如,当文件实际存在于服务器上时,NFS 返回“没有这样的文件或目录”。见Directory entry caching
在man nfs
。
回答by Erik Aronesty
Within a given process, calling opendir and closedir on the parent directory of a file invalidates the NFS cache. I used this while programming a job scheduler. Very, very helpful. Try it!
在给定的进程中,对文件的父目录调用 opendir 和 closedir 会使 NFS 缓存无效。我在编写作业调度程序时使用了它。非常非常有帮助。尝试一下!
回答by Jeff Taylor
You're seeing the effects of NFS's attribute cache. See man nfs
, and check out DATA AND METADATA COHERENCE
.
您正在看到 NFS 属性缓存的效果。看看man nfs
,看看DATA AND METADATA COHERENCE
。
NFS by default caches attributes for a minimum of 30 seconds (acregmin
and acdirmin
) and a maximum of 60 seconds (acregmax
and acdirmax
). You can override all of these together with actimeo
, or disable the attribute cache entirely with noac
. With the noac
mount option, the behaviour described by the OP goes away, but hits performance.
默认情况下,NFS 将属性缓存最少 30 秒(acregmin
和acdirmin
),最多 60 秒(acregmax
和acdirmax
)。您可以使用 覆盖所有这些actimeo
,或者使用 完全禁用属性缓存noac
。使用noac
mount 选项,OP 描述的行为会消失,但会影响性能。
lookupcache=positive
is useful if you're just looking for the appearance of new files, but deletions will still go through the attribute cache.
lookupcache=positive
如果您只是在寻找新文件的外观,则很有用,但删除操作仍将通过属性缓存。