第七單元

訪問網絡文件共享服務
一 掛載網絡文件系統
網絡文件系統是由網絡附加存儲服務器通過網絡向多個主機提供的一種文件系統 , 而不是由塊設備 ( 例如硬盤驅動器 ) 提供的。客戶端通過特殊的文件系統協議和格式訪問遠程存儲
Linux 中有兩種主要協議可用訪問網絡文件系統 : NFS 和CIFS
1 )CIFS: 通用網絡文件系統
CIFS 是針對 Microsoft Windows 操作系統的本地網絡文件系統Linux 系統可以掛載和訪問 CIFS 文件共享 , 如同常見的網絡文件系統一樣。
samba-client RPM 軟件包所包含的 smbclient 實用程序可用來識別由 Windows 或Samba 文件服務器提供的 CIFS 共享
客戶端:
1 通過samba-client方式共享
yum install samba-client -y ###安裝samba-client###
smbclient -L //172.25.254.250 ###登入遠程服務器172.25.254.250###
smbclient //172.25.254.250/westos1 ###進入westos1###
put anaconda-ks.cfg ###往westos1上傳文件###
rm anaconda-ks.cfg ###在westo1上刪除文件###
過程如下:
[root@localhost ~]# smbclient -L //172.25.254.250 ###登入172.25.254.250
Enter root's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]
Sharename Type Comment
--------- ---- -------
westos1 Disk test share
westos2 Disk test share
westos3 Disk test share
westos4 Disk test share
westos5 Disk test share
westos6 Disk test share
westos7 Disk test share
westos8 Disk test share
westos9 Disk test share
westos10 Disk test share
IPC$ IPC IPC Service (Samba Server Version 4.1.1)
Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]
Server Comment
--------- -------
Workgroup Master
--------- -------
[root@localhost ~]# smbclient //172.25.254.250/westos1 ###進入westos1###
Enter root's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]
smb: \> ls ###查看遠程服務器的文件###
. D 0 Sun Apr 30 01:36:27 2017
.. D 0 Wed Dec 2 20:43:01 2015
file A 52 Sun Apr 30 01:35:24 2017
userfile A 19 Sun Apr 30 01:35:25 2017
anaconda-ks.cfg A 8619 Sun Apr 30 01:36:01 2017
file2 N 0 Sun Apr 30 01:36:32 2017
file3 N 0 Sun Apr 30 01:36:32 2017
file4 N 0 Sun Apr 30 01:36:32 2017
file5 N 0 Sun Apr 30 01:36:32 2017
file6 N 0 Sun Apr 30 01:36:32 2017
file7 N 0 Sun Apr 30 01:36:32 2017
file8 N 0 Sun Apr 30 01:36:32 2017
file9 N 0 Sun Apr 30 01:36:32 2017
file10 N 0 Sun Apr 30 01:36:32 2017
fileeeeee N 0 Sun Apr 30 01:36:17 2017
100221120 blocks of size 1024. 21816820 blocks available
smb: \> !ls ###查看本地文件###
anaconda-ks.cfg etc file.rej Public
boot file kernel-3.10.0-123.el7.x86_64.rpm Templates
Desktop file1 lib Videos
Documents file3 Music
Downloads file.path Pictures
smb: \> put anaconda-ks.cfg
putting file anaconda-ks.cfg as \anaconda-ks.cfg (27.5 kb/s) (average 27.5 kb/s)
smb: \> rm anaconda-ks.cfg
NT_STATUS_NO_SUCH_FILE listing \anaconda-ks.cfg
smb: \> quit
2 通過掛載的方式共享
mount //172.25.254.250/westos1 /mnt/ -o username=guest ###以匿名用戶身份將westos1掛載到本地的/mnt下###
touch /mnt/file3
過程如下:
[root@localhost ~]# mount //172.25.254.250/westos1
mount: can't find //172.25.254.250/westos1 in /etc/fstab
[root@localhost ~]# mount //172.25.254.250/westos1 -o username=guest
mount: can't find //172.25.254.250/westos1 in /etc/fstab
[root@localhost ~]# mount //172.25.254.250/westos1 /mnt/ -o username=guest
[root@localhost ~]# touch /mnt/file3
[root@localhost ~]# touch /mnt/filehello
3 開機自動掛載
vim /etc/fstab
mount -a ###立即生效####
/etc/fstab下寫的內容:
//172.25.254.250/westos1 /mnt cifs defaults,username=guest 0 0
過程如下:
[root@localhost ~]# umount /mnt/
[root@localhost ~]# vim /etc/fstab
[root@localhost ~]# mount -a ###立即生效####
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 4064104 6409796 39% /
devtmpfs 922268 0 922268 0% /dev
tmpfs 942660 84 942576 1% /dev/shm
tmpfs 942660 17040 925620 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
/dev/sr0 3654720 3654720 0 100% /run/media/root/RHEL-7.0 Server.x86_64
//172.25.254.250/westos1 100221120 78407756 21813364 79% /mnt
2)nfs:網絡文件系統
NFS ( Network File System ) 是由 Linux 、 UNIX 及其他類似操作系統使用的互聯網標準協議 , 可作為它們的本地網絡文件系統。
它是一種活動擴展之下的開放標準 , 可支持本地 Linux 權限和文件系統功能
有兩種方法用來確定由服務器提供的 NFS 導出 , 或叫做文件共享。如果服務器支持 NFSv3 或 NFSv2 , 您可以使用 showmount -e server 命令來獲取導出項列表。如果服務器支持 NFSv4 , 則可以將 / 導出項掛載到一個空目錄并瀏覽所有導出文件系統的內容
1 訪問 NFS 導出的命令
yum install nfs-utils -y ###安裝nfs####
showmount -e ###登入###
mount ###掛載###
過程如下:
[root@localhost ~]# showmount -e 172.25.254.250 ###-e指連接到指定遠程主機###
Export list for 172.25.254.250:
/nfsshare/nfs5 *
/nfsshare/nfs4 *
/nfsshare/nfs3 *
/nfsshare/nfs2 *
/nfsshare/nfs1 *
/content 172.25.0.0/255.255.0.0
[root@localhost ~]# mount 172.25.254.250:/nfsshare/nfs1 /mnt/ ###掛載,不用寫客戶端#####
[root@localhost ~]# cd /mnt/
[root@localhost mnt]# touch haha{1..10}
[root@localhost mnt]# ls
file1 haha10 haha3 haha5 haha7 haha9
haha1 haha2 haha4 haha6 haha8
[root@localhost mnt]# rm -fr *
2 開機自動掛載
vim /etc/fstab
mount -a
/etc/fstab 下寫的內容:
172.25.254.250:/nfsshare/nfs1 /mnt defaults 0 0
[root@localhost mnt]# cd
[root@localhost ~]# umount /mnt/
[root@localhost ~]# vim /etc/fstab
[root@localhost ~]# mount -a
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 4065080 6408820 39% /
devtmpfs 922268 0 922268 0% /dev
tmpfs 942660 84 942576 1% /dev/shm
tmpfs 942660 17044 925616 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
/dev/sr0 3654720 3654720 0 100% /run/media/root/RHEL-7.0 Server.x86_64
172.25.254.250:/nfsshare/nfs1 100221952 78411776 21810176 79% /mnt
[root@localhost ~]# touch file
[root@localhost ~]# touch file1
[root@localhost ~]# rm -fr file file1
二 自動掛載網絡存儲
使用 mount 命令 , 需要具有 root 用戶權限以連接到網絡共享。或者 , 我們可以向/etc/fstab 添加條目 , 但是隨后與網絡服務器的連接將始終處于活動狀態。當某一程序試圖訪問網絡共享中的文件時 , 可以將 automounter ( 或 autofs )服務配置為 “ 按需 ” 掛載網絡共享。當共享不再使用并處于不活動狀態一定時間以后 ,automounter 會對共享解除掛載
不活動狀態的時間間隔默認為五分鐘 , 但該時間間隔可在/etc/sysconfig/autofs 中進行全局更改
1 使用/net映射
/net,自掛載掛載點 , 然后手動配置間接自動掛載映射
默認情況下 , autofs 服務運行時 , 存在一個名為 /net 的特殊目錄 , 但是該目錄將顯示為空,訪問不存在的目錄 /net/instructor.example.com 會使自動掛載器創建該子目錄 , 并顯示該 NFS 服務器上的所有NFS 導出項。這有時稱為 “ 瀏覽 ” 共享
/net/instructor.example.com 之下的所有文件和目錄停止使用且超時期滿后 ,autofs 將共享解除掛載并刪除空的 /net/instructor.example.com 子目錄
yum install autofs.x86_64 -y ###安裝autofs.x86_64###
systemctl start autofs ###開啟服務###
cd /net ###進入該目錄下###
ls ###查看發現為空###
cd 172.25.254.250 ###訪問不存在的目錄172.25.254.250
ls ##查看發現有內容###
cd nfsshare/nfs1
過程如下:
[root@localhost ~]# systemctl start autofs ###開啟服務###
[root@localhost ~]# cd /net/
[root@localhost net]# cd 172.25.254.250
[root@localhost 172.25.254.250]# ls
content nfsshare
[root@localhost 172.25.254.250]# cd nfsshare/nfs1
[root@localhost nfs1]# ls
[root@localhost nfs1]# touch file1
[root@localhost nfs1]# ls
file1 file2
[root@localhost nfs1]# df ###查看是否掛載###
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 4070616 6403284 39% /
devtmpfs 922268 0 922268 0% /dev
tmpfs 942660 84 942576 1% /dev/shm
tmpfs 942660 17052 925608 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
/dev/sr0 3654720 3654720 0 100% /run/media/root/RHEL-7.0 Server.x86_64
172.25.254.250:/nfsshare/nfs1 100221952 78411776 21810176 79% /net/172.25.254.250/nfsshare/nfs1
[root@localhost nfs1]# cd
[root@localhost ~]# vim /etc/sysconfig/autofs ###編輯掛載時間###
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 4070636 6403264 39% /
devtmpfs 922268 0 922268 0% /dev
tmpfs 942660 84 942576 1% /dev/shm
tmpfs 942660 17052 925608 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
/dev/sr0 3654720 3654720 0 100% /run/media/root/RHEL-7.0 Server.x86_64
172.25.254.250:/nfsshare/nfs1 100221952 78415872 21806080 79% /net/172.25.254.250/nfsshare/nfs1
2 間接映射
除了使用 /net 映射 , 系統管理員也可以手動配置任意目錄, 以便訪問時在其子目錄上 “ 按需 ” 掛載特定共享
vim /etc/auto.master
/etc/auto.master下寫的內容:
最終掛載點的上一級目錄 有最終掛載點的一個目錄(例 :/etc/auto.westos)
vim /etc/auto.westos(你在/etc/auto.master下編輯的最終掛載點目錄)
編輯內容:
nfs1 172.25.254.250:/nfsshare/nfs1 ###將遠程服務器的共享目錄掛載到nfs1,這樣只能掛載nfs2###
* 172.25.254.250:/nfsshare/& ###可以掛載任意目錄###
systemctl restart autofs.service ###重啟服務###
過程如下:
[root@localhost ~]# mkdir /westos
[root@localhost ~]# vim /etc/auto.master
[root@localhost ~]# vim /etc/auto.westos
#####此時/etc/auto.westos下的內容為:nfs1 172.25.254.250:/nfsshare/nfs1####
[root@localhost ~]# systemctl restart autofs.service
[root@localhost ~]# cd /westos/
[root@localhost westos]# ls ###/westos下沒有nfs1目錄####
[root@localhost westos]# cd nfs1
[root@localhost nfs1]# pwd
/westos/nfs1
[root@localhost nfs1]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 4070672 6403228 39% /
devtmpfs 922268 0 922268 0% /dev
tmpfs 942660 84 942576 1% /dev/shm
tmpfs 942660 17052 925608 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
/dev/sr0 3654720 3654720 0 100% /run/media/root/RHEL-7.0 Server.x86_64
172.25.254.250:/nfsshare/nfs1 100221952 78409728 21812224 79% /westos/nfs1
[root@localhost nfs1]# cd nfs2
-bash: cd: nfs2: No such file or directory
nfs1 172.25.254.250://nfsshare/nfs1
[root@localhost nfs1]# vim /etc/auto.westos
#####此時/etc/auto.westos下的內容為:* 172.25.254.250:/nfsshare/&#####
[root@localhost nfs1]# systemctl restart autofs.service
[root@localhost nfs1]# cd
[root@localhost ~]# cd /westos/nfs2
[root@localhost nfs2]# pwd
/westos/nfs2
[root@localhost nfs3]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 4070672 6403228 39% /
devtmpfs 922268 0 922268 0% /dev
tmpfs 942660 84 942576 1% /dev/shm
tmpfs 942660 17052 925608 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
/dev/sr0 3654720 3654720 0 100% /run/media/root/RHEL-7.0 Server.x86_64
172.25.254.250:/nfsshare/nfs2 100221952 78409728 21812224 79% /westos/nfs2
另外有需要云服務器可以了解下創新互聯cdcxhl.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業上云的綜合解決方案,具有“安全穩定、簡單易用、服務可用性高、性價比高”等特點與優勢,專為企業上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
網站題目:訪問網絡文件共享服務-創新互聯
當前鏈接:http://www.yijiale78.com/article30/cegsso.html
成都網站建設公司_創新互聯,為您提供外貿網站建設、網站內鏈、營銷型網站建設、虛擬主機、網站導航、定制開發
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯