[Linux] NFSv4 and Autofs caveats

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值