NFS是一个Linux下的经典网络共享方案,由Server段提供共享,由客户端实施挂载。RHEL 7支持NFSv3和NFSv4。
NFS服务与RPC进程
启动nfs-server进程后,会带起NFS服务和PRC进程。RPC进程包括四个组件:
以下是英文原文介绍
– rpc.statd
: implements monitoring protocol (NSM) between NFS client and NFS server
– rpc.mountd
: NFS mount daemon that implements the server side of the mount requests from NFSv3 clients.
– rpc.idmapd
: Maps NFSv4 names and local UIDs and GIDs
– rpc.rquotad
: provides user quota information for remote users.
配置NFS server服务端
1. 安装nfs包
# rpm -qa | grep nfs-utils
# yum install nfs-utils rpcbind
2. 设置nfs及相关服务自启动
# systemctl enable nfs-server
# systemctl enable rpcbind
# systemctl enable nfs-lock
由于nfs程序包版本不同,nfs-lock在RHEL7.1版本(nfs-utils-1.3.0-8.el7)及以下无效,可以忽略(rpc-statd.service已经是静态了)。
# systemctl enable nfs-idmap
由于nfs程序包版本不同,nfs-idmap在RHEL7.1版本(nfs-utils-1.3.0-8.el7)及以下无效,可以忽略(nfs-idmap.service已经是静态了)。
3. 启动NFS服务
# systemctl start rpcbind
# systemctl start nfs-server
# systemctl start nfs-lock
# systemctl start nfs-idmap
4. 检查NFS服务状态:
# systemctl status nfs
5. 创建需要共享的目录
# mkdir /test
6. 配置属组
# chgrp nfsnobody /test
7. 配置权限:
# chmod -R 775 /test
8. Export共享目录
参照格式修改/etc/exports文件
dir client1 (options) [client2(options)...]
以下是Option设置说明,第一项是默认值
ro / rw :
a) ro : allow clients read only access to the share.
b) rw : allow clients read write access to the share.
sync / async :
a) sync : NFS server replies to request only after changes made by previous request are written to disk.
b) async : specifies that the server does not have to wait.
wdelay / no_wdelay
a) wdelay : NFS server delays committing write requests when it suspects another write request is imminent.
b) no_wdelay : use this option to disable to the delay. no_wdelay option can only be enabled if default sync
option is enabled.
no_all_squash / all_squash :
a) no_all_squash : does not change the mapping of remote users.
b) all_squash : to squash all remote users including root.
root_squash / no_root_squash :
a) root_squash : prevent root users connected remotely from having root access. Effectively squashing remote root privileges.
b) no_root_squash : disable root squashing.
示例:
# vi /etc/exports
/test *(rw)
/nfs 192.168.1.12(ro)
9. 生效配置
# exportfs -r
-r 重新刷新nfs配置,同步至/var/lib/nfs/etab。
其他参数如下
-a : exports entries in /etc/exports but do not synchronize with /var/lib/nfs/etab
-i : ignore entries in /etc/exports and uses command line arguments.
-u : un-export one or more directories
-o : specify client options on command line
10. 重启nfs服务:
# systemctl restart nfs-server
NFS客户端配置
1. 安装nfs客户端包
# rpm -qa | grep nfs-utils
# yum install nfs-utils
2. 手工挂载
mount -t nfs -o options host:/remote/export /local/directory
示例 :
# mount -t nfs -o ro,nosuid remote_host:/home /remote_home
3. 配置/etc/fstab实现系统启动时自动挂载
# vi /etc/fstab
remote_host:/home /remote_home nfs rw,nosuid,_netdev 0 0
NFS相关防火墙配置
服务器端防火墙加上进站允许策略
# firewall-cmd --add-service=nfs --zone=internal --permanent
# firewall-cmd --add-service=mountd --zone=internal --permanent
# firewall-cmd --add-service=rpc-bind --zone=internal --permanent