Archival Notice
This guide was consolidated from historical administration records compiling early Squid release tarballs on RHEL and managing FreeBSD pf firewall rules. Please verify compilation build arguments (./configure) against your active software version.
Building high-capacity caching proxy servers across enterprise campus environments (such as caching pools in east-dc1 or west-dc1) requires compiling Squid from source with optimized cache replacement policies (heap, lru) and delay pool throttling support. Installing basic distribution binary packages often excludes essential networking parameters.
In this proxy engineering masterclass, I explore how to write custom compilation bash scripts for Squid, perform fast cache directory flushing via direct partition formatting, and clear caching tables on FreeBSD behind packet filters (pf.conf).
Part 1: Automated Bare-Metal Squid Build Script (squidinstall)
To deploy identical Squid server configurations across unconfigured Linux edge routers without manual compilation input, run the custom automation script squidinstall.
Deploy the following script within your working source folder /root/squid/squidinstall.sh:
#!/bin/bash
# /root/squid/squidinstall.sh
# Enterprise compilation script for bare-metal Squid gateways
echo "Initializing System Directory Structures..."
mkdir -p /usr/local/squid
mkdir -p /var/log/squid
echo "Generating Protected Service Identity Accounts..."
groupadd squid
useradd -g squid -d /dev/null -s /bin/false squid
echo "Executing Custom Source Build Directives..."
cd /root/squid
./configure --prefix=/usr/local/squid --exec-prefix=/usr/local/squid --enable-delay-pools --enable-poll --disable-ident-lookups --enable-cache-digests --enable-removal-policies=heap,lru --enable-arp-acl
make
make install
echo "Allocating Storage Spools and Cache Filesystems..."
touch /var/log/squid/access.log
touch /var/log/squid/cache.log
chown -R squid:squid /var/log/squid/access.log
chown -R squid:squid /var/log/squid/cache.log
mkdir -p /cache
chown -R squid:squid /cache
echo "Compilation process successful. Deploy configuration profiles in /root/squid/etc."
Part 2: Lightning-Fast Storage Cache Purging (mkfs)
During caching storage corruption or severe disk space exhaustion, deleting millions of individual cache chunk files using recursive file removal (rm -rf) takes hours. To clear caching partitions in seconds, unmount and format the underlying dedicated storage volume directly.
# Gracefully terminate proxy listening background processes
killall squid
# Check active disk mount identities
df -h
umount /cache
Invoke direct filesystem block formatting against the underlying storage volume partition (such as /dev/sda8):
# Reformat partition with fresh journaled ext3 structures
mkfs.ext3 /dev/sda8
# Remount cache path and reset storage group ownership
mount /dev/sda8 /cache
chown -R squid:squid /cache
Initialize new swap directory cache structures and restart proxy daemons:
# Verify and initialize clean swap structures
/usr/local/squid/sbin/squid -z
/usr/local/squid/sbin/squid
Part 3: FreeBSD Transparent Cache Flushing (pf.conf)
When clearing Squid cache hierarchies on FreeBSD gateway platforms operating behind Packet Filter (pf), temporarily decouple web forwarding rules before running directory cleanups.
vi /etc/pf.conf
Comment out the active NAT redirection port forwarding instruction string:
# Temporarily bypass transparent HTTP port interception
# rdr on $int_if proto tcp from $lan_net to port 80 -> 127.0.0.1 port 9723
Reload running packet filtering daemons and clear persistent proxy storage blocks:
# Apply updated firewall configurations instantly
/etc/rc.d/pf reload
# Terminate daemons and scrub storage chunks
killall squid
cd /cache
rm -rfv *
# Re-establish storage index trees
/usr/local/squid/sbin/squid -z
/usr/local/squid/sbin/squid -D
Caching Verified
Your bare-metal Squid proxy servers are successfully compiled with advanced replacement policies and operating perfectly under optimal storage parameters!