nfs作业
服务机:
编写配置文件:
[root@localhost ~]# vim /etc/exports
配置文件内容:
/nfs/shared *(ro,sync)
/nfs/upload 192.168.36.0/24(rw,anonuid=210,anongid=210,sync)
/home/tom 192.168.36.132(rw)
创建目录,文件:
[root@localhost ~]# mkdir /nfs/shared -pv
mkdir: created directory '/nfs'
mkdir: created directory '/nfs/shared'
[root@localhost ~]# touch /nfs/shared/{0..10}
[root@localhost ~]# mkdir /nfs/upload
修改文件权限
[root@localhost ~]# chmod o+w /nfs/upload
创建tom用户设置uidgid,并查看是否有家目录
[root@localhost ~]# useradd -u 210 -r nfs-upload
[root@localhost ~]# useradd tom
[root@localhost ~]# id tom
uid=1001(tom) gid=1001(tom) groups=1001(tom)
[root@localhost ~]# ll /home/tom/ -d
drwx------. 3 tom tom 78 Oct 27 15:51 /home/tom/
保存配置
[root@localhost ~]# exportfs -ra
客户机:
查看服务机挂载目录:
[root@localhost ~]# showmount -e 192.168.36.131
Export list for 192.168.36.131:
/nfs/shared *
/nfs/upload 192.168.36.0/24
/home/tom 192.168.36.132
创建test目录用于放置挂载文件:
[root@localhost ~]# mkdir /test{1..3}
首先对shared目录进行挂载,手动修改权限:
[root@localhost ~]# mount -o remount,ro 192.168.36.131:/nfs/shared /test1
mount: /test1: mount point not mounted or bad option.
[root@localhost ~]# mount 192.168.36.131:/nfs/shared /test1
[root@localhost ~]# mount | grep /test1
192.168.36.131:/nfs/shared on /test1 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.36.132,local_lock=none,addr=192.168.36.131)
进入fstab配置文件,对upload实现自动挂载
[root@localhost ~]# vim /etc/fstab
[root@localhost ~]# mount -a
mount: (hint) your fstab has been modified, but systemd still uses
the old version; use 'systemctl daemon-reload' to reload.
[root@localhost ~]# systemctl daemon-reload
对tom实现挂载:
[root@localhost ~]# mount 192.168.36.131:/home/tom /test3
在root用户下没有权限查看:
[root@localhost ~]# ll /test3
ls: cannot open directory '/test3': Permission denied
添加和服务机同id的tom用户:
[root@localhost ~]# useradd -u 1001 tom
仅有tom用户可以查看test文件:
[root@localhost ~]# su - tom
[tom@localhost ~]$ ll /test3
total 0
[tom@localhost ~]$ touch a
[tom@localhost ~]$