1、开放/nfs/shared目录,供所有用户查询资料;
#客户端和服务端都需要安装相应的软件包:
[root@localhost ~]# yum install -y nfs-utils
[root@localhost ~]# yum install -y rpcbind
服务端:
#服务端:
[root@localhost ~]# systemctl stop firewalld.service #关闭防火墙
[root@localhost ~]# setenforce 0 #关闭SELinux
[root@localhost ~]# mkdir -pv
[root@localhost ~]# mkdir -pv /nfs/shared #创建共享目录
[root@localhost shared]# touch test1 #创建共享文件
[root@localhost shared]# echo "this is a test" > /nfs/shared/test1
[root@localhost shared]# vim /etc/exports #编辑配置文件
/nfs/shared *(ro)
[root@localhost shared]# systemctl restart nfs-server.service #重新启动服务
[root@localhost shared]# showmount -e 192.168.76.132 #查看共享内容
Export list for 192.168.76.132:
/nfs/shared *
客户端:
[root@localhost ~]# showmount -e 192.168.76.132
Export list for 192.168.76.132:
/nfs/shared *
[root@localhost ~]# mkdir -pv /nfs/shared #创建存放共享文件的目录
[root@localhost ~]# mount 192.168.76.132:/nfs/shared /nfs/shared/ #把共享文件挂载到指定的共享文件目录中
[root@localhost ~]# cd /nfs/shared/
[root@localhost shared]# ll
总用量 4
-rw-r--r--. 1 root root 15 11月 16 17:05 test1
[root@localhost shared]# cat test1
this is a test
[root@localhost shared]# touch file1
touch: 无法创建 'file1': 只读文件系统
2、开放/nfs/upload目录,该目录为192.168.76.0/24网段的主机的数据上传目录,并将所有该网段主机上
传文件的所属者和所属组映射为nfs-upload,其UID和GID为2001;
服务端:
[root@localhost ~]# mkdir -pv /nfs/upload
[root@localhost upload]# touch test1
[root@localhost upload]# ll
总用量 0
-rw-r--r--. 1 root root 0 11月 16 18:21 test1
[root@localhost upload]# echo "my name is jeff" > test1
[root@localhost upload]# vim /etc/exports
/nfs/upload 192.168.76.0/24(rw,all_squash,anonuid=2001,anongid=2001)
[root@localhost upload]# useradd -u 2001 nfs-upload
[root@localhost upload]# systemctl restart nfs-server.service
[root@localhost upload]# showmount -e localhost
Export list for localhost:
/nfs/upload 192.168.76.0/24
[root@localhost upload]# chmod o=rwx /nfs/upload/
[root@localhost upload]# ll
总用量 4
-rw-r--r--. 1 nfs-upload nfs-upload 0 11月 16 18:26 file
-rw-r--r--. 1 root root 16 11月 16 18:21 test1
客户端:
[root@localhost ~]# mkdir -pv /nfs/upload
[root@localhost nfs]# mount 192.168.76.132:/nfs/upload /nfs/upload/
[root@localhost upload]# cat test1
my name is jeff
[root@localhost upload]# touch file
[root@localhost upload]# ll
总用量 4
-rw-r--r--. 1 2001 2001 0 11月 16 18:26 file
-rw-r--r--. 1 root root 16 11月 16 18:21 test1