Nfs

nfs重新掛載問題

  • December 27, 2016

我在 RHEL7 中重新掛載 nfs 時發現了一個奇怪的問題。

我在 nfs-server 上共享了 2 個目錄:

# showmount -e
Export list for localhost.localdomain:  
/file2 192.168.122.1  
/file1 192.168.122.1  

然後我將它們安裝在我的客戶端上:

# sudo mount 192.168.122.100:/file2 /media  
# sudo mount 192.168.122.100:/file1 /mnt/file1
# mount 
192.168.122.100:/file1 on /mnt/file1 type nfs4 (rw,relatime,vers=4.0,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.122.1,local_lock=none,addr=192.168.122.100)
192.168.122.100:/file2 on /media type nfs4 (rw,relatime,vers=4.0,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.122.1,local_lock=none,addr=192.168.122.100)

然後我嘗試將其中一個重新安裝到 ro:

# sudo mount -o ro,remount /mnt/file1/

就在這時奇怪的事情發生了,兩人都變成了ro:

192.168.122.100:/file1 on /mnt/file1 type nfs4 (ro,relatime,vers=4.0,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.122.1,local_lock=none,addr=192.168.122.100)
192.168.122.100:/file2 on /media type nfs4 (ro,relatime,vers=4.0,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.122.1,local_lock=none,addr=192.168.122.100)

我已經擷取了一些數據包,但我發現重新安裝時沒有發送數據包。

我現在不知道,有沒有人可以幫助我?

謝謝。

我找到它了。

這是因為 NFS 預設使用 sharecache。見man nfs

  sharecache / nosharecache
                 Determines  how  the  client's  data  cache and attribute cache are shared when mounting the same export more than once concurrently.  Using the same
                 cache reduces memory requirements on the client and presents identical file contents to applications when the same remote file is accessed  via  dif‐
                 ferent mount points.

                 If  neither  option  is  specified,  or  if the sharecache option is specified, then a single cache is used for all mount points that access the same
                 export.  If the nosharecache option is specified, then that mount point gets a unique cache.  Note that when data and attribute  caches  are  shared,
                 the mount options from the first mount point take effect for subsequent concurrent mounts of the same export.

                 As  of  kernel 2.6.18, the behavior specified by nosharecache is legacy caching behavior. This is considered a data risk since multiple cached copies
                 of the same file on the same client can become out of sync following a local update of one of the copies.

手冊頁說a single cache is used for all mount points that access the same export

然後我使用nosharecache選項,現在它變得正常了。

192.168.122.100:/file1 on /mnt/file1 type nfs4 (ro,relatime,vers=4.0,rsize=131072,wsize=131072,namlen=255,hard,nosharecache,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.122.1,local_lock=none,addr=192.168.122.100)
192.168.122.100:/file2 on /mnt/file2 type nfs4 (rw,relatime,vers=4.0,rsize=131072,wsize=131072,namlen=255,hard,nosharecache,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.122.1,local_lock=none,addr=192.168.122.100

引用自:https://unix.stackexchange.com/questions/332335