Centos 7 安装和配置NFS服务

                                                                                  Centos 7 安装和配置NFS服务

1、安装nfs服务
    yum -y install nfs-utils

    
2、编辑exports
    (1) 用vi打开exports
    vi /etc/exports    
    (2) 增加访问目录
    /home/ 192.168.1.20/24(rw,sync,no_root_squash,no_subtree_check)
    共享目录  访问者的IP限制(共享选项)
    
    选项说明
        ro:共享目录只读
        rw:共享目录可读可写
        all_squash:所有访问用户都映射为匿名用户或用户组
        no_all_squash(默认):访问用户先与本机用户匹配,匹配失败后再映射为匿名用户或用户组
        root_squash(默认):将来访的root用户映射为匿名用户或用户组
        no_root_squash:来访的root用户保持root帐号权限
        anonuid=<UID>:指定匿名访问用户的本地用户UID,默认为nfsnobody(65534)
        anongid=<GID>:指定匿名访问用户的本地用户组GID,默认为nfsnobody(65534)
        secure(默认):限制客户端只能从小于1024的tcp/ip端口连接服务器
        insecure:允许客户端从大于1024的tcp/ip端口连接服务器
        sync:将数据同步写入内存缓冲区与磁盘中,效率低,但可以保证数据的一致性
        async:将数据先保存在内存缓冲区中,必要时才写入磁盘
        wdelay(默认):检查是否有相关的写操作,如果有则将这些写操作一起执行,这样可以提高效率
        no_wdelay:若有写操作则立即执行,应与sync配合使用
        subtree_check(默认) :若输出目录是一个子目录,则nfs服务器将检查其父目录的权限
        no_subtree_check :即使输出目录是一个子目录,nfs服务器也不检查其父目录的权限,这样可以提高效率
    
3、重新加载配置
    exportfs -r  //使配置生效
    
4、启动nfs服务
    systemctl start rpcbind
    systemctl start nfs-server    
    
    确认NFS服务器启动成功:
    rpcinfo -p

5、设置nfs开机启动
    systemctl enable rpcbind
    systemctl enable nfs-server
    

6、关闭防火墙
    临时关闭防火墙
    systemctl stop firewalld

    永久防火墙开机自启动
    systemctl disable firewalld

    临时打开防火墙
    systemctl start firewalld

    防火墙开机启动
    systemctl enable firewalld

    查看防火墙状态
    systemctl status firewalld

7、关闭SELinux
    临时关闭SELinux
    setenforce 0


    临时打开SELinux
    setenforce 1
    
    开机关闭SELinux
    编辑/etc/selinux/config文件,将SELINUX的值设置为disabled (不是最后一行)
    
    # This file controls the state of SELinux on the system.
    # SELINUX= can take one of these three values:
    #     enforcing - SELinux security policy is enforced.
    #     permissive - SELinux prints warnings instead of enforcing.
    #     disabled - No SELinux policy is loaded.
    SELINUX=disabled
    # SELINUXTYPE= can take one of three two values:
    #     targeted - Targeted processes are protected,
    #     minimum - Modification of targeted policy. Only selected processes are protected. 
    #     mls - Multi Level Security protection.
    SELINUXTYPE=targeted 

    查看SELinux状态
    执行getenforce命令
    
8、查看远程电脑NFS共享的目录

    showmount -e 远程电脑的IP
    
    完整用法
    showmount -e [server]    显示 NFS 服务器导出的所有共享。
    showmount -a [server]    列出客户端主机名或 IP 地址,以及使用“主机:目录”格式显示的安装目录。
    showmount -d [server]    显示 NFS 服务器上当前由某些 NFS 客户端安装的目录。

9、linux 挂载nfs
    1、mount挂载
    mount -t nfs 192.168.1.2:/home /home/disk/
    
    2、永久挂载
    vim /etc/fstab       //mount永久生效,重启后mount不消失
    192.168.1.2:/home  /home/disk              nfs     nolock          0 0

10、windows 挂载nfs
    1、打开nfs功能
        控制面板----程序和功能----启用或关闭Windows功能----NFS服务----[nfs客户端+管理工具]
    2、修改nfs权限的写权限
        需要读写权限的需要修改注册表 
        通过修改注册表将windows访问NFS时的UID和GID改成0即可,步骤如下 
        a、在运行中输入regedit,打开注册表编辑器; 
        b、进入HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ClientForNFS\CurrentVersion\Default条目; 
        c、选择新建—-QWORD值,新建AnonymousUid,AnonymousGid两个值,值为0. 

    3、挂载nfs
        a) dos挂载
            mount \\192.168.1.2:\home Z:
        
        b) 计算机--映射网络驱动器
            文件夹: \\192.168.1.2:\home

Reference:
    win10 挂载NFS(网络文件夹)
    https://blog.csdn.net/qq_34158598/article/details/81976063
    CentOS7下NFS服务安装及配置
    https://www.cnblogs.com/st-jun/p/7742560.html
    CentOS 7快速安装配置NFS服务
    https://www.cnblogs.com/vincent-liang/p/7043274.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章