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端查看
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值