Linux中架设一台NFS服务器,按照要求配置

实验任务:
架设一台NFS服务器,并按照以下要求配置
1、开放/nfs/shared目录,供所有用户查询资料;
2、开放/nfs/upload目录,该目录为172.24.8.0/24网段的主机的数据上传目录,并将所有该网段主机上传文件的所属者和所属组映射为nfs-upload,其UID和GID为2001;
3、将/home/tom(该目录为uid=1111,gid=1111的tom用户的家目录)目录仅共享给172.24.8.129这台主机上的jerry用户,jerry对该目录具有访问、新建和删除文件的权限。

实验步骤:
安装对应NFS和RPC的软件包,关闭防火墙

[root@localhost nfs]# yum install nfs-utils -y
[root@localhost nfs]# yum install rpcbind -y
[root@localhost nfs]# systemctl stop firewalld.service 
[root@localhost nfs]# setenforce 0

1、开放/nfs/shared目录,供所有用户查询资料;
进入exports文件中配置文件传输的权限

[root@localhost tom]# vim /etc/exports
/nfs/shared     *(ro)	#*号代表可以给所以主机共享

2、开放/nfs/upload目录,该目录为172.24.8.0/24网段的主机的数据上传目录,并将所有该网段主机上传文件的所属者和所属组映射为nfs-upload,其UID和GID为2001;
进入exports配置目录文件传输信息

[root@localhost tom]# vim /etc/exports
/nfs/upload     192.168.175.0/24(rw,all_squash,anonuid=2001,anongid=2001)

创建用户和设置UID和GID

[root@localhost nfs]# useradd -u 2001 nfs-upload
[root@localhost nfs]# id nfs-upload 
uid=2001(nfs-upload) gid=2001(nfs-upload) groups=2001(nfs-upload)

3、将/home/tom(该目录为uid=1111,gid=1111的tom用户的家目录)目录仅共享给192.168.175.133这台主机上的jerry用户,jerry对该目录具有访问、新建和删除文件的权限。
进入exports配置目录文件传输信息

[root@localhost tom]# vim /etc/exports
/home/tom       192.168.175.133(rw)

添加tom用户查看用户信息

[root@localhost nfs]# useradd -u 1111 tom
[root@localhost nfs]# ll /home/
total 4
drwx------.  3 nfs-upload nfs-upload   78 Aug 11 15:48 nfs-upload
drwx------. 15 redhat     redhat     4096 Jul 15 14:29 redhat
drwx------.  3 tom        tom          78 Aug 11 16:17 tom
drwx------.  3 nfs-upload nfs-upload   78 Aug 11 15:46 ufs-upload

重启服务即可

[root@localhost nfs]# systemctl restart rpcbind
[root@localhost nfs]# systemctl restart nfs-server.service 

在另外用户上创建jerry用户并且UID和GID同为1111,挂载到本地

[root@localhost upload]# useradd jerry -u 1111
[root@localhost nfs]# mount 192.168.175.129:/home/tom tom/
[root@localhost nfs]# ll
total 0
drwxr-xr-x. 2 root  root  20 Aug 11 15:40 shared
drwx------. 3 jerry jerry 78 Aug 11 16:17 tom
drwxr-xrwx. 2 root  root  32 Aug 11 16:10 upload

最后在客户机上测试Jerry用户进入tom目录增删改查

[root@localhost nfs]# su - jerry 
[jerry@localhost ~]$ cd /nfs/
[jerry@localhost nfs]$ ll
total 0
drwxr-xr-x. 2 root  root  20 Aug 11 15:40 shared
drwx------. 3 jerry jerry 78 Aug 11 16:17 tom
drwxr-xrwx. 2 root  root  32 Aug 11 16:10 upload
[jerry@localhost nfs]$ cd tom/
[jerry@localhost tom]$ touch file
[jerry@localhost tom]$ ll
total 0
-rw-rw-r--. 1 jerry jerry 0 Aug 11 16:33 file
-rw-r--r--. 1 root  root  0 Aug 11 16:44 server

测试完成,实验也完成。
感谢观看,希望这篇文章对你也有帮助。

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值