tunasync 配置

按照官方中文文档学习

在 Github Releases 下载 tunasync-linux-amd64-bin.tar.gz 。

用gunzip 和 untar 解压后 获得了两个二进制

❯ ls
tunasync tunasynctl tunasync-v0.9.3-linux-amd64-bin.tar

创建两个文件夹

一个tunasync_config用于存储配置

一个mirror_data 用于存储镜像数据

文件夹名字可以自己定制 官方文档里给出配置到/tmp中 我不太喜欢把东西塞到/tmp里

配置内容按照文档里自行修改即可

开启同步进程

./tunasync manager --config manager.conf & 
./tunasync worker --config worker.conf &

manager.conf worker.conf 是在当前文件夹下建立的软链接.

我还搞了两个方便的shell脚本

❯ cat kill.sh
pkill -f "tunasync worker"
pkill -f "tunasync manager"

❯ cat start.sh
./tunasync manager --config manager.conf &
./tunasync worker --config worker.conf &

当然 能设置成systemctl的开机启动形式是更好的 但我这毕竟只是测试。

配置nginx

nginx将镜像文件通过https高效的提供给用户,相当于提供了一个让外部用户访问到服务器文件的方式。

nginx 的使用非常简单 只需要写好指定的配置文件 然后用nginx命令启动服务就行

只是通常,这要求用sudo来运行,如果要求使用个人用户,需要给出一些特殊的配置。否则会出现一些权限问题

例如

nginx 的 stop 命令默认会去找 /run/nginx.pid,但你用非 root 用户启动时,pid 文件其实没写到 run,所以 stop 命令找不到 pid,导致无法优雅停止进程。

幸运的是 这些问题通过ai 都能轻松解决,包括定制化的给出pid ,log路径

用ai生成的简易测试配置

worker_processes  1;
pid /home/juryorca/mirror/nginx/logs/nginx.pid;
events { worker_connections 1024; }
http {
# 使用系统上标准的 mime.types(用绝对路径,避免相对查找失败)
include /etc/nginx/mime.types;
default_type application/octet-stream;

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;

server {
# 本地测试用 nginx,监听回环地址,端口 8080
listen 127.0.0.1:8080;
server_name localhost;

# 根目录指向 tunasync 生成的 mirror_data
root /home/juryorca/mirror/tunasync_py/mirror_data;

# 关闭目录索引(如需浏览改为 autoindex on;)
autoindex on;

# 静态文件处理
location / {
try_files $uri $uri/ =404;
add_header Cache-Control "public, max-age=3600";
}

# 日志写到仓库下的 nginx/logs(启动脚本会确保目录存在),避免写系统目录导致权限问题
access_log /home/juryorca/mirror/nginx/logs/mirror_local_access.log combined;
error_log /home/juryorca/mirror/nginx/logs/mirror_local_error.log warn;

# 打开文件缓存以减少 stat 调用
open_file_cache max=1000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;

# gzip 文本类内容
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
}
}

tunasync 和 nginx 联动,就能实现一个服务定时同步上游镜像,一个服务将本地文件转发。

当然 ,实际要在真实环境下跑起来,需要进行更细致的配置。