这里所谓同步其实就是指从外网访问。从外网访问首先需要公网IP,家里的网络跟电信要到了公网IP,但是这个公网IP隔一段时间会变,重启路由器也会变,之前一直在树莓派上面运行一个脚本,每隔一段时间检查公网IP并发送到阿里云服务器,这几天发现R6800自带ddns的功能,这下真是方便太多了。如果没有公网IP的话,可能就需要做反向隧道,就像自己办公室的电脑那样,或者网上有各种花生壳、Zerotier等方式也可以,没试过。
这里的从外网访问主要有ftp和syncthing两种,其实自己都用不到,ssh加rsync就足够了,主要是给kitty用的。
ftp
参考 https://wiki.archlinux.org/index.php/Very_Secure_FTP_Daemon ,archwiki真是百科全书。
sudo apt install vsftpd
修改 /etc/vsftpd.conf 下列几项,其他保持默认就好。
write_enable=YES local_root = /mnt/WD-storage/share chroot_local_user=YES #限制用户只可访问local_root # 开启chroot时,根目录不允许写权限,取消写权限或配置allow_writeable_chroot。 allow_writeable_chroot=YES #允许local_root有写权限
当然本身ftp服务配置在21端口上,需要在路由器上面设置端口映射,使nas的21端口能够从外部访问到
客户端访问的话很多工具,仅在linux上说,登录命令行界面可以用lftp,远程挂载可以用curlftpfs。
syncthing
因为之前折腾过seafile,本来想用seafile或者最近很火的nextcloud的,但是这两个工具都是类似传统的网盘的工具,实现不同客户端的同步,而不包括服务器端。nextcloud在服务器端修改文件,软件无法感知并同步到客户端,seafile服务器端的数据甚至是加密的。而syncthing的概念有点类似于git,是一种分布式的同步,没有中心节点。
安装
debian上的安装很简单,直接加源使用apt安装就可以,也可以直接下载可执行文件。
- apt
curl -s https://syncthing.net/release-key.txt | sudo apt-key add - echo "deb https://apt.syncthing.net/ syncthing stable" | sudo tee /etc/apt/sources.list.d/syncthing.list sudo apt install apt-transport-https sudo apt update sudo apt install syncthing
- systemd
若前面采用apt安装不用这步,安装时默认安装了/lib/systemd/system/syncthing@.service。如果手动安装,并想用systemd管理的话。
将
https://github.com/syncthing/syncthing/blob/master/etc/linux-systemd/system/syncthing%40.service
拷贝到
/etc/systemd/system 或
/usr/local/lib/systemd/system
sudo systemctl enable syncthing@swint.service
sudo systemctl start syncthing@swint.service
- 外部访问
syncthing默认只可以通过localhost来访问,想在外部访问按如下方式:
syncthing # 首次运行,生成配置文件 sed -i 's/127.0.0.1/0.0.0.0/g' ~/.config/syncthing/config.xml
使用
配置还是相当简单地,鼠标点点就好。但是这里面也有不少坑,syncthing是纯粹的同步软件,默认同步home目录下相同路径。如果想让A的
/home/xxx/A/sync/
和B的 /home/xxx/B/sync/
同步的话,需要A修改Actions--Advanced--Options中Default Folder Path为
/home/xxx/A/
,B上做相应的修改,相当于重新定义home路径。