RECE-nfs共享文件
实验要求
架设一台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可以完全访问该目录
下载工具
[root@localhost ~]# yum install rpcbind
[root@localhost ~]# yum install nfs-utils
关闭防火墙并开启服务
[root@localhost zzy]# systemctl stop firewalld
[root@localhost zzy]# setenforce 0
[root@localhost zzy]# systemctl start nfs-server
服务机配置
[root@localhost zzy]# vim /etc/exports
[root@localhost zzy]# cat /etc/exports
/nfs/shared *(ro,sync)
/nfs/upload 192.168.64.0/24(rw,anonuid=210,anongid=210,sync)
/home/tom 192.168.64.132(rw)[root@localhost zzy]# mkdir /nfs/shared -pv
mkdir: created directory '/nfs'
mkdir: created directory '/nfs/shared'
[root@localhost zzy]# touch /nfs/shared/{0..10}
[root@localhost zzy]# mkdir /nfs/upload
[root@localhost zzy]# chmod o+w /nfs/upload
[root@localhost zzy]# useradd -u 210 -r nfs-upload
[root@localhost zzy]# useradd tom
[root@localhost zzy]# id tom
uid=1001(tom) gid=1001(tom) groups=1001(tom)
[root@localhost zzy]# ll /home/tom/ -d
drwx------. 3 tom tom 78 Oct 29 10:02 /home/tom/
[root@localhost zzy]# exportfs -ra
客户机配置
[root@localhost zzy]# showmount -e 192.168.64.131
Export list for 192.168.64.131:
/nfs/shared *
/nfs/upload 192.168.64.0/24
/home/tom 192.168.64.132
[root@localhost zzy]# mkdir /test/{1..5} -pv
mkdir: created directory '/test'
mkdir: created directory '/test/1'
mkdir: created directory '/test/2'
mkdir: created directory '/test/3'
mkdir: created directory '/test/4'
mkdir: created directory '/test/5'
[root@localhost zzy]# mount 192.168.64.131:/nfs/shared /test/1
[root@localhost zzy]# mount -o remount,ro 192.168.64.131:/nfs/shared /test/1
[root@localhost zzy]# mount | grep /test/1
192.168.64.131:/nfs/shared on /test/1 type nfs4 (ro,relatime,vers=4.2,rsize=262144,wsize=262144,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.64.132,local_lock=none,addr=192.168.64.131)
[root@localhost zzy]# vim /etc/fstab
[root@localhost zzy]# mount -a
mount: (hint) your fstab has been modified, but systemd still usesthe old version; use 'systemctl daemon-reload' to reload.
[root@localhost zzy]# systemctl daemon-reload
[root@localhost zzy]# mount -a
[root@localhost zzy]# mount 192.168.64.131:/home/tom /test/3
[root@localhost zzy]# ll /test/3
ls: cannot open directory '/test/3': Permission denied
[root@localhost zzy]# useradd -u 1001 tom
[root@localhost zzy]# su - tom
[tom@localhost ~]$ ll /test/3
total 0
[tom@localhost ~]$ touch a
[tom@localhost ~]$ su
Password:
[root@localhost tom]# mount
.....
192.168.64.131:/nfs/shared on /test/1 type nfs4 (ro,relatime,vers=4.2,rsize=262144,wsize=262144,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.64.132,local_lock=none,addr=192.168.64.131)
192.168.64.131:/nfs/upload on /test/2 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.64.132,local_lock=none,addr=192.168.64.131)
192.168.64.131:/home/tom on /test/3 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.64.132,local_lock=none,addr=192.168.64.131)
......
[root@localhost tom]# cat /etc/fstab
/dev/mapper/rhel-root / xfs defaults 0 0
UUID=c8ddc1a7-628f-4f9f-8b34-644ba3a8e92b /boot xfs defaults 0 0
/dev/mapper/rhel-swap none swap defaults 0 0
192.168.64.131:/nfs/upload /test/2 nfs4 defaults 0 0
[root@localhost tom]#