Professional Documents
Culture Documents
Programster's Blog
Tutorials focusing on Linux, programming, and open-source
The tutorial below will show you how to con gure a CentOS 7 server with Nginx to act as a mirror
for other CentOS 7 servers.
Steps
First we need to update and install all the necessary packages.
Now we are going to con gure Nginx to use the location we just created. Replace the contents of
/etc/nginx/nginx.conf with:
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
https://blog.programster.org/centos-7-create-centos-7-mirror 1/7
1/23/2019 CentOS 7 - Create CentOS 7 Mirror | Programster's Blog
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
}
Copy to clipboard
server {
listen 80;
server_name localhost;
root /var/www/html/repos;
location / {
autoindex on;
}
}
Copy to clipboard
createrepo /var/www/html/repos/centos/7/os/x86_64/
createrepo /var/www/html/repos/centos/7/updates/x86_64/
Copy to clipboard
Now we need to fetch the data for the mirror. Go to the CentOS mirrors list and pick the mirror
closest to you that has an rsync address (6th column in the table). For me, I am going to use
Bytemark since I am in the United Kingdom.
rsync://mirror.bytemark.co.uk/centos
Copy to clipboard
https://blog.programster.org/centos-7-create-centos-7-mirror 2/7
1/23/2019 CentOS 7 - Create CentOS 7 Mirror | Programster's Blog
Take the given url, and add the following to the end of it:
/7/os/x86_64/
/7/updates/x86_64/
Copy to clipboard
#!/bin/bash
/usr/bin/rsync -avz --delete --exclude='repo*' \
rsync://mirror.bytemark.co.uk/centos/7/os/x86_64/ \
/var/www/html/repos/centos/7/os/x86_64/
/usr/bin/createrepo --update \
/var/www/html/repos/centos/7/os/x86_64/
/usr/bin/createrepo --update \
/var/www/html/repos/centos/7/updates/x86_64/
Copy to clipboard
Now con gure the cron service to call that script from at midnight every day by executing
crontab -e and adding the following line:
https://blog.programster.org/centos-7-create-centos-7-mirror 3/7
1/23/2019 CentOS 7 - Create CentOS 7 Mirror | Programster's Blog
Configure SELinux
If you are running selinux and you don't want to disable it, then run the following command to
have selinux allow nginx to serve content from /var/www
[base]
baseurl=http://centos-mirror.programster.org/centos/$releasever/os/$basearch/
...
[updates]
baseurl=http://centos-mirror.programster.org/centos/$releasever/updates/$basearch/
...
Copy to clipboard
https://blog.programster.org/centos-7-create-centos-7-mirror 4/7
1/23/2019 CentOS 7 - Create CentOS 7 Mirror | Programster's Blog
References
Deviantengineer.com - Install your own local Repo server for CentOS 7
Tecmint - How to Setup a Network Repository to Install or Update Packages – Part 11
StackOver ow - Nginx 403 forbidden for all les
LOG IN WITH
OR SIGN UP WITH DISQUS ?
Name
https://blog.programster.org/centos-7-create-centos-7-mirror 5/7
1/23/2019 CentOS 7 - Create CentOS 7 Mirror | Programster's Blog
✉ Subscribe d Add Disqus to your siteAdd DisqusAdd 🔒 Disqus' Privacy PolicyPrivacy PolicyPrivacy
We are a participant in the Amazon Services LLC Associates Program, an af liate advertising
program designed to provide a means for us to earn fees by linking to Amazon.com and
af liated sites. More info.
https://blog.programster.org/centos-7-create-centos-7-mirror 6/7
1/23/2019 CentOS 7 - Create CentOS 7 Mirror | Programster's Blog
https://blog.programster.org/centos-7-create-centos-7-mirror 7/7