How to cache Fedora RPM’s with Squid Proxy, an easy solution

Often there are many computers on your LAN that need to be updated when a new Fedora is released or just for the usual DNF UPDATE — you don’t want to re-download all the patches and you don’t want to wait for them to be downloaded.

This is where Squid comes to the rescue — with some tweaking, it can help us cache the files, EVEN if each client decides to fetch from a different mirror.

The first thing to do is to configure Squid..
add these into /etc/squid/squid.conf :

url_rewrite_program /etc/squid/squid-urlrewrite
url_rewrite_children 20 startup=1 idle=1 concurrency=10000

This tells squid to consult with the above program whenever a request is made, and change the request to another URL if necessary.

Now download and install https://github.com/rchunping/squid-urlrewrite ,
putting the resulting binary to /etc/squid

Now create a file called /etc/squid-urlrewrite.conf and put these in it

# loglevel
# info: default
# debug: more detail info
# log messages are write to syslog
loglevel debug

# rewrite  <regexp> <target>
# redirect <regexp> [301;]<target>

# mirror template:
# rewrite ^http://somesite/somedir/fedora/linux/(.*)$     http://ftp.plusline.net/fedora/linux/$1

# Change many common mirrors to ftp.plusline.net :
rewrite ^http://fedora\.mirror\.garr\.it/fedora/linux/(.*)$	http://ftp.plusline.net/fedora/linux/$1
rewrite ^http://fedora\.mirror\.root\.lu/(.*)$	http://ftp.plusline.net/fedora/linux/$1
rewrite ^http://www\.nic\.funet\.fi/pub/mirrors/fedora.redhat.com/pub/fedora/linux/(.*)$	http://ftp.plusline.net/fedora/linux/$1
rewrite ^http://ftp\.halifax\.rwth-aachen\.de/fedora/linux/(.*)$     http://ftp.plusline.net/fedora/linux/$1
rewrite ^http://fedora\.uib\.no/fedora/linux/(.*)$     http://ftp.plusline.net/fedora/linux/$1
rewrite ^http://mirrors\.uni-ruse\.bg/fedora/linux/(.*)$     http://ftp.plusline.net/fedora/linux/$1

# rpmfusion
# ftp://mirror.proserve.nl/rpmfusion/nonfree/fedora/releases/30/Everything/x86_64/os/Packages/u/unrar-5.7.4-1.fc30.x86_64.rpm
rewrite ^ftp://mirror\.proserve\.nl/rpmfusion/(.*)$  ftp://mirror.de.leaseweb.net/rpmfusion/$1

The above file contains some mirrors that are commonly accessed by my computers. You will need to add more if your computers decide to use mirrors other than garr, root, funet or halifax. The template is simple:
rewrite ^somehost/somedir/fedora/linux/(.*)$ http://ftp.plusline.net/fedora/linux/$1

replace somehost/somedir with what you see in squid logs. The right side always stays the same.

Why plusline? Since plusline was the first one that my server picked on, I resulted using it for ALL my computers – since I did not want multiple copies of each file stored in squid.

Now that squid is ready, you can tell DNF to start using it.. On each computer on your LAN, add this to the /etc/dnf/dnf.conf file:

proxy=http://192.168.1.11:3300

This assumes that your squid lives on 192.168.1.11 and is listening to port 3300.

Thats it.. when you do a dnf update or dnf system-upgrade, it should use the squid.. In the squid logs, you should see an access to the ftp.plusline site.. if you see other sites, STOP the dnf, edit /etc/squid-urlrewrite.conf and add that mirror to that file as well.. restart squid, restart dnf..

This entry was posted in Off Off - Turkish. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *