0
点赞
收藏
分享

微信扫一扫

centos7基于tunasync搭建的开源镜像服务

1 开源镜像服务概述

同步镜像站点的数据到本地服务器,使用​​nginx​​实现http服务向局域网内的其他机器提供yum服务,解决内网yum安装软件的问题。

2 开源镜像服务搭建

2.1 支持rsync的国内镜像源

在官方提供的源列表中选择最方便的同步源。

Ubuntu 源列表:https://launchpad.net/ubuntu/+archivemirrors
rsync://mirrors.shuosc.org/ubuntu/
rsync://mirrors.sohu.com/ubuntu/
rsync://mirrors.tuna.tsinghua.edu.cn/ubuntu/
rsync://mirrors.ustc.edu.cn/ubuntu/
rsync://mirrors.yun-idc.com/ubuntu/

CentOS 源列表:https://www.centos.org/download/mirrors/
rsync://mirrors.tuna.tsinghua.edu.cn/centos/
rsync://ftp.iij.ad.jp/centos/
rsync://mirror-hk.koddos.net/centos/

EPEL 源列表:https://admin.fedoraproject.org/mirrormanager/mirrors/EPEL
rsync://mirrors.yun-idc.com/epel/
rsync://rsync.mirrors.ustc.edu.cn/epel/
rsync://hkg.mirror.rackspace.com/epel/


2.2 配置环境

systemctl disable firewalld
systemctl stop firewalld

vim/etc/sysconfig/selinux
并修改SELINUX=enforce为SELINUX=disabled

yum -y install epel-release
yum -y install rsync createrepo nginx
useradd -m -s /bin/bash mirrors #创建mirrors用户
passwd mirrors

mkdir /home/mirrors/tunasync/{conf,db} -pv #建立同步目录
mkdir /data
chown -R mirrors:mirrors /data
chown -R mirrors:mirrors /home/mirrors/*
cd /home/mirrors/tunasync
wget https://github.com/tuna/tunasync/releases/download/v0.3.7/tunasync-linux-bin.tar.gz
tar zxf tunasync-linux-bin.tar.gz
su mirrors
$ vim ~/.bash_profile #增加下面的配置
TUNAPATH=/home/mirrors/tunasync
PATH=$PATH:$TUNAPATH

$ source ~/.bash_profile
$ mkdir -pv /data/mirrors/log/plog


2.3 编辑同步服务的manager 与 worker配置文件(mirrors用户)

$ vim /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 = ""


$ vim /home/mirrors/tunasync/conf/worker-centos.conf #centos系统配置
[global]
name = "centos_worker"
log_dir = "/data/mirrors/log/tunasync/{{.Name}}"
mirror_dir = "/data/mirrors"
concurrent = 6
interval = 1447

[manager]
api_base = "http://192.168.142.132:14242"
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 = "centos"
provider = "rsync"
upstream = "rsync://mirrors.tuna.tsinghua.edu.cn/centos/"
use_ipv6 = false


$ vim /home/mirrors/tunasync/conf/worker-ubuntu.conf #ubuntu系统配置
[global]
name = "ubuntu_worker"
log_dir = "/data/mirrors/log/tunasync/{{.Name}}"
mirror_dir = "/data/mirrors"
concurrent = 10
interval = 3359

[manager]
api_base = "http://192.168.142.132:14242"
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 = 16020
ssl_cert = ""
ssl_key = ""

[[mirrors]]
name = "ubuntu"
provider = "rsync"
upstream = "rsync://mirrors.tuna.tsinghua.edu.cn/ubuntu/"
use_ipv6 = false


$ vim /home/mirrors/tunasync/conf/worker-epel.conf #epel需要配置
[global]
name = "epel_worker"
log_dir = "/data/mirrors/log/tunasync/{{.Name}}"
mirror_dir = "/data/mirrors"
concurrent = 3
interval = 2113

[manager]
api_base = "http://192.168.142.132:14242"
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 = 16030
ssl_cert = ""
ssl_key = ""

[[mirrors]]
name = "epel"
provider = "rsync"
upstream = "rsync://ftp.iij.ad.jp/pub/linux/Fedora/epel/"
use_ipv6 = false


2.4 启动tunasync(mirrors用户)

tunasync manager --config /home/mirrors/tunasync/conf/manager.conf >> /data/mirrors/log/plog/manager.log &


tunasync worker --config /home/mirrors/tunasync/conf/worker-centos.conf >> /data/mirrors/log/plog/worker-centos.log &
tunasync worker --config /home/mirrors/tunasync/conf/worker-ubuntu.conf >> /data/mirrors/log/plog/worker-ubuntu.log &
tunasync worker --config /home/mirrors/tunasync/conf/worker-epel.conf >> /data/mirrors/log/plog/worker-epel.log &


2.5 http 服务

vim /etc/nginx/nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {

autoindex on; #开启nginx目录浏览功能
autoindex_exact_size off; #文件大小从KB开始显示
autoindex_localtime on; #显示文件修改时间为服务器本地时间
charset utf-8,gbk;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;
include /etc/nginx/mime.types;
# default_type application/octet-stream; #点击文件后会下载文件
default_type text/plain; #点击文件是显示内容的
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
listen [::]:80;
server_name _;
root /data/mirrors/;
include /etc/nginx/default.d/*.conf;
location / {
}

error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}




systemctl start nginx && systemctl enable nginx

centos7基于tunasync搭建的开源镜像服务_nginx

2.6 手动更新

更新镜像信息

tunasynctl set-size -w <worker-id> <mirror> <size>

2.7 定时任务(mirrors用户)

vim /home/mirrors/tunasync/scripts/updateTunasync.sh 
#! /bin/bash
source ~/.bash_profile

centos_size=`du -sh /data/mirrors/centos/ | awk '{print $1}'`
epel_size=`du -sh /data/mirrors/epel/ | awk '{print $1}'`
ubuntu_size=`du -sh /data/mirrors/ubuntu/ | awk '{print $1}'`


tunasynctl set-size -w centos_worker centos $centos_size > /dev/null 2>&1
tunasynctl set-size -w epel_worker epel $epel_size > /dev/null 2>&1
tunasynctl set-size -w ubuntu_worker ubuntu $ubuntu_size > /dev/null 2>&1


*/5 * * * * sh /home/mirrors/tunasync/scripts/updateTunasync.sh > /dev/null 2>&1



举报

相关推荐

0 条评论