How to setup a Alpine Linux mirror

 

Contents

Introduction

This document describes how to set up an Alpine Linux mirror and make it available via http and rsync.

We will:

  • create the dir where we have the mirror
  • set up a cron job to sync with master mirror every hour
  • set up lighttpd for http access
  • set up rsync so other mirrors can rsync from you

Make sure that you have enough disk space.

Current (2019-01-24) disk usage in GB:

edge v2.4 v2.5 v2.6 v2.7 v3.0 v3.1 v3.2 v3.3 v3.4 v3.5 v3.6 v3.7 v3.8 v3.9 total
98.1 18.9 10.4 13.0 16.6 16.5 17.5 14.5 20.4 24.3 33.8 45.6 43.8 69.3 66.8 525.4

Script used to calculate the size:

#!/usr/bin/env bash

total=0
dest="$(mktemp -d)" for dir in edge v2.4 v2.5 v2.6 v2.7 v3.0 v3.1 v3.2 v3.3 v3.4 v3.5 v3.6 v3.7 v3.8; do
old_total="$total"
src="rsync://rsync.alpinelinux.org/alpine/$dir/"
size=`rsync -a -n --stats "$src" "$dest" | grep '^Total file size' | tr -d ',' | awk '{ print $4 }'`
total=$(("$old_total" + "$size"))
echo "$dir: $size" | awk '{ print $1 sprintf("%.1f", $2/1073741824) }'
done echo "total: $total" | awk '{ print $1 sprintf("%.1f", $2/1073741824) }'
rm -r "$dest"

Setting up the cron job

Install rsync which will be used to sync from the master mirror.

apk add rsync

Save the following file as /etc/periodic/hourly/alpine-mirror

#!/usr/bin/env sh

# make sure we never run 2 rsync at the same time
lockfile="/tmp/alpine-mirror.lock"
if [ -z "$flock" ] ; then
exec env flock=1 flock -n $lockfile "$0" "$@"
fi src=rsync://rsync.alpinelinux.org/alpine/
dest=/var/www/localhost/htdocs/alpine/ # uncomment this to exclude old v2.x branches
#exclude="--exclude v2.*" mkdir -p "$dest"
/usr/bin/rsync \
--archive \
--update \
--hard-links \
--delete \
--delete-after \
--delay-updates \
--timeout=600 \
$exclude \
"$src" "$dest"

(or use this script)

Make it executable:

chmod +x /etc/periodic/hourly/alpine-mirror

Now it will sync every hour. (given cron runs)

Setting up HTTP access via lighttpd

Install the lighttpd server

apk add lighttpd

Enable dir listings by uncommenting the following line in /etc/lighttpd/lighttpd.conf:

dir-listing.activate      = "enable"

Also set cache-control to force cache revalidate every 30 mins. Uncomment mod_setenv in /etc/lighttpd/lighttpd.conf:

"mod_setenv",

Add also the following lines to /etc/lighttpd/lighttpd.conf:

setenv.add-response-header += (
"Cache-Control" => "must-revalidate"
)

Start lighttpd and make it start at boot:

rc-service lighttpd start rc-update add lighttpd

Note: You may wish to consider Darkhttpd as an alternative to Lighttpd

If so, simply install, start and auto-start the webserver:

apk add darkhttpd && rc-service darkhttpd start && rc-update add darkhttpd

Darkhttpd will, by default, offer directory listings and serve data from /var/www/localhost/htdocs/

See the main article on Darkhttpd for more configuration options

Setting up rsyncd

Add the following lines to /etc/rsyncd.conf:

[alpine]
path = /var/www/localhost/htdocs/alpine
comment = My Alpine Linux Mirror

Optionally set a bandwidth limit in /etc/conf.d/rsyncd. In this example we limit to 500Kbytes/s (approx 5Mbit/s)

RSYNC_OPTS="--bwlimit=500"

Mirror statistics

Simple bandwidth statistics can be generated with vnstat.

apk add vnstat

edit /etc/vnstat.conf and replace the interface name with the appropriate one.

Start vnstatd

/etc/init.d/vnstatd start

copy the following script to /etc/periodic/15min/stats and make sure your crond is running. please not that heredoc should be tab indented or the script will fail. A working copy can be found here: http://tpaste.us/RrMv

#!/usr/bin/env sh

output="/var/www/localhost/htdocs/.stats"
nic="eth0" generate_index() {
cat <<-EOF
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="cache-control" content=no-cache">
<meta http-equiv="refresh" content="3000">
<title>Alpine Linux mirror statistics</title>
</head>
<body>
<table border="0">
<tr><td><img src="summary.png" alt="summary"></td><td><img src="hours.png" alt="hours"></td></tr>
<tr><td rowspan="2"><img src="days.png" alt="days"></td><td><img src="top10.png" alt="top10"></td></tr>
<tr><td><img src="months.png" alt="months"></td></tr>
</table>
</body>
</html>
EOF
} if [ ! -f "$output"/index.html ]; then
mkdir -p $output
generate_index > "$output"/index.html
fi for type in hours days months top10 summary hsummary vsummary; do
vnstati --${type} -i $nic -o $output/${type}.png
done

Update mirror from mqtt

If you want your mirror to be really uptodate compared to our master mirror you can subscribe to Alpine Linux message server "msg.alpinelinux.org" and check for upload messages. Add mqtt-exec to be able to execute processes when specific topics are being send.

apk add mqtt-exec

mqtt-exec supports running multiple time so we need to setup a specific config.

ln -s /etc/init.d/mqtt-exec /etc/init.d/mqtt-exec.sync-mirror

ln -s /etc/conf.d/mqtt-exec /etc/conf.d/mqtt-exec.sync-mirror

edit /etc/conf.d/mqtt-exec.sync-mirror

mqtt_topics="rsync/rsync.alpinelinux.org/#"
exec_user="buildozer"
exec_command="/usr/local/bin/sync-mirror"

Copy the following file to /usr/local/bin/sync-mirror and make it executable (dont forget to update the variables).

#!/bin/sh

src="rsync://rsync.alpinelinux.org/alpine/"
dest="/var/www/localhost/htdocs/alpine/"
lock="/tmp/sync-mirror.lock"
topic="$1"
dir="$2" [ -z "$flock" ] && exec env flock=1 flock $lock $0 "$@" if [ -n "$dir" ] && [ -d "$dest/${dir%/*}" ]; then
logger "Syncing directory: $dir"
src="${src}${dir%/}/"
dest="${dest}${dir%/}/"
else
logger "Syncing all directories"
fi /usr/bin/rsync \
--archive \
--update \
--verbose \
--progress \
--timeout=600 \
--delay-updates \
--delete-after \
"$src" \
"$dest"

And finally start mqtt-exec and let it listen on msg.alpinelinux.org

/etc/init.d/mqtt-exec.sync-mirror start

To make sure you are not missing any packages (in case something goes wrong with MQTT subscription) you can periodically sync all directories by adding the script to cron.

ln -s /usr/local/bin/sync-mirror /etc/periodic/hourly/sync-mirror

Now watch your syslog as it should tell you when it will update directories in your local mirror.

How to setup a Alpine Linux mirror的更多相关文章

  1. 转载Alpine Linux常用命令

    Alpine Linux常用命令 目录 一:Alpine Linux开启SSH远程登陆 1.简介: 2.配置 3.配置命令 4.重启服务 二:Alpine Linux源管理 1.简介 2.国内源简介: ...

  2. Alpine Linux常用命令

    一:Alpine Linux开启SSH远程登陆 1.简介: 最重要的一个服务了,远程登陆需要用它,文件传输需要用它,必备功能.不管你是在实体机上跑,虚拟机上跑,docker里面跑,这个都是必须的. 2 ...

  3. Alpine Linux:如何配置GUI的图形桌面环境:x Desktop Environment

    alpine linux 真是不错.小巧.迅捷! 官方的各个版本的alpine镜像内没有带图形环境的.那我们如何构建自己的桌面图形环境呢? 其实:这个问题,在起官网的wiki内有指南,我们根据那些相关 ...

  4. Alpine Linux配置使用技巧【一个只有5M的操作系统(转)】

    Alpine Linux是一个面向安全应用的轻量级Linux发行版.它采用了musl libc和busybox以减小系统的体积和运行时资源消耗,同时还提供了自己的包管理工具apk. Alpine Li ...

  5. 更新Alpine Linux源 sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories apk add xxx

    更新Alpine Linux源 国内镜像源 清华TUNA镜像源:https://mirror.tuna.tsinghua.edu.cn/alpine/中科大镜像源:http://mirrors.ust ...

  6. Alpine Linux 常用命令

    一:Alpine Linux开启SSH远程登陆 1.简介: 最重要的一个服务了,远程登陆需要用它,文件传输需要用它,必备功能.不管你是在实体机上跑,虚拟机上跑,docker里面跑,这个都是必须的. 2 ...

  7. Centos7安装完毕后重启提示Initial setup of CentOS Linux 7 (core)的解决方法

    问题: CentOS7安装完毕,重新开机启动后显示: Initial setup of CentOS Linux 7 (core) 1) [x] Creat user 2) [!] License i ...

  8. [转]装完CentOS后,重新开机启动后显示: Initial setup of CentOS Linux 7 (core)

    转:装完Centos7提示Initial setup of CentOS Linux 7 (core)   在用U盘装完CentOS后,重新开机启动后显示: Initial setup of Cent ...

  9. Docker系列之(三):Docker微容器Alpine Linux

    1. 前言 使用Docker创建容器时,基础镜像通常选择Ubuntu或Centos,不管哪个镜像的大小都在100MB以上. Alpine Linux是一个面向安全的轻型的Linux发行版. Alpin ...

随机推荐

  1. Python只有文件不存在才能写文件

    当我们在Python里面写文件时,我们常用的模式为 w模式,这种模式下,如果文件不存在,就会生成文件:如果文件已经存在,就会直接覆盖. 有时候,如果文件已经存在,直接覆盖文件可能会导致重要数据丢失.你 ...

  2. Natas24 Writeup(strcmp绕过漏洞)

    Natas24: 一个登录页面,查看源码,发现关键代码: if(array_key_exists("passwd",$_REQUEST)){ if(!strcmp($_REQUES ...

  3. 原来rollup这么简单之 rollup.watch篇

    大家好,我是小雨小雨,致力于分享有趣的.实用的技术文章. 内容分为翻译和原创,如果有问题,欢迎随时评论或私信,希望和大家一起进步. 大家的支持是我创作的动力. 计划 rollup系列打算一章一章的放出 ...

  4. MySQL数据库02

    MySQL数据库 前言: 前面我们了解了什么是数据库,什么是MySQL数据库以及如何运用,接下来我们接着深入学习MySQL. (提前声明,以下所提供的事例不标准,仅供参考) 数据库的备份与还原: 备份 ...

  5. Ubuntu 安装 tensorflow-gpu 1.4 包含 CUDA 8.0 和cuDNN

    硬件环境:NVIDIA GTX 980 Ti 系统环境:Ubuntu 16.04 64位 一.安装 NVIDIA驱动 关闭 Secure Boot 具体如何禁用 BIOS 中的 Secure Boot ...

  6. [AI开发]一个例子说明机器学习和深度学习的关系

    深度学习现在这么火热,大部分人都会有‘那么它与机器学习有什么关系?’这样的疑问,网上比较它们的文章也比较多,如果有机器学习相关经验,或者做过类似数据分析.挖掘之类的人看完那些文章可能很容易理解,无非就 ...

  7. 解决Pycharm导入当前项目的.py文件错误

    如图所示错误,由左边导航栏可见.py文件存在: 解决办法:右键单击导包错误文件所在目录,选择[Mark Directory as]+[Sources Root] 错误已解决:

  8. ML-Agents(四)GridWorld

    目录 ML-Agents(四)GridWorld Visual Observations Masking Discrete Actions 环境与训练参数 场景基本结构 代码分析 环境初始化代码 Ag ...

  9. [bzoj]1059矩阵游戏<二分图匹配*匈牙利算法>

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1059 初见此题,我觉得这是水题,我认为只要每一行和每一列至少存在一个黑格就可以出现对角线, ...

  10. TCP/IP中的传输层协议TCP、UDP

    TCP提供可靠的通信传输,而UDP则常用于让广播和细节控制交给应用的通信传输. 传输层协议根据IP数据报判断最终的接收端应用程序. TCP/IP的众多应用协议大多以客户端/服务端的形式运行.客户端是请 ...