Syncthing是一个开源文件同步工具,可以在多台设备之间实时同步文件或文件夹,官方网站:https://syncthing.net/ 下载地址:https://syncthing.net/downloads/ ,如果是windows一般推荐下载图形界面SyncTrayzor, 但我这边都是linux,就用k8s+docker了。
1、先贴上k8s的,因为这是云端的master服务器
apiVersion: apps/v1
kind: Deployment
metadata:name: syncthinglabels:app: syncthing
spec:replicas: 1selector:matchLabels:app: syncthingstrategy:type: Recreatetemplate:metadata:labels:app: syncthingspec:containers:- env:- name: PGIDvalue: "1000"- name: PUIDvalue: "1000"- name: TZvalue: '"Asia/Shanghai"'image: linuxserver/syncthing:1.23.2name: syncthingports:- containerPort: 8384- containerPort: 22000- containerPort: 22000protocol: UDP- containerPort: 21027protocol: UDPresources: {}volumeMounts:- mountPath: /var/syncthingname: syncthing-datarestartPolicy: Alwaysvolumes:- name: syncthing-datanfs:server: 172.30.0.15path: /data/nfs/syncthing
---
apiVersion: v1
kind: Service
metadata:labels:app: syncthingname: syncthing
spec:ports:- name: "8384" # web管理页面port: 8384targetPort: 8384 - name: "22000" # 服务器同步发现端口,文件也通过这个端口传输port: 22000targetPort: 22000- name: 22000-udpport: 22000protocol: UDPtargetPort: 22000- name: "21027"port: 21027protocol: UDPtargetPort: 21027selector:app: syncthingtype: NodePort
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:name: syncthing-ingressannotations:kubernetes.io/ingress.class: nginx
spec:tls:- hosts:- 'syncthing.xxx.com'secretName: syncthing-tlsrules:- host: syncthing.xxx.comhttp:paths:- path: /pathType: Prefixbackend:service:name: syncthingport:number: 8384
2、再贴上docker的,这是slave
docker run --name syncthing -d --restart always -p 8384:8384 -p 22000:22000 -p 21027:21027 \ -e PGID='1000' -e PUID='1000' -e TZ='Asia/Shanghai' \-v /home/admin/docker_data/syncthing/data:/var/syncthing -v /home/admin/docker_data/syncthing/app:/app linuxserver/syncthing:1.23.2
3、保持网络通畅,然后添加设备,共享文件夹就是了