在 CentOS 上 mount 远程目录,常见有几种方式,最常用的是 NFS 和 SSHFS,下面分别说。
# 安装
yum install -y nfs-utils
# 启动服务
systemctl enable --now nfs-server
# 创建共享目录
mkdir -p /data/share
# 配置共享
vi /etc/exports
加入:
/data/share 192.168.1.0/24(rw,sync,no_root_squash)
# 生效
exportfs -r
yum install -y nfs-utils
mkdir -p /mnt/remote
mount -t nfs 192.168.1.100:/data/share /mnt/remote
✅ 测试:
df -h
ls /mnt/remote
开机自动挂载:
vi /etc/fstab
192.168.1.100:/data/share /mnt/remote nfs defaults 0 0
适合 临时挂载 / 跨公网
yum install -y epel-release
yum install -y sshfs
mkdir -p /mnt/sshremote
sshfs user@remote_ip:/remote/path /mnt/sshremote
卸载:
fusermount -u /mnt/sshremote
yum install -y cifs-utils
mount -t cifs //192.168.1.100/share /mnt/smb \
-o username=xxx,password=xxx
No route to host → 防火墙 / 网络问题nfs-server 是否启动如果你告诉我:
我可以直接给你一套完整命令。