溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

訪問網(wǎng)絡(luò)文件共享服務(wù)

發(fā)布時(shí)間:2020-06-02 17:31:58 來源:網(wǎng)絡(luò) 閱讀:892 作者:blueclo 欄目:建站服務(wù)器

第七單元

訪問網(wǎng)絡(luò)文件共享服務(wù)

 

 

掛載網(wǎng)絡(luò)文件系統(tǒng)

網(wǎng)絡(luò)文件系統(tǒng)是由網(wǎng)絡(luò)附加存儲服務(wù)器通過網(wǎng)絡(luò)向多個(gè)主機(jī)提供的一種文件系統(tǒng) , 而不是由塊設(shè)備 ( 例如硬盤驅(qū)動器 ) 提供的。客戶端通過特殊的文件系統(tǒng)協(xié)議和格式訪問遠(yuǎn)程存儲

Linux 中有兩種主要協(xié)議可用訪問網(wǎng)絡(luò)文件系統(tǒng) : NFS 和CIFS

 

1 )CIFS: 通用網(wǎng)絡(luò)文件系統(tǒng)

CIFS 是針對 Microsoft Windows 操作系統(tǒng)的本地網(wǎng)絡(luò)文件系統(tǒng)Linux 系統(tǒng)可以掛載和訪問 CIFS 文件共享 , 如同常見的網(wǎng)絡(luò)文件系統(tǒng)一樣。

samba-client RPM 軟件包所包含的 smbclient 實(shí)用程序可用來識別由 Windows 或Samba 文件服務(wù)器提供的 CIFS 共享

 

客戶端:

1 通過samba-client方式共享

yum    install    samba-client    -y         ###安裝samba-client###

smbclient    -L     //172.25.254.250         ###登入遠(yuǎn)程服務(wù)器172.25.254.250###

smbclient        //172.25.254.250/westos1   ###進(jìn)入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   ###進(jìn)入westos1###

Enter root's password:                                

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

smb: \> ls                                  ###查看遠(yuǎn)程服務(wù)器的文件###

  .                                   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 開機(jī)自動掛載

 

vim      /etc/fstab

mount        -a          ###立即生效####

 

/etc/fstab下寫的內(nèi)容:

//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:網(wǎng)絡(luò)文件系統(tǒng)

NFS ( Network File System ) 是由 Linux 、 UNIX 及其他類似操作系統(tǒng)使用的互聯(lián)網(wǎng)標(biāo)準(zhǔn)協(xié)議 , 可作為它們的本地網(wǎng)絡(luò)文件系統(tǒng)。

它是一種活動擴(kuò)展之下的開放標(biāo)準(zhǔn) , 可支持本地 Linux 權(quán)限和文件系統(tǒng)功能

 

有兩種方法用來確定由服務(wù)器提供的 NFS 導(dǎo)出 , 或叫做文件共享。如果服務(wù)器支持 NFSv3 或 NFSv2 , 您可以使用 showmount -e  server 命令來獲取導(dǎo)出項(xiàng)列表。如果服務(wù)器支持 NFSv4 , 則可以將 / 導(dǎo)出項(xiàng)掛載到一個(gè)空目錄并瀏覽所有導(dǎo)出文件系統(tǒng)的內(nèi)容

 

1   訪問 NFS 導(dǎo)出的命令

 yum   install     nfs-utils     -y       ###安裝nfs####

 showmount    -e         ###登入###

mount                     ###掛載###

 

過程如下:

[root@localhost ~]# showmount -e 172.25.254.250   ###-e指連接到指定遠(yuǎn)程主機(jī)###

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 開機(jī)自動掛載

vim      /etc/fstab

mount     -a

 

/etc/fstab 下寫的內(nèi)容:

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

 

 

 

 

 自動掛載網(wǎng)絡(luò)存儲

使用 mount 命令 , 需要具有 root 用戶權(quán)限以連接到網(wǎng)絡(luò)共享?;蛘?, 我們可以向/etc/fstab 添加條目 , 但是隨后與網(wǎng)絡(luò)服務(wù)器的連接將始終處于活動狀態(tài)。當(dāng)某一程序試圖訪問網(wǎng)絡(luò)共享中的文件時(shí) , 可以將 automounter ( 或 autofs )服務(wù)配置為 “ 按需 ” 掛載網(wǎng)絡(luò)共享。當(dāng)共享不再使用并處于不活動狀態(tài)一定時(shí)間以后 ,automounter 會對共享解除掛載

不活動狀態(tài)的時(shí)間間隔默認(rèn)為五分鐘 , 但該時(shí)間間隔可在/etc/sysconfig/autofs 中進(jìn)行全局更改

 

 

1  使用/net映射  

/net,自掛載掛載點(diǎn) , 然后手動配置間接自動掛載映射

默認(rèn)情況下 , autofs 服務(wù)運(yùn)行時(shí) , 存在一個(gè)名為 /net 的特殊目錄 , 但是該目錄將顯示為空,訪問不存在的目錄 /net/instructor.example.com 會使自動掛載器創(chuàng)建該子目錄 , 并顯示該 NFS 服務(wù)器上的所有NFS 導(dǎo)出項(xiàng)。這有時(shí)稱為 “ 瀏覽 ” 共享

/net/instructor.example.com 之下的所有文件和目錄停止使用且超時(shí)期滿后 ,autofs 將共享解除掛載并刪除空的 /net/instructor.example.com 子目錄

 

yum   install   autofs.x86_64   -y      ###安裝autofs.x86_64###

systemctl    start      autofs          ###開啟服務(wù)###

cd     /net                            ###進(jìn)入該目錄下###

ls                                     ###查看發(fā)現(xiàn)為空###

cd          172.25.254.250             ###訪問不存在的目錄172.25.254.250

ls                                     ##查看發(fā)現(xiàn)有內(nèi)容###

cd           nfsshare/nfs1             

 

 

過程如下:

[root@localhost ~]# systemctl start autofs          ###開啟服務(wù)###

[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     ###編輯掛載時(shí)間###

[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 映射 , 系統(tǒng)管理員也可以手動配置任意目錄, 以便訪問時(shí)在其子目錄上 “ 按需 ” 掛載特定共享

vim        /etc/auto.master

/etc/auto.master下寫的內(nèi)容:

最終掛載點(diǎn)的上一級目錄           有最終掛載點(diǎn)的一個(gè)目錄(例 /etc/auto.westos)

vim       /etc/auto.westos(你在/etc/auto.master下編輯的最終掛載點(diǎn)目錄)

編輯內(nèi)容:

nfs1                   172.25.254.250:/nfsshare/nfs1       ###將遠(yuǎn)程服務(wù)器的共享目錄掛載到nfs1,這樣只能掛載nfs2###

*                172.25.254.250:/nfsshare/&        ###可以掛載任意目錄###

systemctl   restart    autofs.service        ###重啟服務(wù)###

 

 

 

 

過程如下:

[root@localhost ~]# mkdir /westos              

[root@localhost ~]# vim /etc/auto.master

[root@localhost ~]# vim /etc/auto.westos

#####此時(shí)/etc/auto.westos下的內(nèi)容為: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

#####此時(shí)/etc/auto.westos下的內(nèi)容為:*                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


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI