AppServer/

在 CentOS 上实现 nfs 共享

发布
更新
字数
364
阅读
1 分钟

最近收到一个需求,需要在 CentOS 上实现服务器端和客户端。大致的研究了一下,做个笔记如下。
首先在服务器端安装 nfs 。

bash
yum install nfs-utils rpcbind
# 将 nfs 和 rpcbind 加入自启动并启动
chkconfig nfs-server on
chkconfig rpcbind on
service nfs-server start
service rpcbind start
# 将 nfs 从防火墙中放开
firewall-cmd --permanent --zone=public --add-service=nfs
firewall-cmd --permanent --zone=public --add-service=rpc-bind
firewall-cmd --permanent --zone=public --add-service=mountd
firewall-cmd --reload

然后编辑 /etc/exports 文件,如下:

bash
/home/nfs_folder 192.168.1.100(rw,sync,no_root_squash,no_subtree_check,anonuid=65534,anongid=65534)
参数说明
rw/ro这个目录是可读写还是只读。
sync/asyncsync 指数据会同步写入内存和硬盘中;async 指数据会先暂存在内存中,并没有直接写入硬盘。
no_root_squash/root_squash客户端使用 nfs 帐号的时候如果为 root ,那么使用 root_squash 的话,就会转为 nfsnobody ,这样会比较安全。但如果一定要用 root 身份的话,就要使用 no_root_squash 了。
all_squash无论使用什么用户的话,都会转为 nfsnobody 了。
anonuid/anongid这个是用于指定上面关于 *_squash 的匿名用户的设置,默认为 nfsnobody ,也可以自己定义一个用户的 uid 和 gid 。

修改过 /etc/exports 文件后,可以使用

bash
exportfs -a

来使配置生效。

在客户端这边,可以在 /etc/fstab 中加入如下行调用 nfs 的共享:

bash
192.168.1.1:/home/nfs_folder /data nfs defaults 0 2

评论

正在载入评论…

留下评论

人机验证
四位数字,看不清可点击图片刷新

评论经审核后显示。

回到顶部 ↑