绝了,这款P2P全平台的文件同步工具,开源且不依赖中心服务器

最近在研究一些好玩的开源软件,似乎有些沉迷。

发现这样一款软件可以支持多平台的同步软件,可以在Windows上、各种Linux发行版、MacOS是和Android上,甚至你可以在你的群晖或是OpenWRT甚至树莓派上使用它,可以使多个平台的文件保持一致,非常适合企业或是个人文件的多端同步。
经测试同步时差在10s左右,即一方客户端删除、增加或修改文件,另一端开始产生同步效果的时间,效果极佳!

环境准备

话不多说,开始搭建,首先需要一个docker的环境,我这里依然使用一键脚本。

# CentOS,版本至少大于等于7
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

# Ubuntu
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

# Debian
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

我这里依然使用CentOS7来演示搭建,使用其它Linux发行版或运行有Docker环境的小伙伴操作类似。

# 查看Docker的版本
[root@mx ~]# docker -v
Docker version 20.10.9, build c2ea9bc
[root@mx ~]# 

# 查看Docker运行状态
[root@mx ~]# systemctl status docker

image

安装docker-compose

这里搭建需要使用到docker-compose工具,它是docker官方出品的管理软件,能够有效地定义我们容器运行方式,使得管理更加高效。这里使用官方提供的安装脚本。

# 官方
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
# 备用地址
curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.5/docker-compose-`uname -s`-`uname -m`  /usr/local/bin/docker-compose

chmod +x /usr/local/bin/docker-compose

如果上面的方式下载不了,可以以下地址下载二进制运行文件。

# github地址
# https://github.com/docker/compose/releases/

wget https://github.com/docker/compose/releases/download/v2.0.1/docker-compose-linux-x86_64 
mv docker-compose-linux-x86_64 /usr/local/bin/docker-compose && chmod +x /usr/local/bin/docker-compose

查看docker-compose的版本

[root@mx ~]# docker-compose -v
Docker Compose version v2.0.1
[root@mx ~]# 

部署Syncthing

首先创建一个存储数据的目录,并在此目录下创建一个dockerfile的文件。

[root@mx ~]# mkdir -p /opt/docker/syncthing
[root@mx ~]# mkdir -p /opt/docker/syncthing/data
[root@mx ~]# cd /opt/docker/syncthing/ && vim docker-compose.yml

下面是内容,粘贴到docker-compose.yml文件中,保存!我这里把/opt/docker/syncthing/data作为同步目录,大家可自行更改。

---
version: "3"
services:
  syncthing:
    image: syncthing/syncthing
    container_name: syncthing
    hostname: my-syncthing
    environment:
      - PUID=1000
      - PGID=1000
    volumes:
      - /opt/docker/syncthing/data:/var/syncthing
    ports:
      - 8384:8384
      - 22000:22000/tcp
      - 22000:22000/udp
    restart: unless-stopped

执行命令开始部署Syncthing运行环境。

[root@mx syncthing]# docker-compose up
[+] Running 5/5
 ⠿ syncthing Pulled                                                                                                                                               17.2s
   ⠿ a0d0a0d46f8b Pull complete                                                                                                                                    7.1s
   ⠿ c1f268ddb189 Pull complete                                                                                                                                    7.7s
   ⠿ 7135014d6b43 Pull complete                                                                                                                                   11.6s
   ⠿ 1eeaea656424 Pull complete                                                                                                                                   11.8s
[+] Running 2/2
 ⠿ Network syncthing_default  Created                                                                                                                              0.1s
 ⠿ Container syncthing        Created                                                                                                                              0.1s
Attaching to syncthing
syncthing  | [monitor] 12:57:53 INFO: We will skip creation of a default folder on first start
syncthing  | [start] 12:57:53 INFO: syncthing v1.18.3 "Fermium Flea" (go1.17.1 linux-amd64) docker@build.syncthing.net 2021-09-28 06:05:18 UTC [noupgrade]
syncthing  | [start] 12:57:53 INFO: Generating ECDSA key and certificate for syncthing...
syncthing  | [start] 12:57:53 INFO: Default folder created and/or linked to new config
syncthing  | [start] 12:57:53 INFO: Default config saved. Edit /var/syncthing/config/config.xml to taste (with Syncthing stopped) or use the GUI
syncthing  | [start] 12:57:53 INFO: Archiving a copy of old config file format at: /var/syncthing/config/config.xml.v0
syncthing  | [HN32Y] 12:57:53 INFO: My ID: HN32YAU-WLN3D6S-JA65AC6-7VWORO4-O4OOXS3-543CCUQ-FJ3LBX7-SDEU6QY
syncthing  | [HN32Y] 12:57:54 INFO: Single thread SHA256 performance is 164 MB/s using minio/sha256-simd (164 MB/s using crypto/sha256).
syncthing  | [HN32Y] 12:57:55 INFO: Hashing performance is 132.67 MB/s
syncthing  | [HN32Y] 12:57:55 INFO: Running database migration 1...
syncthing  | [HN32Y] 12:57:55 INFO: Running database migration 2...
……


如果启动没有问题,可以使用它在后台运行。使用ctrl+c 结束当前进程,并放到后台运行。

[root@mx syncthing]# docker-compose up -d
[root@mx syncthing]# docker ps
CONTAINER ID   IMAGE                 COMMAND                  CREATED         STATUS                            PORTS                                                                                                                                                NAMES
7cafc4c27c08   syncthing/syncthing   "/bin/entrypoint.sh …"   7 minutes ago   Up 2 seconds (health: starting)   0.0.0.0:8384->8384/tcp, :::8384->8384/tcp, 0.0.0.0:22000->22000/tcp, :::22000->22000/tcp, 21027/udp, 0.0.0.0:22000->22000/udp, :::22000->22000/udp   syncthing
[root@mx syncthing]# 

开放防火墙端口

firewall-cmd --add-port={8384,22000}/tcp --permanent
firewall-cmd --add-port=22000/udp --permanent
firewall-cmd --reload

访问

使用ip:8384访问,可以看到已经正常地访问到我们的syncthing服务了,但还需要一些设置使我们的服务更加的安全。

image

为我们的服务设置一个访问密码,当然在些基础上更好的方法是再为网站添加好ssl证书,此处略过。

image

输入用户名和密码并点击保存。

image

配置同步

点击添加一个文件夹,并为此文件夹设置好名称等相关属性。

image

image

这样我们就建立好了一个可用于同步的文件夹。

image


选择右上角的操作,点击"显示id",会生成一个二维码和id,这个会用于我们后面绑定同步关系。

image

使用客户端测试同步

我这里使用Mac的客户端来先做一个测试,下载好运行文件,点击syncthing开始运行。

image

运行后,会在本地启动一个类似的于Linux服务器上创建的服务。

image

点击右下角的添加设备,将我们前面的id填到此处,点击保存。

image

image

回到Linux端,这里可以看到有一个设备已经添加进来了,点击添加设备,,这样就产生绑定关系了。

image

再把创建的文件夹共享给该设备。

image

这样两端的设备就实现了同步,快去试试吧~需要开源项目地址,可私聊获取!

image

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

运维贼船

你的鼓励将是我创作最大的动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值