访问网络文件共享服务

来源:互联网 发布:深圳市金软网络骗局 编辑:程序博客网 时间:2024/05/19 04:51

####unit7###

CIFS:通用网络文件系统:针对windows操作系统的本地网络文件系统;linux系统可以挂载和访问cifs文件共享。

[root@localhost ~]# yum search cifs                    
Loaded plugins: langpacks
============================ N/S matched: cifs =============================
cifs-utils.x86_64 : Utilities for mounting and managing CIFS mounts

  Name and summary matches only, use "search all" for everything.
[root@localhost ~]# yum search samba
\Loaded plugins: langpacks
============================ N/S matched: samba ============================
samba-client.x86_64 : Samba client programs
samba-common.x86_64 : Files used by both Samba servers and clients
samba-libs.i686 : Samba libraries
samba-libs.x86_64 : Samba libraries
samba-python.x86_64 : Samba Python libraries
samba-winbind.x86_64 : Samba winbind
samba-winbind-modules.i686 : Samba winbind modules
samba-winbind-modules.x86_64 : Samba winbind modules
samba.x86_64 : Server and Client software to interoperate with Windows
             : machines

  Name and summary matches only, use "search all" for everything.

[root@localhost ~]# yum install samba-client.x86_64 -y              #####安装客户端,识别服务器提供的cifs共享
Loaded plugins: langpacks
Resolving Dependencies
--> Running transaction check
---> Package samba-client.x86_64 0:4.1.1-31.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================
 Package            Arch         Version               Repository      Size
============================================================================
Installing:
 samba-client       x86_64       4.1.1-31.el7          rhel_dvd       513 k

Transaction Summary
============================================================================
Install  1 Package

Total download size: 513 k
Installed size: 1.4 M
Downloading packages:
samba-client-4.1.1-31.el7.x86_64.rpm                   | 513 kB   00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : samba-client-4.1.1-31.el7.x86_64                         1/1
  Verifying  : samba-client-4.1.1-31.el7.x86_64                         1/1

Installed:
  samba-client.x86_64 0:4.1.1-31.el7                                        

Complete!

[root@localhost ~]# 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
    ---------            -------

[root@localhost ~]# smbclient  //172.25.254.250/westos1               
Enter root's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]
smb: \> quit
[root@localhost ~]# mount //172.25.254.250/westos1 /mnt/ -o username=guest       #####挂载文件到/mnt,匿名用户可访问到
[root@localhost ~]# df
Filesystem               1K-blocks     Used Available Use% Mounted on
/dev/vda1                 10473900  3210252   7263648  31% /
devtmpfs                    927072        0    927072   0% /dev
tmpfs                       942660      140    942520   1% /dev/shm
tmpfs                       942660      644    942016   1% /run
tmpfs                       942660        0    942660   0% /sys/fs/cgroup
//172.25.254.250/westos1 100221120 78407756  21813364  79% /mnt

[root@localhost ~]# umount /mnt/

[root@localhost ~]# vim /etc/fstab


[root@localhost ~]# vim /etc/rc.d/rc.local


[root@localhost ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/vda1       10473900 3210232   7263668  31% /
devtmpfs          927072       0    927072   0% /dev
tmpfs             942660     140    942520   1% /dev/shm
tmpfs             942660     644    942016   1% /run
tmpfs             942660       0    942660   0% /sys/fs/cgroup

[root@localhost ~]# mount -a                                         ######使更改生效
[root@localhost ~]# df
Filesystem               1K-blocks     Used Available Use% Mounted on
/dev/vda1                 10473900  3210232   7263668  31% /
devtmpfs                    927072        0    927072   0% /dev
tmpfs                       942660      140    942520   1% /dev/shm
tmpfs                       942660      644    942016   1% /run
tmpfs                       942660        0    942660   0% /sys/fs/cgroup
//172.25.254.250/westos1 100221120 78407724  21813396  79% /mn
t

NFS:网络文件系统:支持本地linux权限和文件系统功能。


[root@localhost ~]# yum install nfs-utils -y
Loaded plugins: langpacks
Package 1:nfs-utils-1.3.0-0.el7.x86_64 already installed and latest version
Nothing to do
[root@localhost ~]# showmount -e 172.25.254.250             ######识别连接到的服务端 
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 ~]#df

Filesystem                    1K-blocks     Used Available Use% Mounted on
/dev/vda1                      10473900  3210260   7263640  31% /
devtmpfs                         927072        0    927072   0% /dev
tmpfs                            942660      140    942520   1% /dev/shm
tmpfs                            942660      676    941984   1% /run
tmpfs                            942660        0    942660   0% /sys/fs/cgroup
172.25.254.250:/nfsshare/nfs1 100221952 78411776  21810176  79% /mnt

[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  3210280   7263620  31% /
devtmpfs                         927072        0    927072   0% /dev
tmpfs                            942660      140    942520   1% /dev/shm
tmpfs                            942660      676    941984   1% /run
tmpfs                            942660        0    942660   0% /sys/fs/cgroup
172.25.254.250:/nfsshare/nfs1 100221952 78407680  21814272  79% /mnt


[root@localhost ~]# yum install autofs -y                   ########下载autofs服务
Loaded plugins: langpacks
Resolving Dependencies
--> Running transaction check
---> Package autofs.x86_64 1:5.0.7-40.el7 will be installed
--> Processing Dependency: libhesiod.so.0()(64bit) for package: 1:autofs-5.0.7-40.el7.x86_64
--> Running transaction check
---> Package hesiod.x86_64 0:3.2.1-3.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================
 Package       Arch          Version                  Repository       Size
============================================================================
Installing:
 autofs        x86_64        1:5.0.7-40.el7           rhel_dvd        550 k
Installing for dependencies:
 hesiod        x86_64        3.2.1-3.el7              rhel_dvd         30 k

Transaction Summary
============================================================================
Install  1 Package (+1 Dependent package)

Total download size: 579 k
Installed size: 3.6 M
Downloading packages:
(1/2): hesiod-3.2.1-3.el7.x86_64.rpm                   |  30 kB   00:00     
(2/2): autofs-5.0.7-40.el7.x86_64.rpm                  | 550 kB   00:00     
----------------------------------------------------------------------------
Total                                          3.4 MB/s | 579 kB  00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : hesiod-3.2.1-3.el7.x86_64                                1/2
  Installing : 1:autofs-5.0.7-40.el7.x86_64                             2/2
  Verifying  : hesiod-3.2.1-3.el7.x86_64                                1/2
  Verifying  : 1:autofs-5.0.7-40.el7.x86_64                             2/2

Installed:
  autofs.x86_64 1:5.0.7-40.el7                                              

Dependency Installed:
  hesiod.x86_64 0:3.2.1-3.el7                                               

Complete!

[root@localhost ~]# systemctl start autofs                     #####开启服务
[root@localhost ~]# cd /net                                                 #####autofs服务运行时,存在此目录,但该目录为空
[root@localhost net]# ls
[root@localhost net]# cd 172.25.254.250                         ######访问时,使自动挂载器创建该子目录      
[root@localhost 172.25.254.250]# ls
content  nfsshare
[root@localhost 172.25.254.250]# pwd
/net/172.25.254.250
[root@localhost 172.25.254.250]# cd nfsshare/
[root@localhost nfsshare]# ls                               #####浏览共享
nfs1  nfs2  nfs3  nfs4  nfs5
[root@localhost nfsshare]# cd nfs1
[root@localhost nfs1]# ls                                      #####浏览共享
haha       westos23  westos39  westos54  westos7   westos85
[root@localhost nfs1]# pwd
/net/172.25.254.250/nfsshare/nfs1
[root@localhost nfs1]# ls
file1
[root@localhost nfs1]# df
Filesystem                    1K-blocks     Used Available Use% Mounted on
/dev/vda1                      10473900  3214292   7259608  31% /
devtmpfs                         927072        0    927072   0% /dev
tmpfs                            942660      140    942520   1% /dev/shm
tmpfs                            942660      688    941972   1% /run
tmpfs                            942660        0    942660   0% /sys/fs/cgroup
172.25.254.250:/nfsshare/nfs1 100221952 78411776  21810176  79% /net/172.25.254.250/nfsshare/nfs1

[root@localhost ~]# umount /mnt
[root@localhost ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/vda1       10473900 3214312   7259588  31% /
devtmpfs          927072       0    927072   0% /dev
tmpfs             942660     140    942520   1% /dev/shm
tmpfs             942660     684    941976   1% /run
tmpfs             942660       0    942660   0% /sys/fs/cgroup


[root@localhost ~]# mkdir /westos                                    #######创建目录

[root@localhost ~]# vim /etc/auto.master                        #####更改挂载目录                   


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

 

[root@localhost ~]# systemctl restart autofs.service         #####重启服务

测试:

[root@localhost ~]# cd /westos/nfs1
[root@localhost nfs1]# pwd
/westos/nfs1
[root@localhost nfs1]# cd
[root@localhost ~]# cd /westos/nfs2
[root@localhost nfs2]# pwd
/westos/nfs2
[root@localhost nfs2]# cd
[root@localhost ~]# cd /westos/nfs3
[root@localhost nfs3]# pwd
/westos/nfs3
[root@localhost nfs3]# df
Filesystem                    1K-blocks     Used Available Use% Mounted on
/dev/vda1                      10473900  3214304   7259596  31% /
devtmpfs                         927072        0    927072   0% /dev
tmpfs                            942660      140    942520   1% /dev/shm
tmpfs                            942660      684    941976   1% /run
tmpfs                            942660        0    942660   0% /sys/fs/cgroup
172.25.254.250:/nfsshare/nfs3 100221952 78544896  21677056  79% /westos/nfs3

[root@localhost nfs3]# cd
0 0
原创粉丝点击