题目
1、开放/nfs/shared目录,供所有用户查询资料
2、开放/nfs/upload目录,供所有用户上传下载资料
检查是否安装对应包
[root@server1 ~]# rpm -qa | grep nfs
[root@server1 ~]# rpm -qa | grep rpc
关闭防火墙和selinux
[root@server ~]# systemctl stop firewalld
[root@server ~]# setenforce 0
启动NFS服务
[root@server1 ~]# systemctl start nfs-server
开放/nfs/shared目录,供所有用户查询资料
服务端:
[root@server1~]# mkdir -pv /nfs/shared #创建共享目录
[root@server1 ~]# cd /nfs/shared/
[root@server1 shared]# touch test1 #创建共享文件
[root@server1 shared]# echo "this is a test" > /nfs/shared/test1
[root@server1 shared]# vim /etc/exports #编辑配置文件
/nfs/shared *(ro)
[root@server1 shared]# systemctl restart nfs-server.service #重新启动服务
[root@server1 shared]# showmount -e 192.168.210.129 #查看共享内容
Export list for 192.168.210.129:
/nfs/shared *
客户端:
[root@localhost ~]# showmount -e 192.168.210.129
Export list for 192.168.210.129:
/nfs/shared *
[root@localhost ~]# mkdir -pv /nfs/shared #创建存放共享文件的目录
[root@localhost ~]# mount 192.168.210.129:/nfs/shared /nfs/shared/ #把共享文件挂载到指定的共享文件目录中
[root@localhost ~]# cd /nfs/shared/
[root@localhost shared]# ll
总用量 4
-rw-r--r--. 1 root root 15 11月 24 13:20 test1
[root@localhost shared]# cat test1
this is a test
[root@localhost shared]# touch file1
touch: 无法创建 'file1': 只读文件系统
开放/nfs/upload目录,供所有用户上传下载资料
服务端:
[root@server1 ~]# mkdir -pv /nfs/upload
[root@server1 ~]# cd /nfs/upload
[root@server1 upload]# touch test1
[root@server1 upload]# ll
总用量 0
-rw-r--r--. 1 root root 0 Nov 24 13:26 test1
[root@server1 upload]# echo "my name is czc" > test1
[root@server1 upload]# vim /etc/exports
/nfs/upload 192.168.210.0/24(rw,all_squash,anonuid=1001,anongid=1001)
[root@server1 upload]# useradd -u 1001 -g 1001 nfs-upload
[root@server1 upload]# systemctl restart nfs-server.service
[root@server1 upload]# showmount -e localhost
Export list for localhost:
/nfs/upload 192.168.210.0/24
[root@server1 upload]# chmod o=rwx /nfs/upload/
[root@server1 upload]# ll
总用量 4
-rw-r--r--. 1 nfs-upload nfs-upload 0 11月 24 13:30 file
-rw-r--r--. 1 root root 16 11月 24 13:26 test1
客户端:
[root@localhost ~]# mkdir -pv /nfs/upload
[root@localhost nfs]# mount 192.168.210.129:/nfs/upload /nfs/upload/
[root@localhost upload]# cat test1
my name is czc
[root@localhost upload]# touch file
[root@localhost upload]# ll
总用量 4
-rw-r--r--. 1 1001 1001 0 11月 24 13:30 file
-rw-r--r--. 1 root root 16 11月 24 13:26 test1