问题:
可以手动挂载,根据网上教程修改/etc/fstab后,重启自动挂载失败。
(奇葩的是,同一个机器,在机房的时候可以修改/etc/fstab自动挂载,但是换了场地后,自动挂载就失效了,难道是距离远了,网络传输变慢了?有没有大佬能告知其中原理,跪谢。)
解决办法:
1. 由于/etc/fstab的可调选项不多,网上说可以添加_netdev参数设置延迟挂载,可以尝试以下,反正我是失败了。
2. 改变思路,将自动挂载设置成开机自启服务。
(1)步骤1,添加service
sudo vi /etc/systemd/system/hl_nfs.service
内容如下
[Unit]
After=network.target
[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/usr/bin/mount -t nfs -o defaults 10.21.132.32:/NAS/CAPFS/data /etc/share_dir
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.target
这一步踩了很多坑,即使限制了和network.target的先后顺序,但还是会出现mount.nfs: Network is unreachable.
所以Restart参数非常重要!!!
(2)步骤2,赋予权限
sudo chmod 664 /etc/systemd/system/hl_nfs.service
(3)重新加载systemd服务文件,并启用service文件
sudo systemctl daemon-reload
sudo systemctl enable hl_nfs
sudo systemctl start hl_nfs.service
sudo systemctl status hl_nfs.service
sudo systemctl restart hl_nfs.service
重启后自动挂载成功!