NotePublic/Software/Applications/NFS/NFS_服务安装和配置.md

87 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# NFS 服务安装和配置
## 安装
```bash
# Ubuntu
sudo apt-get install nfs-kernel-server
sudo apt-get install nfs-common
# Manjaro
sudo pacman -S nfs-utils
```
## 配置
```bash
sudo vim /etc/exports
```
在该文件末尾添加下面的一行:
```ini
<NFS share dir> *(rw,sync,no_root_squash,no_subtree_check) # * 表示允许任何网段 IP 的系统访问该 NFS 目录
```
新建“\<NFS share dir\>”目录,并为该目录设置最宽松的权限:
```bash
sudo mkdir <NFS share dir>
# -R 表示递归更改该目录下所有文件
sudo chmod -R 777 <NFS share dir>
sudo chown <usr>:<group> <NFS share dir> -R
```
如果修改了 exports 文件需要通过以下命令使修改生效:
```bash
sudo exportfs -arv
```
## 使能/启动 NFS 服务
```bash
# Ubuntu
sudo systemctl enable nfs-kernel-server
sudo systemctl start nfs-kernel-server
# Manjaro
sudo systemctl enable nfs-server
sudo systemctl start nfs-server
```
## 停止/禁用 NFS 服务
```bash
# Ubuntu
sudo systemctl stop nfs-kernel-server
sudo systemctl disable nfs-kernel-server
# Manjaro
sudo systemctl stop nfs-server
sudo systemctl disable nfs-server
```
## 防火墙配置
```bash
firewall-cmd --permanent --zone public --add-service mountd
firewall-cmd --permanent --zone public --add-service rpc-bind
firewall-cmd --permanent --zone public --add-service nfs
firewall-cmd --reload
```
## 挂载 NFS 文件系统
```bash
sudo mount -t nfs <nfs server ip>:<NFS share dir> <mount point> -o nolock
```
## 查看状态
```bash
# 查看NFS的运行状态
sudo nfsstat
# 查看rpc执行信息可以用于检测rpc运行情况
sudo rpcinfo
# 在服务端查看哪些客户访问过哪些 NFS 目录
showmount -a
```