Recently, I was doing some server setup works which involves NFS and Autofs. Of course, I ran into several problems. So I’d like to document it just in case.
Problem 1. Unable to mount exported shares via autofs
In NFS server’s /etc/exports, I put the following:
/mnt/static/images 10.1.1.1/29(ro)
And in a client’s /etc/auto.master and /etc/mnt.nfs, I put
# /etc/auto.master
/mnt /etc/mnt.nfs
# /etc/mnt.nfs
images -fstype=nfs4,soft,timeo=10,ro,intr,retry=0 10.1.1.1:/mnt/static/images
So theoretically, I should be able to visit /mnt/images on the client, but instead, I get the following error:
# ls /mnt/images
ls: cannot access /mnt/images: No such file or directory
What went wrong? I googled a lot and finally find an article in which it states that:
Note that with NFSv4, all exported directories must be part of a single hierarchy and that the root directory of that hierarchy must be exported and identified with the option fsid=0 or fsid=root.
With that information, I made my /etc/exports to look like that and exportfs -ra to apply the changes:
/mnt 10.1.1.1/29(ro)
/mnt/static/images 10.1.1.1/29(ro)
Then the autofs mount in client works. Although I’m not sure if it is the correct way to fix the issue, it can be used as a workaround.
Problem 2. autofs cause client to hang on startup when nfs server is down
By default, in /etc/autofs.conf, there is a timeoutset to 5 minutes. That mean how long does the client to wait before declaring the nfs server is down.
So I first tried to set a shorter timeout in /etc/auto.master for my specific mount like this, but it didn’t work. My client still waits more than 5 minutes on startup.
# /etc/auto.master
/mnt /etc/mnt.nfs --timeout=10
Then, I found there is also some other options in man nfs that might have something to do with the hang. So I changed my /etc/mnt.nfs to look like this:
# /etc/mnt.nfs
images -fstype=nfs4,soft,timeo=10,ro,intr,retry=0 10.1.1.1:/mnt/static/images
Now my client almost doesn’t hang on startup.
本文记录了在服务器设置过程中遇到的两个问题及其解决方案:一是通过调整NFS导出目录结构解决无法通过Autofs挂载共享的问题;二是通过修改Autofs配置减少启动时因NFS服务器未响应导致的挂起时间。

7186

被折叠的 条评论
为什么被折叠?



