GNU/Linux xterm-256color bash 145 views

PROCEDURE SETTING UP SQUID CACHING ON LINUX

1 INSTALL SQUID
To begin the caching setup, we first install Squid using the following command

sudo apt update && sudo apt install squid -y

This ensures that we have the latest version of Squid installed on our system.

2 CONFIGURE SQUID FOR CACHING
Once Squid is installed, we need to modify its configuration file to optimize caching. We open the file using

sudo nano /etc/squid/squid.conf

Inside this file, we ensure that the cache_dir directive is set properly. If not present, we add

cache_dir ufs /var/spool/squid 1000 16 256

This specifies that Squid should use 1GB 1000MB of cache storage. After modifying the file, we save and exit.

3 INITIALIZE AND SET PERMISSIONS FOR THE CACHE DIRECTORY
Before starting Squid, we need to ensure that the cache directory exists and has the correct permissions

sudo mkdir -p /var/spool/squid
sudo chown -R squid:squid /var/spool/squid
sudo chmod -R 750 /var/spool/squid

Then, we initialize the cache

sudo squid -z

This creates the necessary cache structure in /var/spool/squid.

4 START AND ENABLE SQUID
Now, we start the Squid service and enable it to start on boot

sudo systemctl start squid
sudo systemctl enable squid

We verify its status to ensure it is running

systemctl status squid

5 TEST SQUID CACHING
To test whether Squid is caching correctly, we send a request through the proxy

curl -v -x http://localhost:3128 http://example.com/

Then, we monitor Squid’s access logs to check for cache activity

sudo tail -f /var/log/squid/access.log

If caching is working, we should start seeing TCP_HIT entries in the logs, indicating that Squid is successfully serving cached content instead of retrieving it from the internet.

PROCEDURE BENCHMARKING SQUID PERFORMANCE

1 RUN A BENCHMARK TEST
To evaluate the caching efficiency, we perform benchmarking tests using Apache Benchmark ab. This allows us to simulate multiple requests and measure Squid’s response times.

ab -n 100 -c 10 -X localhost:3128 http://example.com/

This command tests how Squid handles a high number of requests and whether cached content is served efficiently.

2 CHECK CACHE HIT RATIO
To determine how much content is being served from the cache, we use

squidclient -p 3128 mgr:info | grep "Cache Hit Ratio"

This will return statistics showing the percentage of requests served from cache rather than fetching from the original server.

we will continue the hit ratio in the next video record

More recordings by jhamm