使用CurlFtpFS挂载远程FTP和开机启动的方法
使用CurlFtpFS挂载远程FTP和开机启动的方法
此次安装的系统为Ubuntu 18
apt-get install curlftpfs
创建本地挂载路径
mkdir /mnt/demodomainftp
一条命令挂在远程FTP到本地的/mnt/demodomainftp目录
curlftpfs domainip /mnt/demodomainftp -o user=username:password,allow_other
创建开机挂在远程FTP目录
curlftpfs#USER:[email protected] /mnt/demodomainftp fuse auto,user,uid=1000,allow_other,_netdev 0 0
使用下面命令测试开机挂载是否报错
mount -a
如果没有错误就不会显示任何信息,否则就会出现报错,比如本次报错信息如下
Error connecting to ftp: Port number ended with 'w'
因为没有时间去排错了,所以为了高效省时,可以使用下面第二种方法实现CurlFtpFS开机挂载远程FTP
添加下面代码到/lib/systemd/system/rc.local.service
1
2
3
[Install]
WantedBy=multi-user.target
Alias=rc-local.service
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[Unit]
Description=/etc/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.local
After=network.target
[Install]
WantedBy=multi-user.target
Alias=rc-local.service
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no
创建软连接
ln -s /lib/systemd/system/rc.local.service /etc/systemd/system/
开机启动
systemctl enable rc-local.service
把需要添加开机启动的命令添加的/etc/rc.local
即可,如下代码所示
1
2
3
4
5
6
7
8
9
10
11
12
13
#!/bin/bash
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
curlftpfs domainip /mnt/demodomainftp -o user=username:password,allow_other
exit 0
搞定~