「Linux」- 搭建 NFS 服务(Ubuntu、CentOS、Debian)

  CREATED BY JENKINSBOT

问题描述

该笔记将记录:在 Linux 中,如何快速部署 NFS 服务,并配置访问,以及常见问题的解决办法;

解决方案

系统环境:Debian,Ubuntu,CentOS
ClearOS release 7.5.0 (Final) | nfs-utils 1.3.0
CentOS release 6.5 (Final) | nfs-utils-1.2.3-75.el6_9.x86_64 | nfs-utils-lib-1.1.5-13.el6.x86_64

第一步、部署服务

执行如下命令,以安装 NFS 服务端:

### NFS 1.3.4 on Ubuntu 18.04 LTS
apt install nfs-kernel-server
systemctl enable nfs-kernel-server.serivce
systemctl start nfs-kernel-server.serivce

### NFS 1.3.0 on ClearOS 7.5
yum install -y nfs-utils nfs-utils-lib
systemctl start nfs-server.service
systemctl enable nfs-server.service

### NFS 1.2.3 on CentOS 6.5
yum install -y nfs-utils nfs-utils-lib
chkconfig nfs on
chkconfig rpcbind on
service rpcbind start
service nfs start

第二步、导出文件系统

添加共享目录,如下示例:

# 导出目录
# 建议使用系统提供的“配置文件引入”方式,而非直接修改 /etc/exports 文件
# 建议使用地址替换星号(*),以限制访问,防止不期望的主机访问 NFS 服务;
cat > /etc/exports.d/foo.exports <<EOF
/home               10.10.50.0/24(rw,sync,no_subtree_check,no_root_squash)
EOF

# 配置重新加载,而无需重启
exportfs -a -r                                                                  

# 查看导出目录
showmount -e 127.0.0.1                                                          

第三步、访问文件系统

在客户端或远程主机中,挂载 NFS 文件系统:

yum install -y nfs-utils

mount -t nfs nfs-server-ip-address:/home

参考文献

How to Install and Configure an NFS Server on Ubuntu 18.04
How To Set Up an NFS Mount on CentOS 6
mount – NFS Server changes in /etc/exports file need Service Restart? – Unix & Linux Stack Exchange
Network File System (NFS)
NFS Server changes in /etc/exports file need Service Restart?
NFS share access – Permission denied – Super User
SettingUpNFSHowTo