1、开放/nfs/shared目录,供所有用户查询资料
2、开放/nfs/upload目录,为192.168.xxx.0/24网段主机可以上传目录,
并将所有用户及所属的组映射为nfs-upload,其UID和GID均为210
3、将/home/tom目录仅共享给192.168.xxx.xxx这台主机,并只有用户tom对该目录有读写权限
服务器:192.168.137.130
配置文件
[root@10 ~]# rpm -qa | grep nfs-utils
nfs-utils-2.5.4-15.el9.x86_64
[root@10 ~]# vim /etc/exports
[root@10 ~]# cat /etc/exports
/nfs/shared *(ro)
/nfs/upload 192.168.137.0/24(rw,anonuid=210,anongid=210)
/home/tom 192.168.137.132(rw)
创建共享目录以及用户tom
[root@10 ~]# mkdir /nfs/upload -pv
mkdir: created directory '/nfs/upload'
[root@10 ~]# mkdir /nfs/shared -pv
[root@10 ~]# useradd tom
组映射为nfs-upload,其UID和GID均为210
[root@10 ~]# useradd -r -u 210 nfs-upload
配置生效
[root@10 ~]# exportfs -ra
设备:192.168.137.132
创建文件,挂载共享文件
[root@localhost ~]# mkdir /test{1..3}
[root@localhost ~]# mount 192.168.137.130:/nfs/shared /test1
[root@localhost ~]# mount | grep /test1
192.168.137.130:/nfs/shared on /test1 type nfs4 (rw,relatime,vers=4.2,rsize=262144,wsize=262144,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.137.132,local_lock=none,addr=192.168.137.130)
挂载,测试创建文件设备端没权限
[root@localhost ~]# mount 192.168.137.130:/nfs/upload /test2
[root@localhost ~]# cd /test2
[root@localhost test2]# touch 1
touch: cannot touch '1': Permission denied
在服务端开启权限
[root@10 ~]# chmod o+w /nfs/upload/
在设备上测试权限创建文件
[root@localhost test2]# touch 1
挂载test3
[root@localhost test2]# mount 192.168.137.130:/home/tom /test3
[root@localhost test2]# mount | grep /test3
192.168.137.130:/home/tom on /test3 type nfs4 (rw,relatime,vers=4.2,rsize=262144,wsize=262144,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.137.132,local_lock=none,addr=192.168.137.130)
设备上创建tom用户测试权限
[root@localhost test2]# useradd tom
[root@localhost test2]# id tom
uid=1001(tom) gid=1001(tom) groups=1001(tom)
[root@localhost test2]# su - tom
[tom@localhost ~]$ ll /test3
total 0
[tom@localhost ~]$ touch /test3/1
光盘的挂载
[root@localhost test2]# vim /etc/fstab
192.168.137.130:/home/tom /test3 nfs4 defaults,sync 0 0
/dev/sr0 /mnt iso9660 defaults 0 0
~
预挂载
[root@localhost test2]# vim /etc/fstab
[root@localhost test2]# mount -a
mount: /mnt: WARNING: source write-protected, mounted read-only.
[root@localhost test2]# reboot
[root@localhost test2]# Connection closing...Socket close.
挂载信息
/dev/nvme0n1p1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquota)
/dev/sr0 on /mnt type iso9660 (ro,relatime,nojoliet,check=s,map=n,blocksize=2048)
192.168.137.130:/home/tom on /test3 type nfs4 (rw,relatime,sync,vers=4.2,rsize=262144,wsize=262144,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.137.132,local_lock=none,addr=192.168.137.130)
挂载成功