目的:服务器Ubuntu 挂载 服务器 Centos
实现:重启 Ubuntu 能够自启远程挂载 Centos
cd /data #到写脚本的目录下
vim auto_mount.sh #配置 自动挂载 的脚本
chmod +x auto_mount.sh #必须有 x 权限,才能够执行
auto_mout.sh 脚本如下:
#!/bin/sh #第一行必须说明解释器
sshfs -o ssh_command='sshpass -p 12345abc ssh' -o cache=yes,allow_other -o StrictHostKeyChecking=no user@hostname:/远程需要挂载的路径 /本服务器需要挂载的路径
参数了解:
-o transform_symlinks 表示转换绝对链接符号为相对链接符号
-o follow_symlinks 沿用服务器上的链接符号
-C 压缩,或者-o compression=yes
-o reconnect 自动重连
-o cache=yes
-o allow_other
在单独执行此脚本时,必须加上路径如下:
/data/auto_mount.sh
为了能够重启服务器后可以自动启用 auto_mount.sh 这个挂载脚本,需要去修改的/etc/rc.local文件
vim /etc/rc.local
rc,local 文件内容如下:
#!/bin/sh #第一行必须说明解释器
/data/auto_mount.sh #脚本的绝对路径
修改完成后,记得给 rc.local 加 x 权限,对于新的服务器里面是没有 rc.local 文件的
chmod +x /etc/rc.local
reboot重启后就可以,自动挂载了