Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

Unit 7:CIFS、NFS 與 autofs 三種網路檔案系統實作

一、CIFS 網路檔案系統

先安裝用戶端:

yum install samba-client -y

列出伺服器上的共享目錄,沒有密碼時直接回車:

smbclient -L //172.25.254.250
Enter root's password:

輸出會像這樣,Sharename 欄位就是可用的共享名稱:

Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]

Sharename Type Comment
--------- ---- -------
westos1 Disk test share
westos2 Disk test share
...
westos10 Disk test share
IPC$ IPC IPC Service (Samba Server Version 4.1.1)

以指令進入共享:

smbclient //172.25.254.250/westos9
smb: \> ls
.  D   0  Mon Aug  8 04:22:27 2016
.. D   0  Wed Dec  2 20:43:01 2015
100221120 blocks of size 1024. 28422828 blocks available

或直接用掛載方式:

mount //172.25.254.250/westos9 /mnt -o username=guest

開機自動掛載有兩種寫法,一是 /etc/fstab:

//172.25.254.253/westos /mnt cifs defaults,username=guest 0 0

二是 /etc/rc.d/rc.local,記得補執行權限:

mount //172.25.254.250/westos9 /mnt -o username=guest
chmod 755 /etc/rc.d/rc.local

二、NFS 網路檔案系統

yum install nfs-utils -y
showmount -e 172.25.254.250                      # 列出對方共享
mount 172.25.254.250:/nfsshare/ns1 /mnt         # 掛載使用

自動掛載同樣兩種寫法:

# /etc/fstab
172.25.254.250:/nfsshare/nfs1 /mnt nfs defaults 0 0

# /etc/rc.d/rc.local
mount 172.25.254.250:/nfsshare/nfs3 /mnt
chmod 755 /etc/rc.d/rc.local

三、autofs 自動掛載服務

用 mount 掛上的共享即使閒置也持續佔用資源,autofs 則是「有人存取才掛、閒置就卸」。

yum install autofs -y
systemctl start autofs
cd /net/172.25.254.250/nfsshare/nfs1

調整閒置卸載時間:

vim /etc/autofs.conf
15 timeout = 3    # 閒置 3 秒後自動卸載

自訂掛載點需要主設定檔與子設定檔搭配,前者寫上層目錄,後者寫實際掛載點與共享路徑:

# /etc/auto.master
/mnt /etc/auto.nfs

# /etc/auto.nfs
pub1 172.25.254.250:/nfsshare/nfs1
*    172.25.254.250:/nfsshare/&

改完重啟 autofs 生效。此後只要 cd /mnt/pub1,系統才會真的掛上,離開一段時間後自動卸除。

Copyright © Linux教程網 All Rights Reserved