syncthing 是一個開源檔案同步系統,你可以在服務器上部署一個服務,之後在家和公司部署一個節點,這樣這三個地方的檔案可以自動同步,這比收費的 Dropbox 方案強了不止一點(syncthing 免費,並且容量取決與你服務器的磁盤大小)。這裏有本喵寫的簡介,更多細節建議查看官方文檔。
要使用 compose 部署請參考如下設定
networks:
ingress_intranet:
external: true
services:
ingress:
image: ${IMAGE_OF_NGINX}
restart: always
volumes:
- ./conf/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
- ./conf/nginx/snippets:/etc/nginx/snippets:ro
- ./conf/nginx/conf.d:/etc/nginx/conf.d:ro
networks:
default:
ingress_intranet:
ipv4_address: ${IP_OF_INGRESS}
sync:
image: ${IMAGE_OF_SYNC}
restart: always
ports:
- "22000:22000/tcp"
- "22000:22000/udp"
environment:
- PUID=1000
- PGID=1000
- TZ=Asia/Shanghai
volumes:
- /home/king/Sync:/var/syncthing/Sync
- /opt/data/sync/sync:/var/syncthing/config
stdiscosrv:
build: ./conf/stdiscosrv
restart: always
environment:
- PUID=1000
- PGID=1000
- TZ=Asia/Shanghai
sync
service sync 是必須的,它默認在 8384 端口上啓動了網頁 ui,在 22000 端口上開放了數據同步
stdiscosrv
stdiscosrv 是非必須的,它自建了一個發現服務器,你也可以直接使用 sync 官方默認提供的發現服務器,但官方免費的服務肯定沒有你自己提供的速度快
因爲官方沒有爲 stdiscosrv 提供 image,所以需要自己 build
cat conf/stdiscosrv/Dockerfile
FROM ghcr.io/linuxserver/baseimage-ubuntu:focal
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends syncthing-discosrv; \
rm -rf /var/lib/apt/lists/*
COPY root/ /
EXPOSE 80
VOLUME /data
chmod a+x conf/stdiscosrv/root/etc/cont-init.d/30-config
cat conf/stdiscosrv/root/etc/cont-init.d/30-config
#!/usr/bin/with-contenv bash
# permissions
chown abc:abc \
/data
chmod a+x conf/stdiscosrv/root/etc/services.d/stdiscosrv/run
cat conf/stdiscosrv/root/etc/services.d/stdiscosrv/run
#!/usr/bin/with-contenv bash
exec \
s6-setuidgid abc \
/usr/bin/stdiscosrv -http -listen=':80' -db-dir='/data' -cert='/data/cert.pem' -key='/data/key.pem'
ingress
ingress 不是必須的使用 nginx 創建了反代將 stdiscosrv 和 sync 提供的網頁服務反代到 80 端口供入口網關訪問
server{
listen 80;
server_name sync.xxx.xxx;
location /{
include snippets/proxy-set.conf;
proxy_pass http://sync:8384;
}
}
server{
listen 80;
server_name stdiscosrv.xxx.xxx;
location /{
include snippets/proxy-set.conf;
proxy_pass http://stdiscosrv;
}
}
cat snippets/proxy-set.conf
proxy_connect_timeout 5s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
# version
proxy_http_version 1.1;
proxy_set_header Host $http_host;
# Allow websocket connections
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Scheme $scheme;
proxy_set_header X-Scheme $scheme;
# Pass the original X-Forwarded-For
proxy_set_header X-Original-Forwarded-For $http_x_forwarded_for;