cifs掛載資料夾不斷斷開連接(ubuntu伺服器)

cifs掛載資料夾不斷斷開連接(ubuntu伺服器)

我有這個 fstab 條目允許 tomcat 應用程式在 Windows Samba 共用資料夾上讀取/寫入:

//dc/docs    /media/docs      cifs       credentials=...,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,sec=ntlm,uid=tomcat7,gid=tomcat7,dir_mode=0770,file_mode=0770 0 0

問題是它在一定時間後不斷卸載——不是 Windows 故障,我可以在其他地方存取共享

$ sudo ls /media/docs
finance  postsale  repository

#after e.g. 10 minutes...
$ sudo ls /media/docs
[sudo] password for user:
ls: cannot access '/media/docs': Connection reset by peer

#this takes ages to complete
$ sudo umount /media/docs

#this fails immediately after, succedes after about 5/10 seconds
$ sudo mount /media/docs
mount error(112): Host is down
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
$ sudo mount /media/docs
mount error(104): Connection reset by peer
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
$ sudo mount /media/docs
$ sudo ls /media/docs
finance  postsale  repository

我該如何調試或防止掉落?

Tomcat 應用程式使用者無權重新安裝,因此每次他們都需要向 IT 提出請求。

請注意,同一共用上的此安裝不會掉落(我發現的唯一區別是usersudoer,而tomcat7上面的不是):

//dc/share       /media/share     cifs       credentials=....credentials,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,sec=ntlm,uid=user,gid=user,dir_mode=0770,file_mode=0770 0 0

更新:

資料夾/var/log/samba為空-如何設定 samba 日誌記錄?

如果我繼續列出該資料夾,它不會刪除:

while true; do date; ls /media/docs; sleep 5; done

更新2:

這裡的mount輸出:

//fs-mxp/ZZZshare on /media/share type cifs (rw,relatime,vers=1.0,sec=ntlm,cache=strict,username=XXX,domain=YYY-it,uid=1000,forceuid,gid=1000,forcegid,addr=10.39.52.6,file_mode=0770,dir_mode=0770,nounix,serverino,mapposix,rsize=61440,wsize=65536,actimeo=1)
//fs-mxp/ftp on /media/ftp type cifs (rw,relatime,vers=1.0,sec=ntlm,cache=strict,username=XXX,domain=YYY-it,uid=1000,forceuid,gid=1000,forcegid,addr=10.39.52.6,file_mode=0770,dir_mode=0770,nounix,serverino,mapposix,rsize=61440,wsize=65536,actimeo=1)
//sql-mxp/C$ on /media/sql type cifs (rw,relatime,vers=1.0,sec=ntlm,cache=strict,username=administrator,domain=YYY-it,uid=1000,forceuid,gid=1000,forcegid,addr=10.39.52.11,file_mode=0770,dir_mode=0770,nounix,serverino,mapposix,rsize=61440,wsize=65536,actimeo=1)
//fs-mxp/ZZZdocs on /media/docs type cifs (rw,relatime,vers=1.0,sec=ntlm,cache=strict,username=YYYdoc,domain=YYY-it,uid=113,forceuid,gid=123,forcegid,addr=10.39.52.6,file_mode=0770,dir_mode=0770,nounix,serverino,mapposix,rsize=61440,wsize=65536,actimeo=1)
//fs-mxp/ZZZshare/ASTE on /home/esales/aste type cifs (rw,relatime,vers=1.0,sec=ntlm,cache=strict,username=XXX,domain=YYY-it,uid=1001,forceuid,gid=1002,forcegid,addr=10.39.52.6,file_mode=0770,dir_mode=0770,nounix,serverino,mapposix,rsize=61440,wsize=65536,actimeo=1)
//fs-mxp/ftp/YYYvendor on /home/esales/YYYvendor type cifs (rw,relatime,vers=1.0,sec=ntlm,cache=strict,username=XXX,domain=YYY-it,uid=1001,forceuid,gid=1002,forcegid,addr=10.39.52.6,file_mode=0770,dir_mode=0770,nounix,serverino,mapposix,rsize=61440,wsize=65536,actimeo=1)

答案1

我猜想這與 Windows 更新提供的修補程式有關,以防止勒索軟體攻擊。它使保存共用資料夾的伺服器拒絕 CIFS V1 請求。預設情況下掛載使用 CIFS V1。透過添加vers=2.0到安裝命令的末尾來嘗試。我遇到了同樣的問題,透過這種方式我設法解決了它。 PS/僅供參考:我的指令如下所示

//192.168.1.10/public/mount /media/windowsshare cifs credentials=/home/MY_USERNAME/.smbcredentials,iocharset=utf8,sec=ntlm,vers=2.0 0 0

答案2

從您新增到問題中的安裝輸出中,我們可以看到您仍在使用 CIFS 1.0。

如果伺服器支援的話,我建議將掛載安裝為 CIFS 2.1,因為從 CIFS v2.0 或 2.1 開始,該協定支援更好地從連接睡眠/切斷中恢復。為此,選項是vers=2.1.

耐用句柄 (2.02、2.1) – 如果暫時斷開連接,允許連接透明地重新連接到伺服器

我還建議添加該選項echo_interval=60而不是添加 while 循環,因為這樣,SMB 用戶端程式碼每分鐘都會向伺服器發送 keepalive 信標。

請注意,正如我在 @Thillina 答案中警告並更正的那樣,選項全部位於第三個字段上,並用逗號分隔。

如欲了解更多詳情,請參閱CIFS 隨機遺失與 Windows 共享的連接

閱讀我在帖子中引用的文章:

3.0 - Microsoft Windows 8 和 Windows Server 2012 中引入的 SMBv3.0 協定。

因此,您擁有 Windows Server 2012 意味著 Windows 端至少支援 CIFSv3.0 及更低版本。

若要檢查是否重新協商以及使用哪個版本,請變更檔案中的選項fstab,然後執行下列操作:

#mount -o remount /media/docs

然後執行mount命令來檢查安裝完成/協商的版本。

答案3

我最終完成了一個 cron 作業,每 3 分鐘觸及每個cifs共享上的一個檔案mount以保持連線處於活動狀態。

到目前為止,股票已恢復正常供應:

cifs_keepalive:

#!/bin/bash

while read spot; do
   touch --no-create "${spot}/.cifs_keepalive"
done <<< "$(mount | awk '/cifs/{ print $3; }')"

/etc/cron.d/cifs_keepalive:

*/3 *   *   *   *   root    /home/bcait/bca_util/bin/cifs_keepalive >/dev/null 2>&1

學分:我的想法來自這篇博文

答案4

就我而言,我有其他網路介面已斷開連接。這些介面上的 DHCP 租約到期導致掛載遺失http://ubuntuforums.org/showthread.php?t=1140094桑巴重新加載。

對我來說,我禁用了這些介面。另一個可能的解決方案是超時時間為 0 的 autofs。

相關內容