Posts: 1
Joined: Sun Nov 16, 2014 3:44 pm

HOWTO Set up the Raspberry Pi as proxy cache

Sun Nov 16, 2014 4:01 pm


I wrote a little guide on how to set up squid on a raspberry pi as proxy cache.

First of all we need to find a storage device for the cache to stay on, this can also be your sd card.
I'll be using a 16GB thumb drive, but a larger thumb drive or spinning disk is even better.
Also if you have a NAS, you could create a NFS share and mount it on your Pi.

I'll be formatting the thumb drive as XFS, as of that tends to be slightly faster.
If you choose to use a spinning drive you can make a cronjob that will perform a defrag once in a while.

My thumb drive can reach the following speeds:
Minimum read: 17MB/s
Maximum read: 21MB/s

Minimum write: 1MB/s
Maximum write: 14MB/s

Remove all partitions from the usb flash drive and create a partition layout. I'll be using a single partition.
Warning: make sure you replace sdb with the right device name. (find the right one with sudo fdisk -l)

sudo fdisk /dev/sdb

If you like me will be using XFS as filesystem, you'd probably will have to install the tools first.

sudo apt-get install xfsprogs

Now format the partition as XFS:

sudo mkfs.xfs /dev/sdb1

Now insert the usb thumb drive to the raspberry pi (if you were executing these commands on your workstation).
We will have to mount the drive now using fstab, so that every time the system boots up the thumb drive will be mounted automatically.
Find the partition you want to use as cache partition using the blkid command and copy the UUID string.

sudo blkid

Once copied you can open up /etc/fstab in your favourite text editor.

sudo vi /etc/fstab

At the bottom of the file add:

UUID=496e98ef-dd6f-4591-bfcc-33d83083720e /mnt/squidcache xfs defaults,noatime 0 0

Now install xfsprogs and squid:
sudo apt-get install xfsprogs squid

Create the mountpoint and give it the right permissions:

sudo mkdir -p /mnt/squidcache
sudo chown -hR proxy:proxy /mnt/squidcache

Now it's time to mount the partition:
sudo mount -a

Now the proxy is running and you should be able to connect from your client on port 3128.
As you see all traffic is being blocked. We will have to allow the traffic and make some other changes.

Search for the following strings in /etc/squid/squid.conf:
http_access allow localnet -> uncomment
cache_dir ufs -> uncomment and change /var/spool* to /mnt/squidcache and 100 to the amount of MB you want to allow squid to cache on the thumb drive.
maximum_object_size -> set to something you think is appropriate, I set it very high, to 4700MB.

Reboot squid:
sudo service squid restart

After setting up the proxy I was able to get cached objects transfered with a speed of 40-43Mbit/s instead of 8Mbit/s.
The bottleneck is the CPU, maxing out at 100% while using the proxy from one client.

The Raspberry Pi could act very well as a caching proxy and is useful for people having slow internet speeds and having a few clients on the network.
If you want to get passed that 40Mbit limit, you should get something more powerful, in terms of CPU power mainly.

Posts: 6
Joined: Sun Nov 03, 2013 10:19 pm

Re: HOWTO Set up the Raspberry Pi as proxy cache

Wed Feb 18, 2015 6:32 am

Thanks, I'm going to set this up to cache windows updates for my small computer repair business.
What a good excuse to buy the new Pi :D

Posts: 1
Joined: Thu Nov 19, 2015 12:50 pm

Re: HOWTO Set up the Raspberry Pi as proxy cache

Thu Nov 19, 2015 12:56 pm

A very clear proceedure, but I am coming across a perhaps unrelated issue....I have followed your proceedure up the point of mounting all.....sudo mount -a........at which point I get the message "mount: unrecognized service". That's a showstopper.....can any light be shed ?? Thanks

Posts: 1
Joined: Wed Mar 16, 2016 2:11 pm

Re: HOWTO Set up the Raspberry Pi as proxy cache

Wed Mar 16, 2016 2:14 pm

May be a bit late but that mount -a is not necessarily a stopper. If you leave you cache location as the default /var/spool (?) then that part command can be skipped.

Maybe try that just to get the proxy running as is, then figure out why the mount is not working.


User avatar
Posts: 5
Joined: Tue Apr 26, 2016 5:18 pm
Contact: Website

Re: HOWTO Set up the Raspberry Pi as proxy cache

Tue Apr 26, 2016 5:21 pm

Thank you for sharing your knowledge. :geek:

Return to “Networking and servers”