家里有台无风扇小台式机,放卧室里很合适没有噪音,性能也还好,唯一美中不足的是只能挂个小固态硬盘,软件和资料一多,装不下!
家里同时也有台威联通的NAS机,容量极大,于是就想着能否将NAS的硬盘通过NFS挂到台式机上,从此磁盘容量不是问题了。
非常方便,挂载之前,先用如下脚本测试一下最佳的挂载参数
EXPORT="192.168.1.20:/Multimedia"
MNTDIR="/mnt/nas/test"
TESTFILE="VID20180124222402.mp4"
NFSPROTO="tcp"
if [[ -n "$1" ]]; then
NFSPROTO="udp"
fi
echo "Testing transfer speed of $NFSPROTO on file $EXPORT/$TESTFILE"
echo
for wsize in 8192 16384 32768 65536 131072
do
if mount | grep $MNTDIR > /dev/null; then
sudo umount $MNTDIR
fi
sudo mount -t nfs -o wsize=$wsize,$NFSPROTO,cto,noatime,intr,nfsvers=3 $EXPORT $MNTDIR
mntedwsize=$(cat /proc/mounts | grep $MNTDIR | grep -oE "wsize=[0-9]{4,6}" | grep -oE "[0-9]{4,6}")
echo $MNTDIR mounted @ wsize \($((mntedwsize/1024))K\), requested wsize \($((wsize/1024))K\)
sudo dd if=$MNTDIR/$TESTFILE of=/home/vincent/1.mkv |& grep "copied"
echo
done
sudo umount $MNTDIR
vincent@minipc:~$ ./testnfs
Testing transfer speed of tcp on file 192.168.1.20:/Multimedia/VID20180124222402.mp4
/mnt/nas/test mounted @ wsize (8K), requested wsize (8K)
441671141 bytes (442 MB, 421 MiB) copied, 8.23115 s, 53.7 MB/s
/mnt/nas/test mounted @ wsize (16K), requested wsize (16K)
441671141 bytes (442 MB, 421 MiB) copied, 5.74573 s, 76.9 MB/s
/mnt/nas/test mounted @ wsize (32K), requested wsize (32K)
441671141 bytes (442 MB, 421 MiB) copied, 5.85674 s, 75.4 MB/s
/mnt/nas/test mounted @ wsize (64K), requested wsize (64K)
441671141 bytes (442 MB, 421 MiB) copied, 6.68029 s, 66.1 MB/s
/mnt/nas/test mounted @ wsize (128K), requested wsize (128K)
441671141 bytes (442 MB, 421 MiB) copied, 6.51051 s, 67.8 MB/s
/etc/fstab中我再用最大的值128k就不合适了
192.168.1.20:/Multimedia /mnt/nas/Multimedia nfs _netdev,defaults,tcp,rsize=131072,wsize=131072,user,auto,noatime,intr 0 0
192.168.1.20:/Download /mnt/nas/Download nfs _netdev,defaults,tcp,rsize=131072,wsize=131072,user,auto,noatime,intr 0 0
192.168.1.20:/Container /mnt/nas/Recordings nfs _netdev,defaults,tcp,rsize=131072,wsize=131072,user,auto,noatime,intr 0 0
在NAS设置(有一万个选项但是不要急,用搜索框输入)中输入nfs关键字,然后是如下定义项
原来下图中allowed ip我是填写成192.168.1.*的,当时可能处于安全考虑,但是升级18.04后就访问不了;后来发现Public文件夹是天然可以访问的,参照其权限设置后可以访问了