Mirror

From CSCWiki
Revision as of 13:45, 20 December 2024 by Y266shen (talk | contribs) (→‎Writing Mirror News & Banner)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The Computer Science Club runs a public mirror (mirror.csclub.uwaterloo.ca) on potassium-benzoate.

We are listed on the ResNet "don't count" list, so downloading from our mirror will not count against one's ResNet quota.

Software Mirrored

A list of current archives (and their respective disk usage) is listed on our mirror's homepage at mirror.csclub.uwaterloo.ca.

Mirroring Requests

Requests to mirror a particular distribution or archive should be made to syscom@csclub.uwaterloo.ca.

Implementation Details

Syncing

Storage

All of our projects are stored on an 8x18TB disk raidz2 array (cscmirror0). There is an additional drive acting as a hot-spare.

  • /mirror/root/.cscmirror0

Each project is given a filesystem the pool. Symlinks are created /mirror/root to point to the correct pool and file system.

Merlin

Project synchronization is done by "merlin" which is a Go rewrite of the Python script "merlin" originally written by a2brenna.

The program is stored in ~mirror/merlin and is managed by the systemd unit merlin-go.service.

The config file merlin-config.ini contains the list of repositories along with their configurations.

To view the sync status, execute ~mirror/merlin/cmd/arthur/arthur status. To force the sync of a project, execute ~mirror/merlin/cmd/arthur/arthur sync:PROJECT_NAME.

Remark: For syncing Debian repositories we were requested to use ftpsync which has configs in ~mirror/ftpsync.

Push Sync

Some projects support push syncing via SSH.

We are running a special SSHD instance on mirror.csclub.uwaterloo.ca:22. This instance has been locked down, with the following settings:

  • Only SSH key authentication
  • Only users of the push group (except mirror) are allowed to connect
  • X11 Forwarding, TCP Forwarding, Agent Forwarding, User RC and TTY are disabled
  • Users are chrooted to /mirror/merlin

Most projects will connect using the push user. The SSH authorized keys file is located at /home/push/.ssh/authorized_keys. An example entry is:

restrict,no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty,command="arthur sync:ubuntu >/dev/null 2>/dev/null </dev/null &",from="XXX.XXX.XXX.XXX" ssh-rsa ...

Sync Scripts

Our collection of synchronization scripts are located in ~mirror/bin. They currently include:

  • csc-sync-apache
  • csc-sync-debian
  • csc-sync-debian-cd
  • csc-sync-gentoo
  • csc-sync-ssh
  • csc-sync-standard

Most of these scripts take the following parameters:

local_dir rsync_host rsync_dir

HTTP(s)

We use nginx as our webserver.

Index

An index of the archives we mirror is available at mirror.csclub.uwaterloo.ca.

As of Spring 2023, it is now generated by Hugo.

~mirror/mirror-index/deploy.sh is scheduled in /etc/cron.d/csc-mirror to be run every minute.

The script will first run synctask2project, which pull project synchronization status from Merlin (using merlin's socket), combine sub-projects (for example racket is a combination for two merlin tasks, plt-bundles and racket-installers) and read the size of the project using zfs list -Hp. This Python script then spits out a json file to data/sync.json. Hugo then read the json file and generate the HTML table based on it. The table part is also generated separately into public/project_table/index.html, which can be read by htmx (JS library used on index page) to achieve live reload on sync status. Finally, the generated product of Hugo is copied to mirror root for display by nginx.

Project information is located at synctask2project/config.toml (NOT the config.toml in the root folder! That's the config for Hugo). Its format is as follows:

merlin_sock = "/path/to/merlin/socket"
zfs_pools = ["mirror_zfs_pool1", "mirror_zfs_pool2"]

[project_name]
# This is supposed to be the short version shown on the website
# Mandatory field
site = "project.site"
# The full URL
# Mandatory field
url = "https://full.project.site"
# We are the upstream or archived project. Don't show sync error or last sync time
# Optional. Default: no
upstream = yes 
# If this project contains multiple merlin sync tasks, list them here
# Optional. Default: project_name
merlin-tasks = ["task1", "task2"]


# define more projects below...

The mirror-index also supports news. When adding new projects or making modifications, create a markdown file in mirror-index/content/news/ to tell the user what was changed. It should be picked up by Hugo automatically on next generation.

On first setup, run setup.sh. When doing development (like change the sass or static files), run build.sh to build assets.

FTP

UPDATE: We now use vsftpd instead. See /etc/vsftpd.conf for details. Official documentation can be found here.

We use proftpd (standalone daemon) as our FTP server.

To increase performance, we disable DNS lookups in proftpd.conf:

UseReverseDNS           off
IdentLookups            off

We also limit the amount of CPU/memory resources used (e.g. to minimize Globbing resources):

RLimitCPU               session 10
RLimitMemory            session 4096K

We allow a maximum of 500 concurrent FTP sessions:

MaxInstances            500
MaxClients              500

The contents of /mirror/root/include/motd.msg are displayed when a user connects.

rsync

We use rsyncd (standalone daemon).

We disable compression and checksumming in rsyncd.conf:

dont compress = *
refuse options = c delete

The contents of /mirror/root/include/motd.msg are displayed when a user connects.

Mirror Administration

Making changes

Everything in the ~mirror is managed by git (so a monorepo containing all sub-projects like Merlin and mirror-index). To make changes, switch to the mirror user and commit with --author "FirstName LastName <email@csc> to show who made the change. Then run git push to push the changes. The remote is using the HTTPS URL, so just enter your CSC credentials.

Writing Mirror News & Banner

You can add news by putting a Markdown file into ~mirror/mirror-index/content/news. A minimal post looks like this:

+++
title = "New mirror index page"
date = "2023-05-04"
+++

We've updated the mirror index page to include more detailed synchronization status information.

If you experienced any usability issues due to browser compatibility, please let us know on [syscom@csclub.uwaterloo.ca](syscom@csclub.uwaterloo.ca).

You can also put up a big banner on the front page for notifying critical information. Just edit ~mirror/mirror-index/config.toml:

[params]
banner = true
# Supported options: blue orange red
banner_color = "orange"
banner_title = "Scheduled Downtime"
# You can write markdown here
banner_text = "CSC Mirror will be down on Dec 22, 2024 from 7am to 4pm (EST/UTC-5). [More](/news/dec-22-2024-scheduled-downtime/)"

And once the incident is over just set banner to be false.

Adding a new project

  1. Find the instructions for mirroring the project. Ideally, try to sync directly from the project’s source repository.
    • Note that some projects provide sync scripts, however we generally won’t use them. We will instead use our custom ones.
  2. Create a zfs filesystem to store the project in:
    • zfs create cscmirror0/$PROJECT_NAME
  3. Change the folder ownership
    • chown mirror:mirror /mirror/root/.cscmirror0/$PROJECT_NAME
  4. Create the symlink in /mirror/root
    • ln -s .cscmirror0/$PROJECT_NAME $PROJECT_NAME (NOTE: The symlink must be relative to the /mirror/root directory. If it isn’t, the symlinks will not work when chrooted)
  5. Repeat the above steps on mirror-phys. sudo ssh mirror-dc on potassium-benzoate [NOTE: This machine is currently unavailable]
  6. Configure the project in merlin (~mirror/merlin/merlin-config.ini)
    • Select the appropriate sync script (typically csc-sync-standard) and supply the appropriate parameters
  7. Restart merlin: systemctl restart merlin-go
    • This will kick off the initial sync
    • Check ~mirror/merlin/log/$PROJECT_NAME for errors, ~mirror/merlin/log-$PROTOCOL/$PROJECT_NAME-*.log for transfer progress
  8. Configure the project in zfssync.yml (~mirror/merlin/zfssync.yml) [NOTE: The backup machine is currently unavailable, so this step is not currently needed]
  9. Update the mirror index configuration (~mirror/mirror-index-ng/synctask2project/config.toml)
  10. Add the project to rsync (/etc/rsyncd.conf)
    • Restart rsync with systemctl restart rsync

If push mirroring is available/required, see Push Sync.

Rename project

  1. Change project name (title) and local_dir in merlin-config.ini
  2. Change zfs dataset name
    • zfs rename cscmirror0/OLD_NAME cscmirror0/NEW_NAME
  3. Reload merlin config
    • systemctl reload merlin-go.service
  4. Remove old symlink and create new symlink in mirror root
    • rm OLD_DIR
    • ln -s .cscmirror0/NEW_DIR NEW_DIR
  5. Add a symlink for the old name (in /mirror/root) so that existing users won't be broken by the change
    • ln -s NEW_DIR OLD_DIR
  6. Update the rsync daemon
    • Edit /etc/rsyncd.conf, adding a new entry for the new name (keep the old name too). Restart with systemctl restart rsync
  7. Modify index page generator config
    • At ~mirror/mirror-index-ng/synctask2project/config.toml
  8. Update an mirror registrations with the project to ensure the new URLs are used

Secondary Mirror

The School of Computer Science's CSCF has provided us with a secondary mirror machine located in DC. This will limit the downtime of mirror.csclub in the event of an outage affecting the MC machine room.

As of June 2023, CSCF mirror is down. CSCF is planing to bring it back with new hardware but no ETA.

Keepalived

Mirror's IP addresses (129.97.134.71 and 2620:101:f000:4901:c5c::f:1055) have been configured has VRRP address on both machines. Keepalived does the monitoring and selecting of the active node.

Potassium-benzoate has higher priority and will typically be the active node. A node's priority is reduced when nginx, proftpd or rsync are not running. Potassium-benzoate starts with a score of 100 and mirror-dc starts with a priority of 90 (higher score wins).

When nginx is unavailable (checked w/ curl), the priority is reduced by 20. When proftpd is unavailable (checked with curl), the priority is reduced by 5. When rsync is unavailable (checking with rsync), the priority is reduced by 15.

The Systems Committee should received an email when the nodes swap position.

Project synchronization

Only potassium-benzoate is configure with merlin. mirror-dc has the software components, but they are probably not update to date nor configured to run correctly.

When a project sync is complete, merlin will kick off a custom script to sync the zfs dataset to the other node. These scripts live in /usr/local/bin and in ~mirror/merlin.