2020-04-17 13:52:26 +08:00
|
|
|
|
# NFS 服务安装和配置
|
|
|
|
|
|
2020-12-10 21:05:20 +08:00
|
|
|
|
## 1.安装
|
2020-04-17 13:52:26 +08:00
|
|
|
|
|
2020-05-20 16:18:39 +08:00
|
|
|
|
```bash
|
2020-04-17 13:52:26 +08:00
|
|
|
|
# Ubuntu
|
|
|
|
|
sudo apt-get install nfs-kernel-server
|
|
|
|
|
sudo apt-get install nfs-common
|
2020-05-11 15:48:07 +08:00
|
|
|
|
# Manjaro
|
|
|
|
|
sudo pacman -S nfs-utils
|
2020-04-17 13:52:26 +08:00
|
|
|
|
```
|
|
|
|
|
|
2020-12-10 21:05:20 +08:00
|
|
|
|
## 2.配置
|
2020-04-17 13:52:26 +08:00
|
|
|
|
|
2020-05-20 16:18:39 +08:00
|
|
|
|
```bash
|
2020-04-17 13:52:26 +08:00
|
|
|
|
sudo vim /etc/exports
|
|
|
|
|
```
|
|
|
|
|
|
2020-05-11 15:48:07 +08:00
|
|
|
|
在该文件末尾添加下面的一行:
|
2020-04-17 13:52:26 +08:00
|
|
|
|
|
2020-05-20 16:18:39 +08:00
|
|
|
|
```ini
|
2020-05-11 15:48:07 +08:00
|
|
|
|
<NFS share dir> *(rw,sync,no_root_squash,no_subtree_check) # * 表示允许任何网段 IP 的系统访问该 NFS 目录
|
2020-04-17 13:52:26 +08:00
|
|
|
|
```
|
|
|
|
|
|
2020-05-11 15:48:07 +08:00
|
|
|
|
新建“\<NFS share dir\>”目录,并为该目录设置最宽松的权限:
|
2020-04-17 13:52:26 +08:00
|
|
|
|
|
2020-05-20 16:18:39 +08:00
|
|
|
|
```bash
|
2020-05-11 15:48:07 +08:00
|
|
|
|
sudo mkdir <NFS share dir>
|
2020-04-17 13:52:26 +08:00
|
|
|
|
# -R 表示递归更改该目录下所有文件
|
2020-05-11 15:48:07 +08:00
|
|
|
|
sudo chmod -R 777 <NFS share dir>
|
|
|
|
|
sudo chown <usr>:<group> <NFS share dir> -R
|
2020-04-17 13:52:26 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
如果修改了 exports 文件需要通过以下命令使修改生效:
|
|
|
|
|
|
2020-05-20 16:18:39 +08:00
|
|
|
|
```bash
|
2020-05-11 15:48:07 +08:00
|
|
|
|
sudo exportfs -arv
|
2020-04-17 13:52:26 +08:00
|
|
|
|
```
|
|
|
|
|
|
2020-12-10 21:05:20 +08:00
|
|
|
|
## 3.使能/启动 NFS 服务
|
2020-04-17 13:52:26 +08:00
|
|
|
|
|
2020-05-20 16:18:39 +08:00
|
|
|
|
```bash
|
2020-05-11 15:48:07 +08:00
|
|
|
|
# Ubuntu
|
2020-04-17 13:52:26 +08:00
|
|
|
|
sudo systemctl enable nfs-kernel-server
|
|
|
|
|
sudo systemctl start nfs-kernel-server
|
2020-05-11 15:48:07 +08:00
|
|
|
|
# Manjaro
|
|
|
|
|
sudo systemctl enable nfs-server
|
|
|
|
|
sudo systemctl start nfs-server
|
2020-04-17 13:52:26 +08:00
|
|
|
|
```
|
|
|
|
|
|
2020-12-10 21:05:20 +08:00
|
|
|
|
## 4.停止/禁用 NFS 服务
|
2020-04-17 13:52:26 +08:00
|
|
|
|
|
2020-05-20 16:18:39 +08:00
|
|
|
|
```bash
|
2020-05-11 15:48:07 +08:00
|
|
|
|
# Ubuntu
|
2020-04-17 13:52:26 +08:00
|
|
|
|
sudo systemctl stop nfs-kernel-server
|
|
|
|
|
sudo systemctl disable nfs-kernel-server
|
2020-05-11 15:48:07 +08:00
|
|
|
|
# Manjaro
|
|
|
|
|
sudo systemctl stop nfs-server
|
|
|
|
|
sudo systemctl disable nfs-server
|
2020-04-17 13:52:26 +08:00
|
|
|
|
```
|
|
|
|
|
|
2020-12-10 21:05:20 +08:00
|
|
|
|
## 5.防火墙配置
|
2020-05-30 09:36:22 +08:00
|
|
|
|
|
2020-07-09 10:54:40 +08:00
|
|
|
|
```bash
|
2020-05-30 09:36:22 +08:00
|
|
|
|
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
|
|
|
|
|
```
|
|
|
|
|
|
2020-12-10 21:05:20 +08:00
|
|
|
|
## 6.挂载 NFS 文件系统
|
|
|
|
|
|
|
|
|
|
### 6.1.Linux 下挂载 NFS
|
2020-04-17 13:52:26 +08:00
|
|
|
|
|
2020-05-20 16:18:39 +08:00
|
|
|
|
```bash
|
2020-05-11 15:48:07 +08:00
|
|
|
|
sudo mount -t nfs <nfs server ip>:<NFS share dir> <mount point> -o nolock
|
2020-04-17 13:52:26 +08:00
|
|
|
|
```
|
|
|
|
|
|
2020-12-10 21:05:20 +08:00
|
|
|
|
### 6.2.Windows 下挂载 NFS
|
|
|
|
|
|
|
|
|
|
打开“控制面板->程序->打开或关闭 Windows 功能”,勾选“NFS 服务->NFS 客户端”和“NFS 服务->管理工具”。
|
|
|
|
|
|
|
|
|
|
由于字体编码问题,NFS 中的中文字符可能乱码,如果是 Win10 系统可打开“控制面板->时钟和区域->区域->管理->更改系统区域设置”,勾选“Beta 版:使用 Unicode UTF-8 提供全球语言支持”。然后重启系统。
|
|
|
|
|
|
|
|
|
|
在 Windows CMD 中使用下列命令即可挂载 NFS 到指定盘符上。
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
mount \\<IP or host name>\<NFS share dir> <mount point>
|
|
|
|
|
# 如
|
|
|
|
|
mount \\192.168.1.100\home\share x:\
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 7.查看状态
|
2020-04-17 13:52:26 +08:00
|
|
|
|
|
2020-05-20 16:18:39 +08:00
|
|
|
|
```bash
|
2020-04-17 13:52:26 +08:00
|
|
|
|
# 查看NFS的运行状态
|
|
|
|
|
sudo nfsstat
|
|
|
|
|
# 查看rpc执行信息,可以用于检测rpc运行情况
|
|
|
|
|
sudo rpcinfo
|
2020-05-11 16:13:53 +08:00
|
|
|
|
# 在服务端查看哪些客户访问过哪些 NFS 目录
|
|
|
|
|
showmount -a
|
2020-04-17 13:52:26 +08:00
|
|
|
|
```
|