NFS磁盘共享
步骤:
注意事项:确保服务端防火墙关闭,或者允许2049端口通信,客户端需具备读写权限。
服务器端
安装NFS服务器:
sudo apt-get install nfs-kernel-server # Debian/Ubuntu
sudo yum install nfs-utils # CentOS/RHEL
配置NFS导出:
编辑/etc/exports文件,添加要共享的目录和客户端权限。例如:
/path/to/share *(rw,sync,no_subtree_check)
启动NFS服务并使能开机启动:
sudo systemctl start nfs-server
sudo systemctl enable nfs-server
客户端
在客户端安装NFS客户端:
sudo apt-get install nfs-common # Debian/Ubuntu
sudo yum install nfs-utils # CentOS/RHEL
挂载NFS共享:
sudo mount -t nfs server_ip:/path/to/share /local/mount/point
------------------例:
NFS服务端
在服务端安装nfs-utils和rpcbind:
sudo yum install nfs-utils rpcbind
sudo systemctl start rpcbind
sudo systemctl enable rpcbind
sudo systemctl start nfs-server
sudo systemctl enable nfs-server
配置共享目录:编辑/etc/exports文件,添加共享路径及权限配置
/data/shared 192.168.1.100(rw,sync,no_root_squash)
重新加载NFS服务:
sudo exportfs -ra
NFS客户端
在客户端安装nfs-utils:
sudo yum install nfs-utils
挂载共享目录:
sudo mount -t nfs 192.168.1.100:/data/shared /mnt/nfs_share
设置自动挂载(可选):编辑/etc/fstab文件:
192.168.1.100:/data/shared /mnt/nfs_share nfs defaults 0 0。