搭建和配置Linux NFS(Network File System)服务需要按照以下步骤进行操作:
sudo apt-get install nfs-kernel-server (Ubuntu)
sudo yum install nfs-utils (CentOS)
/etc/exports,指定共享的目录和权限。例如,可以添加以下内容来共享/shared目录:/shared *(rw,sync,no_root_squash)
其中,/shared表示要共享的目录,*表示允许所有主机访问,rw表示读写权限,sync表示同步写入,no_root_squash表示不对root用户进行权限限制。
sudo systemctl restart nfs-kernel-server
/etc/fstab文件,添加挂载NFS共享目录的条目:server_ip:/shared /mnt/nfs nfs defaults 0 0
其中,server_ip是NFS服务器的IP地址,/shared是要共享的目录,/mnt/nfs是客户端上挂载的目录。
sudo mount -a
现在,Linux NFS服务已经搭建和配置完成,可以在NFS客户端上访问共享的NFS目录了。