我的 Linux 服务器上有一个 smb 挂载,但偶尔会失去连接,从而中断使用挂载目录的软件。有没有办法将 smb 挂载缓存到本地磁盘上?
答案1
听起来您想在使用时安装 SMB 共享。我建议autofs
为此使用。
如果当前不可用,请安装 autofs 和 cifs-utils。
sudo apt-get install autofs cifs-utils # Or
sudo yum install autofs cifs-utils
在启动时启用该服务。
sudo systemctl enable autofs
sudo systemctl start autofs
设置配置文件。
/etc/auto.master
/path/to/mountpoint /etc/auto.<my_server>
/etc/auto.<我的服务器>
<any_name> -fstype=cifs,rw,credentials=/path/to/creds.txt ://<remove_server>/<share_name>
/path/to/creds.txt 确保对文件执行 chmod 600
username=Username
password=Password
重新加载服务sudo systemctl restart autofs
一些了解更多信息的链接
- https://help.ubuntu.com/community/Autofs
- https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html/managing_file_systems/ assembly_mounting-file-systems-on-demand_managing-file-systems#doc-wrapper
您也可以执行此操作,fstab
但这里的主要区别是,当 smb 共享未使用时,autofs
挂载会超时并释放资源,而fstab
会保持挂载并使用资源。如果 autofs 很重要,您可以不设置超时,--timeout=0
但我建议不要设置它以节省资源。
如果您想避免 autofs,可以按照以下 fstab 方法进行操作。您仍然需要创建一个 creds 文件。
添加到/etc/fstab
//<server>/<share> /path/to/mount cifs credentials=/path/to/creds.txt 0 0