centos7配置nfs共享存储服务

参考了:https://www.cnblogs.com/newcaoguo/p/5938556.html      nfs服务的安装与配置

              https://blog.csdn.net/weixin_42502742/article/details/80887120     nfs 目录映射与docker

              https://unix.stackexchange.com/questions/319848/nfs-mount-cant-find-file-in-etc-fstab   解决:mount: can't find /nfs in /etc/fstab的问题

 

nfs 是一种网络文件系统,需要依赖rpc进行过程调度

注意:nfs只验证id和用户名,并且只能在类unix os上进行文件共享服务,由于它的脆弱的验证机制,所以不适宜在internet上工作,在内网使用是非常可行的。

nfs服务端需要确定这两个包正确安装 nfs-utils rpcbind

若是ubuntu服务器,则是nfs-common,nfs-kernel-server两个包,rpcbind是默认安装的。

yum -y install nfs-utils rpcbind

编辑共享目录配置文件 /etc/exports

/var/www/html  192.168.10.0/24(rw,async,no_root_squash)  192.168.20.0/24(ro)
#多个网段或主机之间用空格分开

/var/www    192.168.10.0/24(insecure,ro,sync,root_squash)
/var/www    *(insecure,rw,async,no_root_squash)    #添加,不然会报错

参数:ro表示只读,rw表示可读写,sync同步写(即同时写入内存和硬盘),async异步(暂存于内存),no_root_squash表示如果客户端连接过来的用户是root,则对服务端的目录同样是root权限(请不要开启,好危险的),root_squash表示客户端是root则将其转为匿名用户的权限(建议开启),加入 insecure 选项,secure 选项要求mount客户端请求源端口小于1024(然而在使用 NAT 网络地址转换时端口一般总是大于1024的),默认情况下是开启这个选项的,如果要禁止这个选项,则使用 insecure 标识

启动nfs服务,并设为开机自启动

service rpcbind start		#或则 systemctl start rpcbind
service nfs start		#或则 systemctl start nfs
######ubuntu服务器则是 service startnfs-kernel-server start
chkconfig rpcbind on		#或则 systemctl enable rpcbind
chkconfig nfs on		#或则 systemctl enable nfs

配置防火墙,放行响应端口或服务(这一步可以忽略)

firewall-cmd --permanent --add-service=nfs
firewall-cmd --permanent --add-service=rpc-bind
firewall-cmd --permanent --add-service=mountd
firewall-cmd --reload
firewall-cmd --list-all		#查看firewalld方向的资源

客户端挂载

showmount -e nfs_server_ip: 查看nfs服务端的可用挂载点

客户端挂载操作

mount -t nfs nfs_server:/var/www/html  /bendikongmulu
或者
mount -t nfs nfs_server:/var/www/html  /bendikongmulu -o proto=tcp

无报错便成功,当然客户端可以使用 df -h 来查看是否挂载过来了;这里客户端切换到本地挂载点便可以看见服务端的文件了(注意若,服务端共享的目录为空,客户端是无法查看的)

客户端卸载操作

umount -t nfs -v /bendikongmulu   
#/bendikongmulu umounted  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

戴国进

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值