How to create a mirror step by step3 min read
Hey there again! So recently I went through all the steps on setting up a public mirror server, and website. The guides were not very user friendly so it took me quite some time, but eventually I got it working.. of course.
Here’s our mirror: https://mirror.hostup.org/
We currently got CentOS, OpenVZ and some other ones avaliable. If you’re a customer of ours I recommend that you switch to these mirrors for the fastest speeds. Eitherway, let’s get to it! Here’s 3 simple steps on setting up a mirror just like ours:
1. What kind of mirrors do you want?
The first step is figuring out what mirrors you want to have. Every mirror has the same installation process so I am going to take the CentOS mirror as an example. It all starts with you requiring to install a webserver and rsync.
To install Apache on a CentOS server run:
yum install httpd
If you’re using a Debian based operating system run:
apt install apache2
After you’ve installed Apache you need to edit your configs so that they support directory listing as well as allowing for .htaccess. On CentOS the configuration files are found in /etc/httpd/conf.d, however on some operating systems they may be in /etc/apache/conf.d.
Paste the following inside the newly created file
<VirtualHost *:80> ServerAdmin firstname.lastname@example.org DocumentRoot "/var/html/www" Options +Indexes ServerName mirror.domain.com ErrorLog "/var/log/httpd/domain.com.error_log" CustomLog "/var/log/httpd/domain.com.access_log" common IndexOptions FancyIndexing NameWidth=* FoldersFirst ScanHTMLTitles DescriptionWidth=* HeaderName HEADER.html ReadmeName README.html Options Indexes SymLinksIfOwnerMatch FollowSymLinks ErrorDocument 404 default </VirtualHost> <Directory /var/html/www> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory>
Next you should restart your apache for the changes to take effect, but because apache has two different names depending on whether you’re on CentOS or not, the restart command will be different too. If you’re on CentOS run the following:
service httpd restart
Otherwise run the following
service apache restart
2. Sync from another mirror
Okay, once you’ve got your webserver setup and configured you need to sync with another mirror. The tool you need to do this is called rsync, and here’s how you can install it.
For CentOS you need to run the following:
yum install rsync
For Debian/Ubuntu you need to run the following:
apt install rsync
Okay, next up we just need to start syncing. I recommend that you use a screen window to sync because it will take many hours to do this, and if your SSH connection cuts out, the sync will also stop. Just type screen in the terminal to open a new window.
Once you’re in the screen window just type the following command to start syncing:
rsync -av --delete rsync://mirror.cogentco.com/CentOS/ /var/www/centos
- /var/www/centos your webserver directory path plus directory where the files will be stored
- -v verbose mode
3. Keep your mirror updated
Once it has finished syncing it’s important to keep it updated by syncing off other mirrors. The best tool for this is using cron.
Get started by typing the following in your terminal:
Then add a new line and add the following information:
40 */4 * * * rsync -aq --delete rsync://mirror.cogentco.com/CentOS/ /var/www/centos
This will run the following command in quiet mode (-q) so that it doesn’t create huge log files for no reason. It will also run this command every 4 hours.