NFS服务器简单习题

1、开放/nfs/shared目录,供所有用户查询资料;

#在服务端和客户端安装rpcbind包和nfs-utils包
[root@mm yum.repos.d]# yum install rpcbind -y
[root@mm yum.repos.d]# yum install nfs-utils -y
#在服务端创建/nfs/shared目录并创建实验文件
[root@server ~]# mkdir -p /nfs/shared
[root@server ~]# cd /nfs
[root@server nfs]# ll
total 0
drwxr-xr-x. 2 root root 6 Nov 17 16:20 shared
[root@server shared]# echo "haha" > /nfs/shared/file.txt
[root@server shared]# ll
total 4
-rw-r--r--. 1 root root 5 Nov 17 17:03 file.txt
[root@server shared]# cat file.txt
haha

[root@server shared]# vim /etc/exports
#在/etc/exports文件中配置如下代码
/nfs/shared  192.168.10.130(ro)
#退出后重启rpcbind、nfs-server服务,同时检查防火墙是否关闭,SElinux是否阻碍服务正常运行
[root@server shared]# systemctl restart rpcbind nfs-server
[root@server nfs]# systemctl status firewalld
[root@server nfs]# systemctl stop firewalld
[root@server nfs]# getenforce
Enforcing
[root@server nfs]# setenforce 0
[root@server nfs]# getenforce
Permissive
#访问服务端自己,查看是否配置成功。
[root@server nfs]# showmount -e 192.168.10.129
Export list for 192.168.10.129:
/nfs/shared 192.168.10.130
#检测服务是否成功
[root@mm yum.repos.d]# showmount -e 192.168.10.130
Export list for 192.168.10.130:
#创建文件用于存放查询的服务端文件
[root@mm yum.repos.d]# mkdir /nfsclient
[root@mm nfsclient]# mkdir shared
[root@mm nfsclient]# ll
total 0
drwxr-xr-x. 2 root root 6 Nov 17 16:57 shared
#挂载服务端共享文件到客户端/nfsclient/shared中
[root@mm nfsclient]# mount 192.168.10.129:/nfs/shared  /nfsclient/shared
[root@mm nfsclient]# cd shared/
[root@mm shared]# ll
total 4
-rw-r--r--. 1 root root 5 Nov 17 17:03 file.txt
#检测用户对文件权限,只能查看,并无创建编写的权限
[root@mm shared]# cat file.txt
haha
[root@mm shared]# touch file
touch: cannot touch 'file': Read-only file system

2、开放/nfs/upload目录,供所有用户上传下载资料;
同上述步骤:

#在/nfs创建upload目录
[root@server nfs]# echo this is upload > /nfs/upload/upload
[root@server nfs]# tree
.
├── shared
│   └── file.txt
└── upload
    └── upload

2 directories, 2 files
[root@server nfs]# cat upload/upload
this is upload
#在/etc/exports文件下配置如下命令:
[root@server nfs]#  vi /etc/exports
/nfs/shared  *(ro)
/nfs/upload  *(rw)
#检查防火墙,SElinux状态并重启nfs服务:
[root@server nfs]# systemctl restart nfs-server
[root@server nfs]# showmount -e 192.168.10.123
Export list for 192.168.10.123:
/nfs/upload *
/nfs/shared *
```bash
#创建upload目录,并挂载服务端/nfs/upload:
[root@mm yum.repos.d]# cd /nfsclient
[root@mm nfsclient]# mkdir -p upload
[root@mm nfsclient]# mount 192.168.10.123:/nfs/upload /nfsclient/upload/
[root@mm nfsclient]# tree
.
├── shared
│   └── file.txt
└── upload
    └── upload

2 directories, 2 files

#在服务端修改upload/权限:
[root@server nfs]# cd /nfs
[root@server nfs]# ll
total 0
drwxr-xr-x. 2 root root 22 Nov 17 17:03 shared
drwxr-xr-x. 2 root root 20 Nov 23 16:14 upload
[root@server nfs]# chmod o+w upload/

#检验能否在客户端的/nfsclient/upload目录下创建文件
[root@mm upload]# touch file
[root@mm upload]# ll
total 4
-rw-r--r--. 1 nobody nobody  0 Nov 23 17:17 file
-rw-r--r--. 1 root   root   15 Nov 23 16:14 upload


 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值