树莓派配置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 #

树莓派配置Squid作为网络代理服务器_第1张图片

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

树莓派配置Squid作为网络代理服务器_第2张图片

Find: #dns_v4_first off remove # and change off to on.

树莓派配置Squid作为网络代理服务器_第3张图片

Cache_mem 256 MB

树莓派配置Squid作为网络代理服务器_第4张图片

Maximum_object_size 4096 MB

树莓派配置Squid作为网络代理服务器_第5张图片

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

squid conf 8.png

 
  

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.:

树莓派配置Squid作为网络代理服务器_第6张图片

From the shell enter these commands in turn:

sudo wget http://www.webmin.com/download/deb/webmin-current.deb
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).

树莓派配置Squid作为网络代理服务器_第7张图片

In webmin; you’ll be able to adjust Squid settings through webmin.  Look under servers; Squid proxy server.

树莓派配置Squid作为网络代理服务器_第8张图片

 

Configuring the client:

Set windows browser proxy: Enter the ip address of the Raspberry Pi (192.168.5.250) and port 3128. Restart browser.

树莓派配置Squid作为网络代理服务器_第9张图片

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.

hit log.png

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).


你可能感兴趣的:(树莓派)