Changes between Initial Version and Version 1 of Mirroring


Ignore:
Timestamp:
Mar 1, 2016, 1:41:03 PM (8 years ago)
Author:
ryandesign (Ryan Carsten Schmidt)
Comment:

add Mirroring page

Legend:

Unmodified
Added
Removed
Modified
  • Mirroring

    v1 v1  
     1= Mirroring
     2
     3Thank you for your interest in providing a public MacPorts mirror server to join our existing [wiki:Mirrors list of mirrors]. Making MacPorts content available in more locations makes MacPorts faster.
     4
     5As of March 2016 these instructions are preliminary. If you find inaccuracies or have other comments or questions, please let us know by contacting [https://lists.macosforge.org/mailman/listinfo/macports-mgr portmgr].
     6
     7== Contact us
     8
     9First, please contact [https://lists.macosforge.org/mailman/listinfo/macports-mgr portmgr] to let us know you would like to create a mirror. Please tell us the following information:
     10
     11* The name and web page URL of the organization providing the mirror, so that we can credit you properly.
     12* The city, state/province and [wikipedia:ISO_3166-1_alpha-2 ISO 3166-1 alpha-2 country code] where your mirror is located and the [wikipedia:International_Air_Transport_Association_airport_code IATA airport code] of the closest airport. The airport code and country code will become your MacPorts mirror name.
     13* Your mirror's existing hostname. We will create new hostnames abc.xy.distfiles.macports.org, abc.xy.packages.macports.org and abc.xy.rsync.macports.org (where "abc" is your airport code and "xy" is your country code) `CNAME`d to your existing hostname.
     14* The email address of the server's administrator. We will list this on our mirrors page and MacPorts users might report problems to this address.
     15* Your mirror's upstream Internet connection speed and whether or not your mirror supports IPv6. We will list this information on our mirrors page.
     16
     17We will review your request to become a mirror and will let you know if there are any problems. Meanwhile you can follow the rest of these instructions to get your mirror ready. We reserve the right to refuse a request to become a mirror for any reason, or to remove existing mirrors from use at any time and without notice.
     18
     19If in the future you wish to temporariliy or permanently discontinue providing your mirror, please let us know so that we can make the appropriate changes.
     20
     21== Requirements
     22
     23Running a MacPorts mirror will use a possibly significant amount of bandwidth. Our primary server in California, for example, serves around 60GB of data to users per day. MacPorts chooses the closest mirror, so how much traffic your mirror sees depends on the number of MacPorts users for whom your mirror is the closest. Ensure you have the permission of your network provider to run such a mirror, and that this amount of traffic will not be a problem for you.
     24
     25You'll need a server with at least 1TB of available disk space on a case-sensitive filesystem. You'll need a web server on port 80 such as Apache httpd or nginx on which you can configure new virtual hosts, and the rsync daemon running on port 873. The server should have a hostname and a static IPv4 address. IPv6 access is welcomed but is not required. The server does not need to be running OS X and does not need to have MacPorts installed.
     26
     27== Rsync modules
     28
     29The MacPorts files are distributed in four rsync modules. You should usually mirror all of them.
     30
     31* **packages** contains precompiled archives of each MacPorts port for several OS X versions. This is the largest module, around 600GB. Mirroring this module will provide the greatest benefit to MacPorts users near you since it lets them automatically receive these large files more quickly.
     32* **distfiles** contains the source code tarballs from which the precompiled archives were created. There are some ports that cannot legally be distributed as binaries, so those must build from these source files on the user's computer. This is the second-largest module, around 100GB. **Note:** this module used to be called ''mpdistfiles''. If you are mirroring ''mpdistfiles'', please switch to mirroring ''distfiles''. If your local module is called ''mpdistfiles'', please rename it to ''distfiles'' and let us know so that we can update mirror_sites.tcl.
     33* **release** contains the latest released version of the MacPorts base source code which users update by running `sudo port selfupdate`, as well as the collection of Portfiles—the text files MacPorts reads that tell it how to install each port—which users update by running `sudo port sync`. Users near you can manually configure MacPorts to user your mirror for faster speed. This small module is around 500MB.
     34* **trunk** contains the latest development version of the MacPorts base source code. This small module is around 20MB.
     35
     36== Get the files
     37
     38You'll get the files from our server via [https://rsync.samba.org/ rsync]. You should use the latest version of rsync.
     39
     40For your initial sync, you might speed up your transfer by using a nearby existing MacPorts mirror server. For subsequent scheduled syncing, use the master rsync server, rsync-origin.macports.org.
     41
     42**Note:** If you are syncing from rsync.macports.org, distfiles.macports.org, packages.macports.org, or a specific IP address, please switch to rsync-origin.macports.org.
     43
     44There is a sample script below for mirroring these modules via rsync. You don't have to use that script if you already have other arrangements for syncing, but please use the following `rsync` flags, for the following reasons:
     45
     46||=`rsync` flag        =||=Purpose =
     47|| `--compress`, `-z`   || File data is compressed during transfer. The server won't re-compress files that are already compressed.
     48|| `--delete-delay`     || Files which were removed on the server are removed from the mirror after the transfer is finished. This option is similar to but more efficient than `--delete-after`.
     49|| `--hard-links`, `-H` || Hard links are preserved.
     50|| `--links`, `-l`      || Symbolic links (symlinks) are preserved.
     51|| `--perms`, `-p`      || File and directory permissions are preserved.
     52|| `--recursive`, `-r`  || Directories are copied recursively.
     53|| `--timeout=600`      || If no data is transferred for 10 minutes, the connection is dropped.
     54|| `--times`, `-t`      || Modification times are preserved.
     55
     56== Stay up to date
     57
     58After the initial sync is complete, keep your mirror up to date by periodically re-running the sync script. You can do this using cron, launchd, systemd, or another scheduler. A sample cron configuration is provided below.
     59
     60The sample configuration syncs every hour. It is not necessary to sync that often, but MacPorts developers commit dozens of port updates each day, so the more frequently you sync, the more likely your mirror is to have the content users are requesting. Ensure your mirror syncs at least once daily.
     61
     62== Rsync server
     63
     64MacPorts retrieves the contents of the ''release'' and ''trunk'' modules via rsync. MacPorts comes preconfigured to use the server rsync.macports.org but users can edit their configuration to use your mirror instead. In addition, other mirror administrators may wish to copy your ''packages'' and ''distfiles'' modules. So you should run an rsync daemon to republish the modules you synced.
     65
     66The MacPorts rsync modules have generic names, so we suggest you put our modules in a "macports" folder. We would prefer you not rename our modules.
     67
     68**Note:** If you are providing the ''release'' or ''trunk'' modules under nonstandard names, please edit your rsyncd configuration to provide the module under both the nonstandard name and the standard name, and edit the [wiki:Mirrors Mirrors] page to reflect the standard name. If you are providing the ''packages'' or ''distfiles'' modules under nonstandard names, please edit your rsyncd configuration to provide the module under the standard name, edit the [wiki:Mirrors Mirrors] page to reflect the change, and let us know so that we can update mirror_sites.tcl and/or archive_sites.tcl.
     69
     70There is a sample rsyncd configuration below.
     71
     72== Web server
     73
     74MacPorts retrieves files from the ''packages'' and ''distfiles'' modules via http. MacPorts automatically downloads these files from whichever mirror is closest. So you should run a web server to make these modules available.
     75
     76The contents of the ''packages'' module should be made available directly under !http://abc.xy.packages.macports.org/ and the contents of the ''distfiles'' module should be made available directly under !http://abc.xy.distfiles.macports.org/. It is not necessary to provide the contents of the ''release'' or ''trunk'' modules via http.
     77
     78**Note:** If you are currently providing the contents of the ''packages'' or ''distfiles'' modules in a subdirectory of your MacPorts mirror hostname, or any other hostname, you should reconfigure your web server to provide the contents directly under the MacPorts mirror hostname, and let us know so we can update archive_sites.tcl and/or mirror_sites.tcl. You should configure HTTP 301 redirects from the previously-used URLs to the new ones.
     79
     80Directory listings should be turned on. URL spelling correction and multiviews must be turned off. There are sample web server configurations below.
     81
     82== Add mirror to MacPorts
     83
     84Once your server is synced and ready to accept MacPorts traffic, let us know and we will edit archive_sites.tcl and mirror_sites.tcl to add the URLs of your MacPorts mirror hostnames. Also edit the [wiki:Mirrors Mirrors] page to add information about your server, or we can add it for you.
     85
     86== Sample scripts and configuration files
     87
     88=== Sample rsync update script
     89
     90This sample script can be used to mirror the MacPorts rsync modules.
     91
     92For your initial sync of ''packages'' and ''distfiles'', you can possibly make your transfer faster by uncommenting the `RSYNC_URL_FORMAT` line for a mirror server closer to you, but note that currently not all servers mirror all modules, and not all servers follow our module naming suggestions. For subsequent scheduled syncs, use the origin server.
     93
     94{{{
     95#!/bin/sh
     96
     97set -euo pipefail
     98
     99RSYNC_DIR="/var/www/html/macports"
     100
     101RSYNC_MODULES="packages distfiles release trunk"
     102
     103RSYNC_URL_FORMAT="rsync://rsync-origin.macports.org/%s"
     104#RSYNC_URL_FORMAT="rsync://cjj.kr.rsync.macports.org/macports/%s"
     105#RSYNC_URL_FORMAT="rsync://fco.it.rsync.macports.org/macports-%s"
     106#RSYNC_URL_FORMAT="rsync://jnb.za.rsync.macports.org/macports/%s"
     107#RSYNC_URL_FORMAT="rsync://jog.id.rsync.macports.org/macports/%s"
     108#RSYNC_URL_FORMAT="rsync://lil.fr.rsync.macports.org/%s"
     109#RSYNC_URL_FORMAT="rsync://mse.uk.rsync.macports.org/%s.macports.org"
     110#RSYNC_URL_FORMAT="rsync://nou.nc.rsync.macports.org/macports/%s.macports.org"
     111#RSYNC_URL_FORMAT="rsync://nue.de.rsync.macports.org/macports/%s"
     112#RSYNC_URL_FORMAT="rsync://osl.no.rsync.macports.org/%s"
     113#RSYNC_URL_FORMAT="rsync://sea.us.rsync.macports.org/%s"
     114#RSYNC_URL_FORMAT="rsync://sjc.us.rsync.macports.org/%s"
     115
     116RSYNC=rsync
     117RSYNC_ARGS="--compress --delete-delay --hard-links --links --no-motd --perms --recursive --stats --timeout=600 --times"
     118if [ -t 1 ]; then
     119    RSYNC_ARGS="$RSYNC_ARGS --info=progress2"
     120fi
     121
     122for RSYNC_MODULE in $RSYNC_MODULES; do
     123    RSYNC_URL="$(printf "$RSYNC_URL_FORMAT" "$RSYNC_MODULE")"
     124    echo "Syncing $RSYNC_MODULE from $RSYNC_URL"
     125    $RSYNC $RSYNC_ARGS "$RSYNC_URL" "$RSYNC_DIR/$RSYNC_MODULE"
     126    echo
     127done
     128}}}
     129
     130=== Sample cron configuration
     131
     132This sample cron configuration runs the above sync script every hour at 30 minutes past the hour:
     133
     134{{{
     13530 * * * * /usr/local/bin/macports-rsync.sh 2>&1 >> /var/log/macports-rsync.log
     136}}}
     137
     138So that not all mirrors are trying to connect to the origin server at the same time, please change "30" to a random number between 0 and 59.
     139
     140=== Sample Apache httpd configuration
     141
     142This sample configuration can be used to serve MacPorts files with Apache httpd.
     143
     144{{{
     145<Directory /var/www/html/macports>
     146    Order allow,deny
     147    Allow from all
     148    AllowOverride None
     149    Options +Indexes -FollowSymLinks -MultiViews
     150    IndexOptions Charset=UTF-8 FancyIndexing IconsAreLinks HTMLTable NameWidth=* SuppressDescription
     151    AddType application/macbinhex-40 .hqx
     152    AddType application/octet-stream .bin .exe .rmd160
     153    AddType application/x-7z-compressed .7z
     154    AddType application/x-apple-diskimage .dmg .image .img .smi
     155    AddType application/x-bzip2 .bz2 .tbz .tbz2
     156    AddType application/x-compress .Z
     157    AddType application/x-gzip .gz .tgz
     158    AddType application/x-iso9660-image .iso
     159    AddType application/x-lzip .lz
     160    AddType application/x-lzma .lzma .tlz
     161    AddType application/x-rar-compressed .rar
     162    AddType application/x-stuffit .sit
     163    AddType application/x-stuffitx .sitx
     164    AddType application/x-tar .tar
     165    AddType application/x-tcl .tcl
     166    AddType application/x-xz .txz .xz
     167    AddType application/zip .zip
     168</Directory>
     169<VirtualHost *:80>
     170    ServerName abc.xy.distfiles.macports.org
     171    ServerAlias distfiles.macports.org
     172    DocumentRoot /var/www/html/macports/distfiles
     173    UseCanonicalName On
     174    <IfModule mod_speling.c>
     175        CheckSpelling Off
     176    </IfModule>
     177
     178    Header set "Cache-Control" "max-age=2592000, public"
     179    <LocationMatch "/$">
     180        Header set "Cache-Control" "max-age=300, public"
     181    </LocationMatch>
     182    <LocationMatch "^/ports\.tar\.gz$">
     183        Header set "Cache-Control" "max-age=1800, public"
     184    </LocationMatch>
     185</VirtualHost>
     186<VirtualHost *:80>
     187    ServerName abc.xy.packages.macports.org
     188    ServerAlias packages.macports.org
     189    DocumentRoot /var/www/html/macports/packages
     190    UseCanonicalName On
     191    <IfModule mod_speling.c>
     192        CheckSpelling Off
     193    </IfModule>
     194
     195    Header set "Cache-Control" "max-age=2592000, public"
     196    <LocationMatch "/$">
     197        Header set "Cache-Control" "max-age=300, public"
     198    </LocationMatch>
     199</VirtualHost>
     200}}}
     201
     202If you are serving MacPorts files from subdirectories on any of your hostnames, use `Redirect` directives to redirect those requests to their new locations. For example, these directives show how to redirect requests for !http://hostname/pub/macports/packages/... to !http://abc.xy.packages.macports.org/... and requests for !http://hostname/pub/macports/distfiles/... to !http://abc.xy.distfiles.macports.org/...:
     203
     204{{{
     205    Redirect 301 /pub/macports/packages http://abc.xy.packages.macports.org
     206    Redirect 301 /pub/macports/distfiles http://abc.xy.distfiles.macports.org
     207}}}
     208
     209Place these directives inside the `VirtualHost` directives for each hostname from which you were serving the files at the old URLs, or use an include file.
     210
     211=== Sample nginx configuration
     212
     213This sample configuration can be used to serve MacPorts files with nginx.
     214
     215{{{
     216types {
     217    application/macbinhex-40 hqx;
     218    application/octet-stream bin exe rmd160;
     219    application/x-7z-compressed 7z;
     220    application/x-apple-diskimage dmg image img smi;
     221    application/x-bzip2 bz2 tbz tbz2;
     222    application/x-compress Z;
     223    application/x-gzip gz tgz;
     224    application/x-iso9660-image iso;
     225    application/x-lzip lz;
     226    application/x-lzma lzma tlz;
     227    application/x-rar-compressed rar;
     228    application/x-stuffit sit;
     229    application/x-stuffitx sitx;
     230    application/x-tar tar;
     231    application/x-tcl tcl;
     232    application/x-xz txz xz;
     233    application/zip zip;
     234}
     235server {
     236    listen 80;
     237    listen [::]:80;
     238    server_name abc.xy.distfiles.macports.org distfiles.macports.org;
     239    root /var/www/html/macports/distfiles;
     240    server_name_in_redirect on;
     241    autoindex on;
     242
     243    add_header Cache-Control "max-age=2592000, public";
     244    location ~ /$ {
     245        add_header Cache-Control "max-age=300, public";
     246    }
     247    location = /ports.tar.gz {
     248        add_header Cache-Control "max-age=1800, public";
     249    }
     250}
     251server {
     252    listen 80;
     253    listen [::]:80;
     254    server_name abc.xy.packages.macports.org packages.macports.org;
     255    root /var/www/html/macports/packages;
     256    server_name_in_redirect on;
     257    autoindex on;
     258
     259    add_header Cache-Control "max-age=2592000, public";
     260    location ~ /$ {
     261        add_header Cache-Control "max-age=300, public";
     262    }
     263}
     264}}}
     265
     266If you are serving MacPorts files from subdirectories on any of your hostnames, use `return` directives inside a `location` directive to redirect those requests to their new locations. For example, these directives show how to redirect requests for !http://hostname/pub/macports/packages/... to !http://abc.xy.packages.macports.org/... and requests for !http://hostname/pub/macports/distfiles/... to !http://abc.xy.distfiles.macports.org/...:
     267
     268{{{
     269    location ^~ /pub/macports/packages(/.*)?$ {
     270        return 301 http://localhost.packages.macports.org$1;
     271    }
     272    location ^~ /pub/macports/distfiles(/.*)?$ {
     273        return 301 http://localhost.distfiles.macports.org$1;
     274    }
     275}}}
     276
     277Place these directives inside the `server` directives for each hostname from which you were serving the files at the old URLs, or use an include file.
     278
     279=== Sample rsyncd configuration
     280
     281{{{
     282TODO
     283}}}