本文主要介绍私有镜像站搭建,主要分两步一是下载同步公网镜像,而是提供web 服务,主要使用tunasync 实现下载,使用nginx 或者mirror-web 提供web 服务
本文主要介绍以非root 用户搭建tunaasync
https://github.com/tuna/tunasync
https://gitee.com/weiwei20180921/tunasync
[root@2023001 ~]# groupadd -g 2001 mirrorgroup
[root@2023001 ~]# useradd -u 2101 -g mirrorgroup mirrors
[root@2023001 ~]# passwd mirrors
主要存放应用配置文件及执行文件
[root@2023001 ~]# su - mirrors
[mirrors@2023001 ~]$ pwd
/home/mirrors
[mirrors@2023001 ~]$ mkdir -p /home/mirrors/tunasync/conf
[mirrors@2023001 ~]$ mkdir -p /home/mirrors/tunasync/db
[mirrors@2023001 ~]$ mkdir -p /home/mirrors/tunasync/bin
[mirrors@2023001 ~]$ tree
.
├── tunasync
│ ├── bin
│ ├── conf
│ └── db
3 directories, 0 files
[root@2023001 data]# mkdir -p /data/mirrors
[root@2023001 data]# chown -R mirrors:mirrorgroup /data/mirrors/
主要使用mirrors 用户部署
下载地址:
https://github.com/tuna/tunasync
或者
https://gitee.com/weiwei20180921/tunasync
将tunasync-linux-amd64-bin.tar.gz 解压到/home/mirrors/tunasync/bin 目录
[mirrors@2023001 bin]$ pwd
/home/mirrors/tunasync/bin
[mirrors@2023001 bin]$ tar -xf /home/mirrors/tunasync-linux-amd64-bin.tar.gz
[mirrors@2023001 bin]$ ls
tunasync tunasynctl
[mirrors@2023001 bin]$
先备份,然后修改,最后source
[mirrors@2023001 ~]$ cp .bash_profile .bash_profile.bak.orig
[mirrors@2023001 ~]$ vim .bash_profile
[mirrors@2023001 ~]$ source .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
TUNAPATH=/home/mirrors/tunasync
PATH=$PATH:$HOME/.local/bin:$HOME/bin:$TUNAPATH/bin
export PATH
~
验证
[mirrors@2023001 ~]$ tunasync -v
Version: 0.8.0
Git Hash: c07aaffe65da65217665d7c5df46ea2d857fdfa9
Build Date: 2021-09-02 22:24:51 +0800 CST
[mirrors@2023001 ~]$
tunasync 的所有配置存放在/home/mirrors/tunasync/conf
创建/home/mirrors/tunasync/conf/manager.conf
debug = false
[server]
addr = "127.0.0.1"
port = 14242
ssl_cert = ""
ssl_key = ""
[files]
db_type = "bolt"
db_file = "/home/mirrors/tunasync/db/manager.db"
ca_cert = ""
配置说明
port:监听端口,由于我下载的预编译版 tunasync 的一个小 bug,这里的 port 需固定配置为 14242
ssl_cert与ssl_key:ssl 配置,不需要 ssl 的同学不用配置
db_file:数据库文件,目前统一放在 /home/mirrors/tunasync/db/ 目录
根据需要创建需同步的镜像配置文件。以 CentOS 镜像为例,同步 CentOS 需要创建 /home/mirrors/tunasync/conf/worker-centos.conf,文件内容如下:
[global]
name = "centos_worker79"
log_dir = "/data/mirrors/log/tunasync/{{.Name}}"
mirror_dir = "/data/mirrors/centos-vault"
concurrent = 10
interval = 1440
[manager]
api_base = "http://localhost:28288"
token = "some_token"
ca_cert = ""
[cgroup]
enable = false
base_path = "/sys/fs/cgroup"
group = "tunasync"
[server]
hostname = "localhost"
listen_addr = "127.0.0.1"
listen_port = 16010
ssl_cert = ""
ssl_key = ""
[[mirrors]]
name = "7.9.2009"
provider = "rsync"
upstream = "rsync://mirrors.tuna.tsinghua.edu.cn/centos-vault/7.9.2009/"
use_ipv6 = false
注意:name = “7.9.2009” + mirror_dir = “/data/mirrors/centos-vault”
生成:/data/mirrors/centos-vault/7.9.2009
配置说明
global name:worker 进程名称,用于程序识别
log_dir:tunasync 的日志路径
mirror_dir:镜像下载地址
concurrent:并发线程数
interval:rsync 同步周期,以分钟为单位
api_base:manager 地址,注意,此处需与 manager 所在服务器配置保持一致
server listen_port:该 worker 自身的监听端口,如果同一台服务器上有多个 worker,各个 worker 的配置文件中务必配置不同端口
mirrors name:镜像名称,tunasync 会在镜像根目录下建立一个该名称的目录用于下载镜像
upstream:同步地址,注意,参数最后需要有“/”,否则启动 tunasync 时会报错
启动 tunasync 需开启 manager 进程与 worker 进程,先启动 manager,后启动 worker。为了便于监控系统进程情况,建立 /data/mirrors/log/plog 目录,所有进程的工作日志在该目录中(注意,此处日志为系统终端输出日志,与 tunasync 自身工作日志不同)。同样的,以下命令由 mirrors 用户操作。
[mirrors@2023001 mirrors]$ mkdir -p /data/mirrors/log/plog
[mirrors@2023001 mirrors]$ tunasync manager --config /home/mirrors/tunasync/conf/manager.conf >> /data/mirrors/log/plog/manager.log &
[2] 2611
[mirrors@2023001 mirrors]$ netstat -anp | grep tunasy
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 127.0.0.1:28288 0.0.0.0:* LISTEN 2611/tunasync
[mirrors@2023001 mirrors]$
[mirrors@2023001 mirrors]$ tunasync worker --config /home/mirrors/tunasync/conf/worker-centos.conf >> /data/mirrors/log/plog/worker-centos.log &
[3] 3233
[mirrors@2023001 mirrors]$ netstat -anp | grep tunasy
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 127.0.0.1:16010 0.0.0.0:* LISTEN 3233/tunasync
tcp 0 0 127.0.0.1:28288 0.0.0.0:* LISTEN 2611/tunasync
[mirrors@2023001 mirrors]$