要在两台Linux电脑上共享一个目录,最简单的方式是使用NFS,将一台电脑的目录映射到另一台。

安装nfs-server nfs-common

apt-get -y install nfs-common nfs-kernel-server
mkdir /mnt/nfshare
chmod 777 /mnt/nfshare
echo "/mnt/nfshare 192.168.1.0/24(rw,no_root_squash,insecure,sync)" > /etc/exports
#unraid
"/mnt/disk0" -fsid=108,async,no_subtree_check 192.168.1.0/24(rw,sync,all_squash,anonuid=65535,anongid=65534)
#debian
# /etc/exports: the access control list for filesystems which may be exported                                                                                
#   to NFS clients.  See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes       hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4        gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes  gss/krb5i(rw,sync,no_subtree_check)
#

"/mnt/disk0" 192.168.1.100/32(rw,sync,no_subtree_check,all_squash,anonuid=65534,anongid=65534)

启动服务:

systemctl restart nfs-server
showmount -e localhost

在另外一台 服务器 安装NFS客户端:

apt-get -y install nfs-common

创建目录并挂载NFS:

mkdir /mnt/disk0
mount 192.168.1.99:/mnt/nfshare /mnt/disk0

要在客户端每次启动时自动挂载NFS,可以编辑/etc/fstab,添加一行:

192.168.1.99:/mnt/nfshare /mnt/disk0 nfs rsize=8192,wsize=8192,timeo=14,intr
mount -t nfs -o noatime,nodiratime,nodev,noexec,rsize=131072,wsize=131072 -o tcp 192.168.10.9:/mnt/user/webfiles /mnt/webfiles

均为缺省参数。