tunasync搭建类似清华源镜像 tunasync不知道为什么安装不了。 文档:tunasync/docs/zh_CN/get_started.md at master · tuna/tunasync 下载解压(tar -xvzf archive.tar.gz),不用编译,按照文档 mkdir 创建文件夹 ,touch 创建文件,可以使用redis。
运行脚本
1 2 ./tunasync manager --config /home/uesr/tuna/tunasync_demo/manager.conf ./tunasync worker --config /home/user/tuna//tunasync_demo/worker.conf
这个脚本疑似需要3个ssh窗口
tunasync/docs/zh_CN/workers.conf at master · tuna/tunasync
可以在这里选择要同步的内容
参考
搭建开源镜像站 - fangpsh’s blog
(6 封私信) 使用tunasync部署企业内部开源软件镜像站 - 知乎
使用tunasync搭建自己的开源软件镜像仓库 - 点滴记忆
基于nginx搭建镜像站 这个教程基于deepseek
1 怎么使用nginx和rsync搭建一个可用的镜像源站(类似清华源)。只有局域网使用,可以同步ubuntu的东西,用户界面可以超级简陋(甚至只有文件目录),可以使用sh脚本。
环境要求
Ubuntu服务器(18.04或更高版本)
充足的磁盘空间(建议至少500GB)
局域网环境
安装步骤 1. 安装必要的软件包 bash
1 2 sudo apt update sudo apt install -y nginx rsync cron
2. 创建镜像存储目录 bash
1 2 3 sudo mkdir -p /var/www/mirror/ubuntu sudo chown -R www-data:www-data /var/www/mirror sudo chmod -R 755 /var/www/mirror
3. 配置Nginx 创建Nginx配置文件
1 sudo nano /etc/nginx/sites-available/mirror
添加以下内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 server { listen 80 ; server_name _; root /var/www/mirror; index index.html; autoindex on ; autoindex_exact_size off ; autoindex_localtime on ; location / { try_files $uri $uri / =404 ; } }
启用站点并重新加载Nginx:
1 2 3 sudo ln -s /etc/nginx/sites-available/mirror /etc/nginx/sites-enabled/ sudo nginx -t sudo systemctl reload nginx
4. 创建同步脚本 创建同步脚本
1 sudo nano /usr/local/bin/sync-mirror.sh
添加以下内容
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 #!/bin/bash # 镜像源设置(可以使用清华源或其他国内源) MIRROR_URL="rsync://mirrors.tuna.tsinghua.edu.cn/ubuntu/" # 本地存储路径 LOCAL_PATH="/var/www/mirror/ubuntu" # 日志文件 LOG_FILE="/var/log/ubuntu-sync.log" # 同步选项 RSYNC_OPTIONS="-avzH --delete --partial --progress --bwlimit=10000" # 开始同步 echo "开始同步: $(date)" >> $LOG_FILE rsync $RSYNC_OPTIONS $MIRROR_URL $LOCAL_PATH >> $LOG_FILE 2>&1 echo "同步完成: $(date)" >> $LOG_FILE # 更新权限 chown -R www-data:www-data $LOCAL_PATH chmod -R 755 $LOCAL_PATH
给脚本执行权限:
1 sudo chmod +x /usr/local/bin/sync-ubuntu-mirror.sh
5. 设置定时同步 编辑cron任务:
添加以下内容(每天凌晨3点同步):
1 0 3 * * * /usr/local/bin/sync-ubuntu-mirror.sh
6. 首次同步 手动执行首次同步(这将需要很长时间,取决于网络速度和源站负载):
bash
1 sudo /usr/local/bin/sync-ubuntu-mirror.sh
7. 创建简单用户界面(可选) 可以创建基本HTML页面 /var/www/mirror/index.html:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 <!DOCTYPE html > <html > <head > <title > 局域网Ubuntu镜像站</title > <style > body { font-family : Arial, sans-serif; margin : 40px ; } h1 { color : #333 ; } a { color : #007bff ; text-decoration : none; } a :hover { text-decoration : underline; } </style > </head > <body > <h1 > 局域网Ubuntu镜像站</h1 > <p > 本镜像站最后更新时间: <span id ="last-update" > 未知</span > </p > <p > 可用资源:</p > <ul > <li > <a href ="/ubuntu" > Ubuntu 主仓库</a > </li > </ul > <script > fetch ('/ubuntu-mirror-sync.log' ) .then (response => response.text ()) .then (data => { const lines = data.split ('\n' ); const lastUpdate = lines.filter (line => line.includes ('同步完成' )); if (lastUpdate.length > 0 ) { document .getElementById ('last-update' ).textContent = lastUpdate[lastUpdate.length - 1 ]; } }) .catch (err => { console .log ('无法获取更新日志' ); }); </script > </body > </html >
8. 客户端配置 局域网内的其他Ubuntu机器可以使用此镜像站,编辑sources.list:
1 sudo nano /etc/apt/sources.list
替换为:
1 2 3 4 deb http://[你的服务器IP]/ubuntu/ focal main restricted universe multiverse deb http://[你的服务器IP]/ubuntu/ focal-updates main restricted universe multiverse deb http://[你的服务器IP]/ubuntu/ focal-backports main restricted universe multiverse deb http://[你的服务器IP]/ubuntu/ focal-security main restricted universe multiverse
然后运行更新:
管理维护
监控同步状态 :
1 tail -f /var/log/ubuntu-mirror-sync.log
手动触发同步 :
1 sudo /usr/local/bin/sync-ubuntu-mirror.sh
检查磁盘使用情况 :
1 2 df -h /var/www/mirror du -sh /var/www/mirror/ubuntu
同步脚本修改 前提:找到同步源 中国科学技术大学USTC Open Source Software Mirror 中科大raync同步方法https://mirrors.ustc.edu.cn/help/rsync-guide.html
查看一个镜像站可同步仓库列表
1 rsync rsync.mirrors.ustc.edu.cn:: #有的高校镜像源的rsync协议的url不带rsync
或者
1 rsync mirrors.nju.edu.cn:: #例如南京大学
查看资源目录结构(以ubuntu为例)
1 rsync rsync://rsync.mirrors.ustc.edu.cn/ubuntu/
修改同步脚本: 例如,修改为同步南京大学镜像站的7-zip资源
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 #!/bin/bash # 南京大学7-Zip镜像源设置 MIRROR_URL="rsync://mirrors.nju.edu.cn/7-zip/" LOCAL_PATH="/var/www/mirror/7-zip" LOG_FILE="/var/log/7zip-mirror.log" #镜像URL:改为南京大学7-Zip的rsync地址 rsync://mirrors.nju.edu.cn/7-zip/ #本地路径:调整为 /var/www/mirror/7-zip 以明确存储内容 #日志文件:更名为 /var/log/7zip-mirror.log # 同步选项(保留删除选项以确保镜像一致性) RSYNC_OPTIONS="-av --delete --bwlimit=10000" # 创建本地目录(如果不存在) mkdir -p $LOCAL_PATH # 开始同步 echo "开始同步7-Zip镜像: $(date)" >> $LOG_FILE rsync $RSYNC_OPTIONS $MIRROR_URL $LOCAL_PATH >> $LOG_FILE 2>&1 # 检查同步结果并记录 if [ $? -eq 0 ]; then echo "同步成功完成: $(date)" >> $LOG_FILE # 更新时间戳 echo "最后同步时间: $(date)" > $LOCAL_PATH/LAST_SYNC.txt else echo "同步失败,退出代码: $? - $(date)" >> $LOG_FILE exit 1 fi # 添加镜像站信息文件 cat > $LOCAL_PATH/MIRROR_INFO.txt << EOF ================================================== Nanjing University www.nju.edu.cn Open Source Mirror http://mirror.nju.edu.cn https://mirror.nju.edu.cn rsync://mirror.nju.edu.cn -------------------------------------------------- 7-Zip 镜像同步时间: $(date) 镜像路径: $LOCAL_PATH ================================================== EOF echo "同步完成,详细信息请查看: $LOG_FILE"
改进说明:
增强了日志记录 :添加了更详细的分隔符和同步信息
添加了镜像信息文件 :在本地镜像目录创建 MIRROR_INFO.txt 文件,包含镜像站的基本信息
改进了错误处理 :更详细地记录同步结果和可能的错误
添加了完成提示 :脚本执行完成后会在终端显示简要信息
解决Nginx显示默认欢迎页面问题 例如:
1 2 3 4 5 6 7 Welcome to nginx! If you see this page, the nginx web server is successfully installed and working. Further configuration is required. For online documentation and support please refer to nginx.org. Commercial support is available at nginx.com. Thank you for using nginx.
看到的Nginx欢迎页面表明仍在运行默认站点。
1. 禁用默认站点 1 2 # 使用以下命令禁用默认站点 sudo unlink /etc/nginx/sites-enabled/default
2. 确认您的镜像站点配置已启用 1 2 3 4 5 # 检查您的镜像站点配置是否已链接到sites-enabled目录 ls -l /etc/nginx/sites-enabled/ # 如果不存在链接,创建它 sudo ln -s /etc/nginx/sites-available/mirror /etc/nginx/sites-enabled/
3. 检查Nginx配置语法
如果配置正确,您应该看到:
1 2 nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
4. 重新加载Nginx配置 1 sudo systemctl reload nginx
5. 验证镜像站点是否正常工作 访问您的服务器IP地址,现在应该显示镜像目录列表而不是欢迎页面。
下方未试过了
如果问题仍然存在 检查Nginx的主配置文件,确保它包含了sites-enabled目录:
bash
1 sudo nano /etc/nginx/nginx.conf
确保有以下内容(通常在http块中):
text
1 2 3 4 5 http { ... include /etc/nginx/sites-enabled/*; ... }
检查防火墙设置 确保防火墙允许HTTP流量:
1 2 3 # 如果使用ufw sudo ufw allow 'Nginx HTTP' sudo ufw status
apt-mirror同步ubuntu源 安装apt-mirror
1 sudo apt install apt-mirror
编辑mirror.list配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 ############# config ################## # # set base_path /var/spool/apt-mirror # # set mirror_path $base_path/mirror # set skel_path $base_path/skel # set var_path $base_path/var # set cleanscript $var_path/clean.sh # set defaultarch <running host architecture> # set postmirror_script $var_path/postmirror.sh # set run_postmirror 0 set nthreads 20 set _tilde 0 # ############# end config ############## # 阿里云Ubuntu的APT源 deb [arch=amd64] http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse deb [arch=amd64] http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse deb [arch=amd64] http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse deb [arch=amd64] http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse deb [arch=amd64] http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse # 下载完成后清除部分空间 clean https://mirrors.aliyun.com/ubuntu
运行sudo apt-mirror
但是出现的问题是会显示出一个镜像源的网址的文件夹。
这一部分参考文献
使用apt-mirror搭建内网Ubuntu APT源同步阿里APT源 - 简书
需要使用的命令:
使用 mv 命令的 -t 选项移动多个文件夹。(将多个文件夹 a 、b 、c 和 d 移动到目标目录 myfile 中)
mv a b c d -t /myfile或者mv -t /myfile a b c d
github项目同步 比如obs等项目,需要下载发行文件到本地 清华源使用的api:https://api.github.com/repos/
pip镜像:pypiserver bandersnatch
Python 搭建私有 PyPI 仓库不完全指南-阿里云开发者社区
(12 封私信) 公司内网搭建Python pip 镜像站。 - 知乎
debian部分同步
可以使用ftpsync同步特定架构的debian软件包:比如不需要mips,s390x架构的包。
搭建debian源镜像服务器-CSDN博客
[debian ftpsync sync debian-portriscv64] mirror
Debian – 在 trixie 中的 ftpsync 软件包详细信息
使用nginx搭建debian源镜像服务器_ftpsync debain-CSDN博客
Debian – 建立一个 Debian 仓库的镜像