在 Linux 上安装 NFS (Network File System) 可以分为以下几个步骤:
1. 安装 NFS 服务端软件包:
- 在 CentOS/RHEL 上, 运行 `yum install nfs-utils` 来安装.
- 在 Ubuntu/Debian 上, 运行 `apt-get install nfs-kernel-server` 来安装.
2. 配置 NFS 服务:
- 编辑 `/etc/exports` 文件, 添加共享目录和访问权限. 例如:
```
/share 192.168.1.0/24(rw,sync,no_root_squash)
```
这将共享 `/share` 目录, 允许 `192.168.1.0/24` 网段内的客户端读写访问, 并且客户端 root 用户也拥有 root 权限.
3. 启动 NFS 服务:
- 在 CentOS/RHEL 上, 运行 `systemctl start nfs-server` 来启动 NFS 服务.
- 在 Ubuntu/Debian 上, 运行 `systemctl start nfs-kernel-server` 来启动 NFS 服务.
4. 设置开机自启动:
- 在 CentOS/RHEL 上, 运行 `systemctl enable nfs-server` 来设置 NFS 服务开机自启动.
- 在 Ubuntu/Debian 上, 运行 `systemctl enable nfs-kernel-server` 来设置 NFS 服务开机自启动.
5. 在客户端挂载 NFS 共享目录:
- 在客户端运行 `mount -t nfs 服务器IP:/共享目录 /客户端挂载目录` 来挂载 NFS 共享目录.
- 例如: `mount -t nfs 192.168.1.100:/share /mnt/nfs`
完成以上步骤后, 客户端就可以访问 NFS 共享目录了. 如果需要自动挂载,可以在客户端的 `/etc/fstab` 文件中添加相应的挂载项.