Syncthing是一个开源文件同步工具,可以在多台设备之间实时同步文件或文件夹,官方网站:https://syncthing.net/ 下载地址:https://syncthing.net/downloads/ ,如果是windows一般推荐下载图形界面SyncTrayzor, 但我这边都是linux,就用k8s+docker了。
1、先贴上k8s的,因为这是云端的master服务器
XML
apiVersion: apps/v1
kind: Deployment
metadata:
name: syncthing
labels:
app: syncthing
spec:
replicas: 1
selector:
matchLabels:
app: syncthing
strategy:
type: Recreate
template:
metadata:
labels:
app: syncthing
spec:
containers:
- env:
- name: PGID
value: "1000"
- name: PUID
value: "1000"
- name: TZ
value: '"Asia/Shanghai"'
image: linuxserver/syncthing:1.23.2
name: syncthing
ports:
- containerPort: 8384
- containerPort: 22000
- containerPort: 22000
protocol: UDP
- containerPort: 21027
protocol: UDP
resources: {}
volumeMounts:
- mountPath: /var/syncthing
name: syncthing-data
restartPolicy: Always
volumes:
- name: syncthing-data
nfs:
server: 172.30.0.15
path: /data/nfs/syncthing
---
apiVersion: v1
kind: Service
metadata:
labels:
app: syncthing
name: syncthing
spec:
ports:
- name: "8384" # web管理页面
port: 8384
targetPort: 8384
- name: "22000" # 服务器同步发现端口,文件也通过这个端口传输
port: 22000
targetPort: 22000
- name: 22000-udp
port: 22000
protocol: UDP
targetPort: 22000
- name: "21027"
port: 21027
protocol: UDP
targetPort: 21027
selector:
app: syncthing
type: NodePort
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: syncthing-ingress
annotations:
kubernetes.io/ingress.class: nginx
spec:
tls:
- hosts:
- 'syncthing.xxx.com'
secretName: syncthing-tls
rules:
- host: syncthing.xxx.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: syncthing
port:
number: 8384
2、再贴上docker的,这是slave
XML
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、保持网络通畅,然后添加设备,共享文件夹就是了