I was looking to build *something* that would possibly benefit several customers that have slow or laggy internet access (ie 2mb broadband or satellite).
The solution needed to be cost effective and unobtrusive.
I did some research and decided to use Squid.
Squid (amongst other things) can cache web objects (such as images and executables), speeding up page load times and download times.
Next, I needed some hardware to run Squid on.
Squid can run on Linux and Windows computers, but i ruled out Windows as thats a paid licenced product, thus not cost effective. I also didnt want to install Squid on a desktop computer, i’d either have to buy a new computer, or re-purpose an old computer – (which can be noisy and unsightly). Both options would also consume significant amounts of energy per year, again not very cost effective.
Enter the Raspberry Pi!
I decided on the Raspberry Pi (in this case a Pi3). It fitted my requirements exactly. Low inital outlay, low running annual costs, no OS licence fee, small and quiet!
For this guide, you will need:
- Raspberry Pi 2 or 3
- 16GB micro SD card minimum (faster the better)
- 5v Micro USB charger
- CAT5e cable connected to the Pi and your Router
- Temporary use of a usb keyboard and mouse
- Temporary use of a HDMI TV / Monitor
Once you have completed the inital network configuration, you can connect to your Raspberry Pi via SSH using Putty (default login for the Raspberry Pi is pi and raspberry).
So, you’ve got your Pi plugged in, and you’ve installed Raspbian Jessie (if you’re new to Linux and the Pi family, download the NOOBs installer!), now its time to get to work.
Configure a static IP on the Pi.
Remember, unlike Windows, Linux commands are case sensitve!
This guide is based on Raspbian Jessie!
Open a shell window and type:
sudo nano /etc/dhcpcd.conf
Scroll to the end of doc and enter (use a static ip from your subnet, and change the router address to that of your own router).
#set a static ip address
interface eth0 static ip_address=192.168.5.250/24 static routers=192.168.5.254 static domain_name_servers=188.8.131.52 184.108.40.206 Press Ctrl + X to quit. Hit Y to save
Reboot the Pi for the changes to take effect
At the shell window type:
Tweaking the Pi:
Open a new shell window and enter:
Option 1, expand filesystem
Option 9, advanced config. A3 memory split. 16.
If your running a Raspberry Pi2, you’ll be able to overclock it as well!
For the changes to take effect, type:
Time to update:
Next, we want to update our Raspberry Pi with the latest patches. Open a new shell window
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade Hit Y if prompted.
Now we have a fully patched and up-to-date version of rasparian; its time to install Squid.
Enter the following in the shell
sudo apt-get install squid3
Backup the Squid config file:
sudo cp /etc/squid3/squid.conf /etc/squid3/squidoriginal.conf.bak
Edit the config file:
sudo nano /etc/squid3/squid.conf
use Ctrl + W to find each section:
http_access allow localnet = remove the #
Remove # from: acl localnet src + add ip range/cidr 192.168.5.0/24
Make sure the ip range/cidr matches your networks range
Find: #dns_v4_first off remove # and change off to on.
Cache_mem 256 MB
Maximum_object_size 4096 MB
Cache_dir ufs /var/spool/squid3 = 8192 (1st variable - this is 8192 MB) Ctrl + X and Y to save & exit.
Backup the squid config file and restart the Squid service:
sudo cp /etc/squid3/squid.conf /etc/squid3/squid.conf.bak
sudo service squid3 restart
Make managing Squid easier with Webmin:
First, install webmins prereqs; open a shell and enter:
sudo apt-get -f install
sudo apt-get -y install apache2 apache2-suexec-custom libnet-ssleay-perl libauthen-pam-perl libio-pty-perl apt-show-versions samba bind9 webalizer locate mysql-server
sudo apt-get install squid-cgi
Enter a secure password for MySQL when prompted.:
From the shell enter these commands in turn:
sudo mkdir installed-packages
sudo dpkg -i webmin-current.deb
Once Webmin has been installed; open a browser on your pc https://192.168.5.240:10000
Login using the raspberry pi login (default is pi and raspberry).
In webmin; you’ll be able to adjust Squid settings through webmin. Look under servers; Squid proxy server.
Configuring the client:
Set windows browser proxy: Enter the ip address of the Raspberry Pi (192.168.5.250) and port 3128. Restart browser.
Clear your browser cache and restart the browser. You should now be using the Squid Proxy server on your Raspberry Pi.
Check the cache log:
To check the squid cache logs, open a new shell window and enter:
sudo tail -f /var/log/squid3/access.log
Hits are items being pulled from the Squid Cache rather than the internet.
If your unlucky enough to have a slow or laggy internet connection, one possible solution for you is to build and test a Squid proxy server. However, bear in mind, your mileage may vary as not all objects are cacheable, and certainly any improvement is less noticiable on fast internet connections such as BT infinity.
I performed some “not very scientific” tests using OpenOffice.org. I found that the download speed of the OpenOffice installer on the first try was 3.9mbs, jumping to 7.9Mb/s after caching once, then maxing out at 9.8Mb/s on the second and subsequent runs (likely a limitation of the Raspberry Pi’s network card – which is limited to 100mbs).