(1)关闭防火墙和selinux 装软件
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# mount /dev/sr0 /mnt
mount: /mnt: WARNING: source write-protected, mounted read-only.
[root@localhost ~]# dnf install nfs-utils -y
编辑主配置文件 创建目录和测试文件
[root@localhost ~]# vim /etc/exports/nfs/shared *(ro)
[root@localhost ~]# mkdir -pv /nfs/shared
mkdir: created directory '/nfs'
mkdir: created directory '/nfs/shared'
[root@localhost ~]# touch /nfs/shared/test{a..k}
导出所有参数共享信息,立即生效
[root@localhost ~]# exportfs -ra
客户端 查看 挂载
[root@localhost ~]# showmount -e 192.168.160.129
Export list for 192.168.160.129:
/nfs/shared *
[root@localhost ~]# mount 192.168.160.129:/nfs/shared /media
访问共享目
[root@localhost ~]# ll /media/
total 0
-rw-r--r--. 1 root root 0 Nov 15 10:08 testa
-rw-r--r--. 1 root root 0 Nov 15 10:08 testb
-rw-r--r--. 1 root root 0 Nov 15 10:08 testc
-rw-r--r--. 1 root root 0 Nov 15 10:08 testd
-rw-r--r--. 1 root root 0 Nov 15 10:08 teste
-rw-r--r--. 1 root root 0 Nov 15 10:08 testf
-rw-r--r--. 1 root root 0 Nov 15 10:08 testg
-rw-r--r--. 1 root root 0 Nov 15 10:08 testh
-rw-r--r--. 1 root root 0 Nov 15 10:08 testi
-rw-r--r--. 1 root root 0 Nov 15 10:08 testj
-rw-r--r--. 1 root root 0 Nov 15 10:08 testk
2、开放/nfs/upload目录,为192.168.xxx.0/24网段主机可以上传目录,并将所有用户及所属的组映射为nfs-upload,其UID和GID均为210
编辑主配置文件 创建目录和测试文件 修改目录权限
[root@localhost ~]# vim /etc/exports/nfs/upload 192.168.160.0/24(rw,all_squash,anonuid=210,anongid=210)
[root@localhost ~]# mkdir -pv /nfs/upload
mkdir: created directory '/nfs/upload'
[root@localhost ~]# touch /nfs/upload/test{1..10}
[root@localhost ~]# chmod 777 /nfs/upload
导出所有参数共享信息,立即生效
[root@localhost ~]# exportfs -ra
客户端 添加用户 查看 挂载
[root@localhost ~]# useradd -r -u 210 nfs-upload
[root@localhost ~]# id nfs-upload
uid=210(nfs-upload) gid=210(nfs-upload) groups=210(nfs-upload)
[root@localhost ~]# showmount -e 192.168.160.129
Export list for 192.168.160.129:
/nfs/upload 192.168.160.0/24
[root@localhost ~]# mount 192.168.160.129:/nfs/upload /media
访问共享目录
[root@localhost ~]# ll /media
total 0
-rw-r--r--. 1 root root 0 Nov 15 11:03 test1
-rw-r--r--. 1 root root 0 Nov 15 11:03 test10
-rw-r--r--. 1 root root 0 Nov 15 11:03 test2
-rw-r--r--. 1 root root 0 Nov 15 11:03 test3
-rw-r--r--. 1 root root 0 Nov 15 11:03 test4
-rw-r--r--. 1 root root 0 Nov 15 11:03 test5
-rw-r--r--. 1 root root 0 Nov 15 11:03 test6
-rw-r--r--. 1 root root 0 Nov 15 11:03 test7
-rw-r--r--. 1 root root 0 Nov 15 11:03 test8
-rw-r--r--. 1 root root 0 Nov 15 11:03 test9
3、将/home/tom目录仅共享给192.168.xxx.xxx这台主机,并只有用户tom可以完全访问该目录
编辑主配置文件 创建目录和测试文件 修改用户权限目录权限
[root@localhost ~]# vim /etc/exports/home/tom 192.168.160.120(rw,root_squash,all_squash,anonuid=1111,anongid=1111)
[root@localhost ~]# mkdir -pv /home/tom
mkdir: created directory '/home/tom'
[root@localhost ~]# touch /home/tom/test{a..h}
[root@localhost ~]# chown tom:tom /home/tom/[root@localhost ~]# chmod 700 /home/tom/[root@localhost ~]# ll -d /home/tom
drwx------. 2 tom tom 110 Nov 15 05:49 /home/tom
导出所有参数共享信息,立即生效
[root@localhost ~]# exportfs -ra
客户端 添加用户 查看 挂载
[root@localhost ~]# useradd -u 1111 tom
[root@localhost ~]# id tom
uid=1111(tom) gid=1111(tom) groups=1111(tom)
[root@localhost ~]# showmount -e 192.168.160.128
Export list for 192.168.160.128:
/home/tom 192.168.160.120
[root@localhost ~]# mount 192.168.160.128:/home/tom /media
访问共享目录
[root@localhost ~]# su - tom
[tom@localhost ~]$ ll /media
total 0
-rw-r--r--. 1 root root 0 Nov 15 11:49 testa
-rw-r--r--. 1 root root 0 Nov 15 11:49 testb
-rw-r--r--. 1 root root 0 Nov 15 11:49 testc
-rw-r--r--. 1 root root 0 Nov 15 11:49 testd
-rw-r--r--. 1 root root 0 Nov 15 11:49 teste
-rw-r--r--. 1 root root 0 Nov 15 11:49 testf
-rw-r--r--. 1 root root 0 Nov 15 11:49 testg
-rw-r--r--. 1 root root 0 Nov 15 11:49 testh