实验要求:
架设一台NFS服务器,并按照以下要求配置
1、开放/nfs/shared目录,供所有用户查询资料
2、开放/nfs/upload目录,为192.168.xxx.0/24网段主机可以上传目录,
并将所有用户及所属的组映射为nfs-upload,其UID和GID均为210
3、将/home/tom目录仅共享给192.168.xxx.xxx这台主机,并只有用户tom可以完全访问该目录
实验步骤:
1.创建服务端
[root@localhost ~]# yum install rpcbind
[root@localhost ~]# yum install nfs-utils
#systemctl stop firewalld
#setenforce 0
#systemctl start nfs-server
2.[root@server ~]# dnf install nfs-utils -y 下载nfs
[root@server ~]# vim /etc/exports 配置
/nfs/shared *(ro)
/nfs/upload 192.168.40.0/24(rw,anonuid=210,anongid=210,sync)
/home/tom 192.168.40.128(rw)
3.创建文件
[root@server ~]# vim /etc/exports
[root@server ~]# mkdir /nfs/shared -pv
mkdir: created directory '/nfs/shared'
[root@server ~]# mkdir /nfs/upload -pv
mkdir: created directory '/nfs/upload'
[root@server ~]# useradd tom
[root@server ~]# id tom
uid=1001(tom) gid=1001(tom) groups=1001(tom)
4.[root@server ~]# useradd -r -u 210 nfs-upload
所有用户及所属的组映射为nfs-upload,其UID和GID均为210
5.[root@server ~]# chmod o+w /nfs/upload 给权限
- 启动服务
[root@server ~]# exportfs -ra
[root@server ~]# systemctl start rpcbind
[root@server ~]# systemctl start nfs-server
7.回到客户端
挂载并下载nfs
[root@localhost ~]# mount /dev/sr0 /mnt
mount: /mnt: WARNING: device write-protected, mounted read-only.
[root@localhost ~]# dnf install nfs-utils -y
8.启动服务
[root@localhost ~]# systemctl start rpcbind
[root@localhost ~]# systemctl start nfs-server
9.创建文件
[root@localhost ~]# mkdir /test{1..3}
10.挂载共享文件
[root@localhost ~]# mount 192.168.40.128:/nfs/shared /test1
[root@localhost ~]# mount 192.168.40.128:/nfs/upload /test2
[root@localhost ~]# mount 192.168.40.128:/home/tom /test3
11.
[root@localhost test2]# useradd tom
12.
[root@localhost test2]# id tom
uid=1001(tom) gid=1001(tom) groups=1001(tom)
[root@localhost ~]# vim /etc/fstab
/dev/mapper/rhel-root / xfs defaults 0 0
UUID=dac2f7fc-90d0-4e85-a41d-6a603e69a268 /boot xfs defaults 0 0
UUID=DFE5-17B1 /boot/efi vfat umask=0077,shortname=winnt 0 2
/dev/mapper/rhel-swap none swap defaults 0 0
192.168.40.128:/home/tom /test3 nfs4 defaults,sync 0 0
/dev/sr0 /mnt iso9660 defaults 0 0
13.验证
[root@localhost ~]# mount | grep /test2
192.168.40.128:/nfs/shared on /test2 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.40.128,local_lock=none,addr=192.168.40.128)
[root@localhost ~]# mount | grep /test1
192.168.40.128:/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.40.128,local_lock=none,addr=192.168.40.128)
[root@localhost ~]# mount | grep /test3
192.168.40.128:/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.40.128,local_lock=none,addr=192.168.40.128)

151

被折叠的 条评论
为什么被折叠?



