欢迎来到ChAn的博客

光終會灑在小陳身上,小陳也會燦爛一場
扩大
缩小

CentOS7部署一台NFS服务器,并按以下要求配置

1、开放/nfs/shared目录,供所有用户查询资料;
2、开放/nfs/upload目录,该目录为192.168.11.0/24网段的主机的数据上传目录,并将所有该网段主机上传文件的所属者和所属组映射为nfs-upload,其UID和GID为2001;
3、将/home/tom(该目录为uid=1111,gid=1111的tom用户的家目录)目录仅共享给192.168.11.104这台主机上的jerry用户,jerry对该目录具有访问、新建和删除文件的权限。

服务端:
1、安装软件包
[root@kube-node1 ~]# yum install nfs-utils.x86_64  rpcbind.x86_64 -y

2、关闭防火墙,selinux
[root@kube-node1 ~]# systemctl stop firewalld.service
[root@kube-node1 ~]# systemctl is-active firewalld.service
inactive
[root@kube-node1 ~]# setenforce 0

3、修改exports文件
# 注意空格
[root@kube-node1 ~]# cat /etc/exports
/nfs/shared *(ro)
/nfs/upload 192.168.11.0/24(rw,all_squash,anonuid=2001,anongid=2001)
/home/tom 192.168.11.104(rw)

4、创建目录
[root@kube-node1 ~]# mkdir -p /nfs/{shared,upload}

5、创建用户和用户组
[root@kube-node1 ~]# groupadd tom -g 1111

[root@kube-node1 ~]# useradd tom -u 1111 -g 1111

[root@kube-node1 ~]# id tom
uid=1111(tom) gid=1111(tom) groups=1111(tom)

6、重启服务
[root@kube-node1 ~]# systemctl start rpcbind.service  nfs-server.service

7、查看清单
[root@kube-node1 nfs]# showmount -e 192.168.11.115
Export list for 192.168.11.115:
/nfs/shared *
/nfs/upload 192.168.11.0/24
/home/tom   192.168.11.104


8、去每个目录下创建一个文件
[root@kube-node1 ~]# cd /nfs/shared/
[root@kube-node1 shared]# echo this is file1 > file1
[root@kube-node1 shared]# ll
total 4
-rw-r--r--. 1 root root 14 Mar  7 22:01 file1


[root@kube-node1 shared]# cd /nfs/upload
upload/    uploadmul/
[root@kube-node1 shared]# cd /nfs/upload
[root@kube-node1 upload]# echo this is file2 > file2
[root@kube-node1 upload]# ll
total 4
-rw-r--r--. 1 root root 14 Mar  7 22:01 file2

[root@kube-node1 upload]# cd /home/tom/
[root@kube-node1 tom]# echo this is file3 > file3
[root@kube-node1 tom]# ll
total 4
-rw-r--r--. 1 root root 14 Mar  7 22:01 file3

9、修改权限
[root@kube-node1 tom]# cd /nfs/upload
[root@kube-node1 upload]# chmod o+w .
[root@kube-node1 upload]# cd /nfs/
[root@kube-node1 nfs]# ll
total 0
drwxr-xr-x. 2 root root 19 Mar  7 22:01 shared
drwxr-xrwx. 2 root root 19 Mar  7 22:01 upload

客户端:
1、安装软件
[root@node01 ~]# yum install nfs-utils.x86_64 rpcbind.x86_64 -y

2、创建目录文件
[root@node01 ~]# mkdir -p /client/{1,2,3}
[root@node01 ~]# cd /client/
[root@node01 client]# ll
total 0
drwxr-xr-x. 2 root root 6 Mar  8 22:04 1
drwxr-xr-x. 2 root root 6 Mar  8 22:04 2
drwxr-xr-x. 2 root root 6 Mar  8 22:04 3

3、挂载目录
[root@node01 client]# mount -t nfs 192.168.11.115:/nfs/shared  /client/1
[root@node01 client]# mount -t nfs 192.168.11.115:/nfs/upload  /client/2
[root@node01 client]# mount -t nfs 192.168.11.115:/home/tom  /client/3

4、查询nfs服务的输出清单
[root@node01 client]# showmount -e 192.168.11.115
Export list for 192.168.11.115:
/nfs/shared *
/nfs/upload 192.168.11.0/24
/home/tom   192.168.11.104

5、创建用户和用户组
[root@node01 client]# groupadd nfs-upload -g 2001
[root@node01 client]# useradd nfs-upload -u 2001 -g 2001
[root@node01 client]# useradd jerry -u 1111
[root@node01 client]# id nfs-upload
uid=2001(nfs-upload) gid=2001(nfs-upload) groups=2001(nfs-upload)
[root@node01 client]# id jerry
uid=1111(jerry) gid=1111(jerry) groups=1111(jerry)

测试:
目录1:
[root@node01 client]# cd 1
[root@node01 1]#
[root@node01 1]# ll
total 4
-rw-r--r--. 1 root root 14 Mar  7 22:01 file1
[root@node01 1]# cat file1
this is file1

目录2:
客户端:
[root@node01 1]# cd  /client/2/
# 里面原来一个文件
[root@node01 2]# ll
total 4
-rw-r--r--. 1 root root 14 Mar  7 22:01 file2

#创建一个文件
[root@node01 2]# touch file-nfs
[root@node01 2]# ll
total 4
-rw-r--r--. 1 root       root       14 Mar  7 22:01 file2
-rw-r--r--. 1 nfs-upload nfs-upload  0 Mar  7 22:16 file-nfs

#删除原来的file2文件,在服务端看效果
[root@node01 2]# rm -rf file2
[root@node01 2]# ll
total 0
-rw-r--r--. 1 nfs-upload nfs-upload 0 Mar  7 22:16 file-nfs

服务端:
[root@kube-node1 nfs]# cd /nfs/upload/
[root@kube-node1 upload]# ll
total 0
-rw-r--r--. 1 2001 2001 0 Mar  7 22:16 file-nfs

目录3:
客户端:
#切换到jerry
[root@node01 ~]# su - jerry
[jerry@node01 ~]$
[jerry@node01 ~]$ cd /client/3/

#原来只有一个文件
[jerry@node01 3]$ ll
total 4
-rw-r--r--. 1 root root 14 Mar  7 22:01 file3
[jerry@node01 3]$ cat file3
this is file3

#创建一个文件
[jerry@node01 3]$ touch file3-jerry
[jerry@node01 3]$ ll
total 4
-rw-r--r--. 1 root  root  14 Mar  7 22:01 file3
-rw-rw-r--. 1 jerry jerry  0 Mar  7 22:20 file3-jerry
#删除一个文件,服务端看效果
[jerry@node01 3]$ rm -rf file3
[jerry@node01 3]$ ll
total 0
-rw-rw-r--. 1 jerry jerry 0 Mar  7 22:20 file3-jerry

服务端:
[root@kube-node1 upload]# cd /home/tom/
[root@kube-node1 tom]# ll
total 0
-rw-rw-r--. 1 tom tom 0 Mar  7 22:20 file3-jerry

posted on 2023-03-07 22:49  ChAnAn  阅读(42)  评论(0编辑  收藏  举报

导航