centos7--NFS共享服务

#关闭防火墙和selinux
[root@ c7-41 ~] systemctl stop firewalld
[root@ c7-41 ~] setenforce 0

1,在主机A 服务端安装nfs-utils,rpcbind,提供NFS共享的服务为nfs

[root@ c7-41 ~] yum -y install nfs-utils rpcbind
[root@ c7-41 ~] systemctl enable nfs rpcbind #添加开机自启

2,设置共享目录,NFS的配置文件为/etc/exports,文件内容默认为空(无任何共享),在exports文件中设置共享资源时,记录格式为:”目录位置 客户机地址(权限选项)”

[root@ c7-41 ~] mkdir -p /data
[root@ c7-41 ~] vim /etc/exports
[root@ c7-41 ~] cat /etc/exports
/data/	10.0.0.0/24(rw,sync,no_root_squash,no_all_squash)

# /data: 共享目录位置
# 10.0.0.0/24: 客户端 IP 范围,* 代表所有,即没有限制
# rw: 权限设置,可读可写
# sync: 同步共享目录
# no_root_squash: 可以使用 root 授权
# no_all_squash: 可以使用普通用户授权

3,启动nfs服务,先启动rpcbind,后启动nfs

[root@ c7-41 ~] systemctl start rpcbind.service 
[root@ c7-41 ~] systemctl start nfs
[root@ c7-41 ~] showmount -e #查看本机NFS共享目录
Export list for c7-41:
/data 10.0.0.0/24

4,在主机B 客户端安装nfs,添加开机自启,并启动

[root@ c7-42 ~] yum -y install nfs-utils rpcbind
[root@ c7-42 ~] systemctl enable rpcbind
[root@ c7-42 ~] systemctl start rpcbind
#客户端不安装nfs-utils则不能挂载nfs共享目录;但可以不开启

5,查看NFS服务器端共享目录,并手动挂载NFS共享目录

[root@ c7-42 ~] showmount -e 10.0.0.41
Export list for 10.0.0.41:
/data 10.0.0.0/24
#挂载NFS
[root@ c7-42 ~] mount 10.0.0.41:/data /var/www/html/

6,查看挂载结果

[root@ c7-42 ~] tail -1 /etc/mtab 
10.0.0.41:/data /var/www/html nfs4 rw,relatime,vers=4.1,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=10.0.0.42,local_lock=none,addr=10.0.0.41 0 0

7,进行测试

#在客户端安装httpd服务
[root@ c7-42 ~] yum -y install httpd
[root@ c7-42 ~] systemctl start httpd # 启动httpd
#在主机A 服务端写入测试页
[root@ c7-41 ~] vim /data/index.html
[root@ c7-41 ~] cat /data/index.html 
<h1>what are you doing?</h1>

在web端查看
在这里插入图片描述

发布了56 篇原创文章 · 获赞 65 · 访问量 1983

猜你喜欢

转载自blog.csdn.net/xiaohuai0444167/article/details/105644229