练习:
1、开放/nfs/shared目录,供所有用户查询资料
2、开放/nfs/upload目录,为192.168.xxx.0/24网段主机可以上传目录, 并将所有用户及所属的组映射为nfs-upload,其UID和GID均为210
3、将/home/tom目录仅共享给192.168.xxx.xxx这台主机,并只有用户tom可以完全访问该目
服务端
[root@localhost ~]# dnf install nfs-utils -y 安装nfs
[root@localhost ~]# vim /etc/exports 配置
[root@localhost ~]# cat /etc/exports
/nfs/upload 192.168.226.0/24(rw,anonuid=210,anongid=210) 开放/nfs/upload目录给192.168.226.0/24网段主机,给出读写权限,用户及所属组ID为210
/nfs/shared *(ro) 开放/nfs/shared目录,给出只读权限
/home/tom 192.168.226.128(rw) 开放/home/tom目录给192.168.226.128这台主机,给出读写权限
[root@localhost ~]# mkdir /nfs/shared/ -pv 创建目录 /nfs/shared/
mkdir: created directory '/nfs'
mkdir: created directory '/nfs/shared/'
[root@localhost ~]# touch /nfs/shared/{1..10} 创建文件夹 /nfs/shared/{1..10}
[root@localhost ~]# mkdir /nfs/upload -pv 创建目录/nfs/upload
mkdir /nfs/upload -pv
mkdir: created directory '/nfs/upload'
[root@localhost ~]# useradd -r -u 210 nfs-upload 所有用户及所属的组映射为nfs-upload,其UID和GID均为210
useradd: user 'nfs-upload' already exists
[root@localhost ~]# id nfs-upload
uid=210(nfs-upload) gid=210(nfs-upload) groups=210(nfs-upload)
[root@localhost ~]# chmod o+w /nfs/upload 给其他用户添加写的权限
[root@localhost ~]# useradd tom 创建tom用户
[root@localhost ~]# ll /home/tom/ -d
drwx------. 3 tom tom 78 Oct 26 15:54 /home/tom/
[root@localhost ~]# id tom
uid=1001(tom) gid=1001(tom) groups=1001(tom)
[root@localhost ~]# exportfs -ra 重新读取 NFS 服务器的所有导出配置,并更新其导出表
[root@localhost ~]# systemctl restart nfs-server 重启nfs
客户端
[root@localhost ~]# dnf install nfs-utils -y 下载nfs
[root@localhost ~]# mkdir /p 创建/p目录
[root@localhost ~]# mount 192.168.226.129:/nfs/shared /p 挂载
[root@localhost ~]# showmount -e 192.168.226.129
[root@localhost ~]# cd /p 测试
[root@localhost p]# ll
total 0
-rw-r--r--. 1 root root 0 Oct 26 15:04 1
-rw-r--r--. 1 root root 0 Oct 26 15:04 10
-rw-r--r--. 1 root root 0 Oct 26 15:04 2
-rw-r--r--. 1 root root 0 Oct 26 15:04 3
-rw-r--r--. 1 root root 0 Oct 26 15:04 4
-rw-r--r--. 1 root root 0 Oct 26 15:04 5
-rw-r--r--. 1 root root 0 Oct 26 15:04 6
-rw-r--r--. 1 root root 0 Oct 26 15:04 7
-rw-r--r--. 1 root root 0 Oct 26 15:04 8
-rw-r--r--. 1 root root 0 Oct 26 15:04 9
[root@localhost ~]# mkdir /p1 创建/p1目录
[root@localhost ~]# mount 192.168.226.129:/nfs/upload /p1 挂载
[root@localhost ~]# cd /p1
[root@localhost p1]# touch 1
[root@localhost p1]# ll /1 测试
total 0
-rw-r--r--. 1 210 210 0 Oct 26 16:04 1
[root@localhost p1]# mkdir /p2 创建/p2目录
[root@localhost p1]# id tom
uid=1001(tom) gid=1001(tom) groups=1001(tom)
[root@localhost p1]# su - tom 测试
[tom@localhost ~]$ touch a
[tom@localhost ~]$