樹莓派配置Squid作為網路代理伺服器
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.
Install Squid:
Enter the following in the shell
sudo apt-get install squid3
Configuring Squid:
Backup the Squid config file:
注意:可能安裝後無squid3資料夾,只有squid資料夾,則以下所有涉及squid3的都改為squid。
sudo cp /etc/squid3/squid.conf /etc/squid3/squidoriginal.conf.bak
sudo cp /etc/squid/squid.conf /etc/squid/squid.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 #
http_access deny all 改為 http_access allow all
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
Maximum_object_size_in_memory 8192 KB
#Cache_dir ufs /var/spool/squid3 = 8192 16 256 此設定如硬碟空間太小,可關閉,僅將樹莓派作為網路代理時,無需開啟。
Backup the squid config file and restart the Squid service:
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 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.
Summary:
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).