企业级NFS网络文件共享服务

本文详细介绍了NFS服务在企业环境中的部署步骤,包括服务器角色配置、内核版本确认、软件安装、NFS exports配置,以及客户端的设置和权限管理。重点讲解了常用配置参数和实战案例,适合IT技术人员参考。
摘要由CSDN通过智能技术生成

NFS服务环境准备

服务器角色列表

NFS server:192.168.1.5
NFS clent01:192.168.1.4
NFS clent01:192.168.1.3

系统及内核版本

[root@nfs-server ~]# cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core) 
[root@nfs-server ~]# uname -r
3.10.0-693.el7.x86_64
注:防火墙和selinux都关闭

软件列表

nfs-utils
rpcbind

NFS服务企业案例部署

将NFS server的/data目录共享给192.168.1.0网段,要求可读写

NFS服务端部署

服务安装

[root@nfs-server ~]# yum -y install nfs-utils rpcbind
[root@nfs-server ~]# rpm -qa nfs* rpcbind
nfs-utils-1.3.0-0.66.el7_8.x86_64
rpcbind-0.2.0-49.el7.x86_64
[root@nfs-server ~]# systemctl start rpcbind.service
[root@nfs-server ~]# systemctl enable rpcbind
[root@nfs-server ~]# lsof -i :111
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
rpcbind 16202  rpc    6u  IPv4  64534      0t0  UDP *:sunrpc 
rpcbind 16202  rpc    8u  IPv4  64536      0t0  TCP *:sunrpc (LISTEN)
rpcbind 16202  rpc    9u  IPv6  64537      0t0  UDP *:sunrpc 
rpcbind 16202  rpc   11u  IPv6  64539      0t0  TCP *:sunrpc (LISTEN)
[root@nfs-server ~]# systemctl start nfs.service 
[root@nfs-server ~]# systemctl enable nfs.service 

创建共享目录及授权

[root@nfs-server ~]# mkdir -p /data
[root@nfs-server ~]# chown -R nfsnobody.nfsnobody /data
[root@nfs-server ~]# ll -d /data/
drwxr-xr-x 2 nfsnobody nfsnobody 6 10月 23 15:20 /data/

配置NFS配置文件

[root@nfs-server ~]# vim /etc/exports
[root@nfs-server ~]# cat /etc/exports
/data 192.168.1.0/24(rw,sync)
[root@nfs-server ~]# exportfs -rv
exporting 192.168.1.0/24:/data
[root@nfs-server ~]# showmount -e localhost
Export list for localhost:
/data 192.168.1.0/24
[root@nfs-server ~]# cat /var/lib/nfs/etab 
/data	192.168.1.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,no_pnfs,anonuid=65534,anongid=65534,sec=sys,rw,secure,root_squash,no_all_squash)

本地挂载测试

[root@nfs-server ~]# mount -t nfs 192.168.1.5:/data /mnt/
[root@nfs-server ~]# df -h 
192.168.1.5:/data         18G  1.6G   17G    9% /mnt

客户端配置(所有)

[root@nfs-clent01 ~]# yum -y install rpcbind nfs-utils
[root@nfs-clent01 ~]# systemctl start rpcbind.service 
[root@nfs-clent01 ~]# systemctl enable rpcbind.service
注:nfs服务不用启动
[root@nfs-clent01 ~]# showmount -e 192.168.1.5
Export list for 192.168.1.5:
/data 192.168.1.0/24
[root@nfs-clent01 ~]# mount -t nfs 192.168.1.5:/data /mnt
[root@nfs-clent01 ~]# df -h
192.168.1.5:/data         18G  1.6G   17G    9% /mnt
[root@nfs-clent01 ~]# echo "/bin/mount -t nfs 192.168.1.5:/data /mnt" >>/etc/rc.local 

测试:在clent01的/mnt目录下创建测试文件,clent02和nfs-server都能收到共享文件

[root@nfs-clent01 ~]# cd /mnt/
[root@nfs-clent01 mnt]# ls
[root@nfs-clent01 mnt]# touch test.txt

clent02查看

[root@nfs-clent02 ~]# ll /mnt/
总用量 0
-rw-r--r-- 1 nfsnobody nfsnobody 0 10月 23 15:41 test.txt

nfs-server查看

[root@nfs-server ~]# ll /mnt/
总用量 0
-rw-r--r-- 1 nfsnobody nfsnobody 0 10月 23 15:41 test.txt

NFS服务常用配置参数权限

即为括号内参数

rw:表示可读写
ro:表示只读
sync:写数据时同步写入NFS server磁盘(有点安全,缺点性能会稍降低)
async:写数据会先写入缓冲区,硬盘有空档在写入硬盘
no_root_squash:访问NFS server共享目录的如果是root的话,它对该目录具有root权限
root_squash:访问NFS server共享目录的如果是root的话,权限将会压缩为匿名用户
all_squash:所有用户的权限都会压缩为匿名用户
anonuid:匿名用户,uid通常为nfsnobody用户的值
anongid:匿名用户组,uid通常为nfsnobody用户组的值

企业生产NFS exports配置实例

配置例一:

/data 192.168.1.0/24(rw,sync)
注:允许客户端读写,并且数据同步到服务器端的磁盘里

配置例二:

/data/blog 192.168.1.0/24(rw,sync,all_squash,anonuid=2000,anongid=2000)
注:允许客户端读写,并且数据同步写入服务端磁盘,指定客户端用户的UID和GID

配置例三:

/data/log 192.168.1.0/24(ro)
注:只读,例如有特定用户需要查看共享目录文件的需求,又不希望用户有修改的权限

重点NFS服务文件或命令说明

/etc/exports:主配置文件,默认为空
/usr/sbin/exportfs:管理命令,加载配置生效:exportfs -rv
/usr/sbin/showmount:查看配置及挂在结果:showmount -e 192.168.1.5
/var/lib/nfs/etab:配置文件的完整设定参数
/proc/mounts:客户端挂载参数:grep mnt /proc/mounts
/var/lib/nfs/rmtab:客户端访问服务器exports的信息列表
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

丶重明

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值