温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

访问网络文件共享服务

发布时间:2020-06-02 17:31:58 来源:网络 阅读:881 作者:blueclo 栏目:建站服务器

第七单元

访问网络文件共享服务

 

 

挂载网络文件系统

网络文件系统是由网络附加存储服务器通过网络向多个主机提供的一种文件系统 , 而不是由块设备 ( 例如硬盘驱动器 ) 提供的。客户端通过特殊的文件系统协议和格式访问远程存储

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


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI