一、配置NFS服务


    NFS服务使用端口:2049

    此外还使用以下RPC服务的随机端口:

    RPC使用端口111:远程进程调用

        rpc.lock:随机端口

        rpc.mount:随机端口

        rpc.stat:随机端口


    在RHEL6中,以上随机端口需要设置固定的端口,而RHEL7中则以更简单的方式管理:


    查看本机开放的NFS端口,当重启NFS服务的时候,开放的端口会改变:

[root@client ~]# rpcinfo -p localhost
   program vers proto   port  service
    100024    1   udp  59791  status
    100024    1   tcp  43154  status
    100005    1   udp  20048  mountd
    100005    1   tcp  20048  mountd
    100005    2   udp  20048  mountd
    100005    2   tcp  20048  mountd
    100005    3   udp  20048  mountd
    100005    3   tcp  20048  mountd
    100003    3   tcp   2049  nfs
    100003    4   tcp   2049  nfs
    100227    3   tcp   2049  nfs_acl
    100003    3   udp   2049  nfs
    100003    4   udp   2049  nfs
    100227    3   udp   2049  nfs_acl
    100021    1   udp  46989  nlockmgr
    100021    3   udp  46989  nlockmgr
    100021    4   udp  46989  nlockmgr
    100021    1   tcp  59814  nlockmgr
    100021    3   tcp  59814  nlockmgr
    100021    4   tcp  59814  nlockmgr
    100011    1   udp    875  rquotad
    100011    2   udp    875  rquotad
    100011    1   tcp    875  rquotad
    100011    2   tcp    875  rquotad

        在RHEL7中,则只需要在防火墙添加相应的NFS服务即可:

[root@clz ~]# firewall-cmd --add-service=nfs --permanent
[root@clz ~]# firewall-cmd --add-service=rpc-bind --permanent
[root@clz ~]# firewall-cmd --add-service=mountd --permanent


        编辑/etc/exports文件,配置NFS共享:


    共享目录            范围1(权限1,权限2,权限3)        范围2(权限1,权限2,权限3)

/aa             10.35.89.0/26(rw,sync)     10.35.56.0/26(rw,sync)

    

    修改了exports文件后,无需重启nfs服务,否则可能会导致其他用户访问挂死,执行以下命令重新加载共享内容即可:

 [root@clz ~]# exportfs -avr


    在客户端查看服务器端共享的文件:

[root@client ~]# showmount -e 10.35.89.32

    挂载服务端共享的文件夹:

[root@client ~]# mount 10.35.89.32:/aa /nfs

    查看服务器端共享的文件的默认权限,其中65534指的是nfsnobody用户和组:

[root@client ~]# cat /var/lib/nfs/etab 
/aa10.35.89.0/26(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534,sec=sys,rw,secure,root_squash,no_all_squash)

    客户端默认使用的是nfsnobody的用户访问共享文件:

[root@client nfs]# touch aa
[root@client nfs]# ll
total 0
-rw-r--r--. 1 nfsnobody nfsnobody 0 Feb 11 10:05 aa

    

    export的权限如果加上no_root_squash,则客户端使用root用户访问共享文件时,使用的是root用户


二、配置samba服务


    samba用于类unix和windows之间的文件共享


    安装samba包:

[root@clz ~]# yum install samba -y

    

    samba的2个服务:


        1、smb:端口TCP139和445

        2、nmb::用于windows的netbios协议 使用udp137和138


    防火墙添加samba服务:

[root@clz ~]# firewall-cmd --add-service=samba --permanent

    

    编辑/etc/samba/smb.conf配置文件:


        主要 参数:

            

        全局参数:


                workgroup = WORKGROUP

                hosts allow = 127. 192.168.12. 192.168.13


                log file = /var/log/samba/log.%m


                security = user


            config file = /etc/samba/smb.conf.%U  为每个用户单独设置访问权限


        共享配置:


       [public]

          comment = Public Stuff

          path = /home/samba

          public = yes

          writable = yes(是否隐藏

          printable = no

          write list = +staff (+或@代表是组

         hosts allow = 10.35.89.30



    使用smbpasswd命令添加samba用户,添加的用户必须是系统已经存在的的用户,使用smbpasswd命令需先安装samba-client包:

[root@clz ~]# smbpasswd -a redhat

    使用pdbedit命令查看samba用户列表:

[root@clz ~]# pdbedit -L
redhat:1000:redhat

        

        使用smbclinet在linux系统访问samba共享文件:

[root@client nfs]# smbclient -L //10.35.89.32


        连接smb共享服务:

[root@client nfs]# smbclient  //10.35.89.32 -U redhat%redhat

        


        使用multuser多用户实现多用户权限的设置:


            安装cifs包:

[root@client /]# yum install cifs-utils.x86_64 -y

          挂载共享文件:


        服务器端共享配置“

            

[bb]
331         comment= bb share
332         path = /bb
333         writable = no
334         write list = tom

        客户端挂载:

    [root@client /]# mount -o multiuser,username=redhat,password=redhat,sec=ntlmssp //10.35.89.32/bb  /cc

        客户端使用除root之外的其他用户对共享的文件没有相关的读写权限:


        

[tom@client cc]$ ls
ls: reading directory .: Permission denied


        获取服务器端用户的权限:

[tom@client ~]$ cifscreds add 10.35.89.32 -u tom

        

    此时再访问共享文件夹,具有了读写权限:

[tom@client cc]$ ls
aa  bb  cc  nfs

        

        客户端设置开机自动挂载,编辑fstab:

    //10.35.89.32/bb        /cc     cifs    multiuser,username=redhat,passwd=redhat,sec=ntlmssp 0 0