How to setup a Alpine Linux mirror

How to setup a Alpine Linux mirror,第1张

概述How to setup a Alpine Linux mirror   Contents 1 Introduction 2 Setting up the cron job 3 Setting up HTTP access via lighttpd 4 Setting up rsyncd 5 Mirror statistics 6 Update mirror from mqtt Introduct How to setup a Alpine linux mirror   Contents 1 Introduction 2 Setting up the cron job 3 Setting up HTTP access via lighttpd 4 Setting up rsyncd 5 Mirror statistics 6 Update mirror from mqtt 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 bashtotal=0dest="$(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  }‘`    total=$(("$old_total" + "$size"))    echo "$dir: $size" | awk ‘{ print  sprintf("%.1f",/1073741824) }‘doneecho "total: $total" | awk ‘{ print  sprintf("%.1f",/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 timelockfile="/tmp/alpine-mirror.lock"if [ -z "$flock" ] ; then  exec env flock=1 flock -n $lockfile "Setting up http access via lighttpd" "[email protected]"fisrc=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)

/etc/lighttpd/lighttpd.conf

Install the lighttpd server

apk add lighttpd

Enable dir Listings by uncommenting the following line in

dir-Listing.activate      = "enable"
:

/etc/lighttpd/lighttpd.conf

Also set cache-control to force cache revalIDate every 30 mins. Uncomment mod_setenv in

"mod_setenv",
:

/etc/lighttpd/lighttpd.conf

Add also the following lines to

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

You may wish to consIDer Darkhttpd as an alternative to Lighttpd

Start lighttpd and make it start at boot:

rc-service lighttpd start rc-update add lighttpd

Note: See the main article on Darkhttpd for more configuration options

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/

Setting up rsyncd /etc/rsyncd.conf

Add the following lines to

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

/etc/conf.d/rsyncd

Optionally set a banDWIDth limit in

RSYNC_OPTS="--bwlimit=500"
. In this example we limit to 500Kbytes/s (approx 5Mbit/s)

Mirror statistics
#!/usr/bin/env shoutput="/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.HTMLfifor type in hours days months top10 summary hsummary vsummary; do    vnstati --${type} -i $nic -o $output/${type}.pngdone

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

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

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

#!/bin/shsrc="rsync://rsync.alpinelinux.org/alpine/"dest="/var/www/localhost/htdocs/alpine/"lock="/tmp/sync-mirror.lock"topic=""dir=""[ -z "$flock" ] && exec env flock=1 flock $lock  "[email protected]"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"

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

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全部内容,希望文章能够帮你解决How to setup a Alpine Linux mirror所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/1027775.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存