centos7下NFS配置

时间:2019-08-13
本文章向大家介绍centos7下NFS配置,主要包括centos7下NFS配置使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

NFS是Network File System的缩写,即网络文件系统。客户端通过挂载的方式将NFS服务器端共享的数据目录挂载到本地目录下。

前言
四台机器:
172.16.158.216(把216机器上的/root/filedata目录共享到217,218,218三台机器的/root/filedir目录下)
172.16.158.217
172.16.158.218
172.16.158.219

一、NFS服务安装配置
216-219四台机口全部安装nfs-utils和rpcbind

1:查看是否安装nfs-utils和rpcbind
     rpm -qa nfs-utils rpcbind

2:安装nfs-utils和rpcbind
     yum install nfs-utils rpcbind

3:查看安装目录
    which rpcbind

4:nfs除了主程序端口2049和rpcbind的端口111是固定以外,还会使用一些随机端口,以下配置将定义这些端口,以便配置防火墙
     vim /etc/sysconfig/nfs
     #追加端口配置
    MOUNTD_PORT=4001  
    STATD_PORT=4002
    LOCKD_TCPPORT=4003
    LOCKD_UDPPORT=4003
   RQUOTAD_PORT=4004

5:在172.16.158.216上开放以下端口
    firewall-cmd --zone=public --add-port=111/tcp --permanent
    firewall-cmd --zone=public --add-port=2049/tcp --permanent
    firewall-cmd --zone=public --add-port=4001/tcp --permanent
    firewall-cmd --zone=public --add-port=4002/tcp --permanent
    firewall-cmd --zone=public --add-port=4003/tcp --permanent
    firewall-cmd --zone=public --add-port=4004/tcp --permanent
    firewall-cmd --zone=public --add-port=111/udp --permanent 
    firewall-cmd --zone=public --add-port=2049/udp --permanent
    firewall-cmd --zone=public --add-port=4001/udp --permanent
    firewall-cmd --zone=public --add-port=4002/udp --permanent
    firewall-cmd --zone=public --add-port=4003/udp --permanent
    firewall-cmd --zone=public --add-port=4004/udp --permanent

    firewall-cmd --reload

6:启动rpc服务
     systemctl start rpcbind.service
7:查看状态
    systemctl status rpcbind.service

8:启动NFS服务
     systemctl start nfs.service
9:查看状态
    systemctl status nfs.service

10:查看NFS常见进程详解
     ps -ef|egrep "rpc|nfs"

二、配置NFS服务端
配制说明:
exports文件配置文件/etc/exports
exports文件配置格式:NFS共享的目录 NFS客户端地址1(参数1,参数2,...) 客户端地址2(参数1,参数2,...)

NFS客户端地址:
指定IP: 192.168.0.1
指定子网所有主机: 192.168.0.0/24
指定域名的主机: test.com
指定域名所有主机: *.test.com
所有主机: *

参数:
ro:目录只读
rw:目录读写
sync:将数据同步写入内存缓冲区与磁盘中,效率低,但可以保证数据的一致性
async:将数据先保存在内存缓冲区中,必要时才写入磁盘
all_squash:将远程访问的所有普通用户及所属组都映射为匿名用户或用户组(nfsnobody)
no_all_squash:与all_squash取反(默认设置)
root_squash:将root用户及所属组都映射为匿名用户或用户组(默认设置)
no_root_squash:与rootsquash取反
anonuid=xxx:将远程访问的所有用户都映射为匿名用户,并指定该用户为本地用户(UID=xxx)
anongid=xxx:将远程访问的所有用户组都映射为匿名用户组账户

################开始在216上进行共享目录的配制####################
1:创建需要共享的目录
     mkdir -p /root/filedata
2:授权
     chown nfsnobody.nfsnobody /root/filedata

3:编辑配制文件
    vim /etc/exports
    ###内容:
   /root/filedata 172.16.158.217(rw,sync,all_squash)
   /root/filedata 172.16.158.218(rw,sync,all_squash)
   /root/filedata 172.16.158.219(rw,sync,all_squash)

4:重新加载nfs配置
     exportfs -rv

5:查看nfs服务器挂载情况
   showmount -e localhost

三、配制NFS客户端
    分别在:172.16.158.217172.16.158.218172.16.158.219进行操作

1:创建要挂载的对应目录
    mkdir -p /root/filedir

2: 把216上的/root/filedata目录挂到当前操作机器的/root/filedir目录
      mount -t nfs 172.16.158.216:/root/filedata /root/filedir

3:查看挂载
     df -h

四、测试
    分别在:172.16.158.217172.16.158.218172.16.158.219三台机器上创建一个文件,
   在172.16.158.216172.16.158.217172.16.158.218172.16.158.219四台机器上都可以看到说明成功

原文地址:https://www.cnblogs.com/feiyun126/p/11344831.html