访问网络文件共享服务

xiaoxiao2021-02-27  585

网络文件共享服务

所谓网络文件共享服务,即一个服务器为多个客户端提供文件共享服务,有linux对linux,也有windows对linux,linux对windows

CIFS: 通用网络文件系统

CIFS

CIFS是针对 Microsoft Windows 操作系统的本地网络文件系统。 Linux 系统可以挂载和访问 CIFS 文件共享 , 如同常见的网络文件系统一样。然而 , 由于 CIFS 是基于 NTFS 文件系统权限模型及其自身的身份验证系统来构建的 , 因而 CIFS 协中的所有内容并不能很好地映射到 Linux 中

samba-client RPM

samba-client RPM 软件包所包含的 smbclient 实用程序可用来识别由 Windows 或 Samba 文件服务器提供的 CIFS 共享。该实用程序工作起来犹如在 Microsoft Windows 中单击网上邻居。然后 mount命令可用于挂载共享。

1.安装samba服务

yum install samba-client.x86_64 -y

2.进入服务器

不需要输入密码,即可浏览 [root@localhost mnt]# smbclient -L //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 --------- -------

3.进入服务器的westos1目录

[root@localhost mnt]# smbclient //172.25.254.250/westos1 Enter root’s password: ####不需要输入密码 Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1] smb: > ls . D 0 Sun Apr 30 01:34:32 2017 .. D 0 Wed Dec 2 20:43:01 2015

48936 blocks of size 2097152. 10655 blocks available

smb: > !ls ####显示当前所在位置的内容 4 creat_user.sh userfile smb: > put userfile putting file userfile as \userfile (9.3 kb/s) (average 9.3 kb/s) ####可以上传文件 smb: >

4.挂载服务器

[root@localhost mnt]# mount //172.25.254.250/westos1 /mnt -o username=guest####将172.25.254.250/westos1挂载到/mnt上,因为windows的匿名用户为guest,所以需要加上 -o username=guest [root@localhost mnt]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/vda1 10473900 3357284 7116616 33% / devtmpfs 922268 0 922268 0% /dev tmpfs 942660 140 942520 1% /dev/shm tmpfs 942660 17036 925624 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 78405304 21815816 79% /mnt ####可以看出已经挂载上

5.开机挂载

在/etc/fatab文件中编辑 //172.25.254.250:/westos1 /mnt cifs defaults 0 0 [root@localhost mnt]# umount /mnt/ [root@localhost mnt]# vim /etc/fstab [root@localhost mnt]# mount -a [root@localhost mnt]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/vda1 10473900 3357304 7116596 33% / devtmpfs 922268 0 922268 0% /dev tmpfs 942660 140 942520 1% /dev/shm tmpfs 942660 17036 925624 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

nfs网络文件系统的访问

1.安装访问共享软件

yum install nfs-utils -y

2.识别共享

showmount -e 172.25.254.250

3.使用共享

[root@localhost mnt]# mount 172.25.254.250:/nfsshare/nfs1 /mnt####挂载 [root@localhost mnt]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/vda1 10473900 3357288 7116612 33% / devtmpfs 922268 0 922268 0% /dev tmpfs 942660 140 942520 1% /dev/shm tmpfs 942660 17036 925624 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 78408704 21813248 79% /mnt

4.开机自动挂载

编辑 /etc/fstab文件 172.25.254.250:/nfsshare/nfs1 /mnt nfs defaults 0 0 [root@localhost mnt]# umount /mnt [root@localhost mnt]# vim /etc/fstab [root@localhost mnt]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/vda1 10473900 3357308 7116592 33% / devtmpfs 922268 0 922268 0% /dev tmpfs 942660 140 942520 1% /dev/shm tmpfs 942660 17036 925624 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

间接映射

除了使用 /net 映射 , 系统管理员也可以手动配置任意目录, 以便访问时在其子目录上 “ 按需 ” 挂载特定共享。 间接映射使用两层配置文件语法。在顶级文件/etc/auto.master 中 , 每个管理的 “ 父 ” 目录和包含子目录挂载点与网络共享的单独的第二个配置文件的名称占一行

1.安装autofs软件

[root@localhost mnt]# yum install autofs -y

2./net映射

[root@localhost mnt]# cd /net -bash: cd: /net: No such file or directory [root@localhost mnt]# systemctl start autofs [root@localhost mnt]# cd /net [root@localhost net]# ls [root@localhost net]# cd 172.25.254.250 ####通过net映射可以直接访问远程服务器172.25.254.250 [root@localhost 172.25.254.250]# ls content nfsshare [root@localhost 172.25.254.250]# cd nfsshare/####进入172.25.254.250的nfsshare目录 [root@localhost nfsshare]# ls nfs1 nfs2 nfs3 nfs4 nfs5 [root@localhost nfsshare]# cd nfs1####进入172.25.254.250的nfsshare/nfs1目录 [root@localhost nfs1]# pwd /net/172.25.254.250/nfsshare/nfs1 [root@localhost nfs1]# ls 就你那渣渣网速抢我一楼 [root@localhost nfs1]# touch haha [root@localhost nfs1]# ls haha westos21 westos35 westos49 westos62 westos76 westos9 westos1 westos22 westos36 westos5 westos63 westos77 westos90 [root@localhost nfs1]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/vda1 10473900 3361848 7112052 33% / devtmpfs 922268 0 922268 0% /dev tmpfs 942660 140 942520 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% /net/172.25.254.250/nfsshare/nfs1####由此显示已经挂载,默认退出后300s后才自动卸载 [root@localhost nfs1]# cd [root@localhost ~]# vim /etc/sysconfig/autofs ####对autofs配置文件进行更改,设置闲置3秒后系统自动卸载网络设备 15 timeout = 3 [root@localhost ~]# systemctl restart autofs.service [root@localhost ~]# cd /net/172.25.254.250 [root@localhost 172.25.254.250]# cd nfsshare/nfs1 [root@localhost nfs1]# pwd /net/172.25.254.250/nfsshare/nfs1 [root@localhost nfs1]# ls lin WTF? xiaobaiisgay [root@localhost nfs1]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/vda1 10473900 3361372 7112528 33% / devtmpfs 922268 0 922268 0% /dev tmpfs 942660 140 942520 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 78413824 21808128 79% /net/172.25.254.250/nfsshare/nfs1 [root@localhost nfs1]# cd [root@localhost ~]# date Sun 30 Apr 02:18:22 EDT 2017 [root@localhost ~]# date Sun 30 Apr 02:18:23 EDT 2017 [root@localhost ~]# date Sun 30 Apr 02:18:26 EDT 2017 [root@localhost ~]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/vda1 10473900 3361372 7112528 33% / devtmpfs 922268 0 922268 0% /dev tmpfs 942660 140 942520 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####3秒后自动卸载 [root@localhost ~]# mkdir /westos [root@localhost ~]# vim /etc/auto.master####对子配置文件进行更改,/westos /etc/auto.westos,设置/westos为挂载目录 [root@localhost ~]# vim /etc/auto.westos [root@localhost ~]# cat /etc/auto.westos ####编辑配置文件 nfs1 172.25.254.250:/nfsshare/nfs1 * 172.25.254.250:/nfsshare/&####表示指定任意共享挂载 [root@localhost ~]# systemctl restart autofs.service [root@localhost ~]# cd /westos/ [root@localhost westos]# cd nfs1 [root@localhost nfs1]# ls [root@localhost nfs1]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/vda1 10473900 3361380 7112520 33% / devtmpfs 922268 0 922268 0% /dev tmpfs 942660 140 942520 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 78544896 21677056 79% /westos/nfs1 [root@localhost nfs1]# cd .. [root@localhost westos]# cd nfs2 ####可以任意切换挂载目录 [root@localhost nfs2]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/vda1 10473900 3361380 7112520 33% / devtmpfs 922268 0 922268 0% /dev tmpfs 942660 140 942520 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/nfs2 100221952 78544896 21677056 79% /westos/nfs2####可以看出切换目录后,挂载点也就变了 [root@localhost nfs2]# cd

转载请注明原文地址: https://www.6miu.com/read-805.html

最新回复(0)