Package Proxy Cache

From ArchWiki
Revision as of 12:35, 16 December 2011 by Kynikos (talk | contribs) (update templates, see Help:Style)
Jump to: navigation, search

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.

Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어

External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

If you want to install the same Arch packages over and over - like for testing AIF profiles - it could help if you wouldn't have to get the packages every time from the internet. This article shows you how to setup a Squid proxy that only caches arch packages and can be used with aif/pacman/wget/etc with minimal configuration on the client system.

Install Squid

# pacman -S squid

Configure Squid

This is the minimum configuration to get squid cache arch packages.

Cache Rules

Before defining these rules, remove/comment (if you do not need them) all the default refresh_patterns

refresh_pattern \.pkg\.tar\.   0       20%     4320      reload-into-ims
refresh_pattern .              0       0%      0

That should define that *.pkg.tar.* gets cached, and anything else should not.

Maximum Filesize

Objects larger than this size will NOT be saved on disk:

maximum_object_size 256 MB

Cache Directory

Set the cache dir and its maximum size and subdirs:

cache_dir aufs /var/cache/squid 10000 16 256

Shutdown Lifetime

Time to wait until all active client sockets are closed:

shutdown_lifetime 1 seconds 

Every time you change the cache_dir path (and after fresh install), you need to (re)create this directory:

# squid -z

and it could be helpful to check the config file before running squid:

# squid -k check

Start Squid

# /etc/rc.d/squid start

or if squid is already running:

# /etc/rc.d/squid restart

It could be helpful to check the config file before running:

# squid -k check

Follow Squid access log

To see the access to squid:

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

You should see this for packages that are directed to original host:


and for packages that are delivered from the cache:


Manual Arch Install

Before running /arch/setup, add variables for your proxy. To do so, run on the console:

# export http_proxy='http://your_squid_machine_ip:3128'
# export ftp_proxy='ftp://your_squid_machine_ip:3128'

Now just use /arch/setup to normally install the system, and it should use your proxy. Watch the squid logs to verify this.

Note: If you want to use the proxy settings in the installed system, you need to add the http_proxy and/or ftp_proxy variables in an appropriate place on the installed system. (like /etc/profile.d/

Automatic Arch Install

After login in the arch install image, setup your network (eg. `dhcpcd eth0`) and get this AIF profile on it.

Warning: This PARTITIONS AND FORMATS the defined device, so please go through the whole file before you run it!
export ftp_proxy='ftp://your_squid_machine_ip:3128'
export http_proxy='http://your_squid_machine_ip:3128'


#TARGET_PACKAGES='xorg gnome ttf-dejavu'

worker_configure_system () {
	echo "export http_proxy=$http_proxy" >> /mnt/etc/profile.d/
	echo "export ftp_proxy=$ftp_proxy" >> /mnt/etc/profile.d/
	chmod +x /mnt/etc/profile.d/
	sed -i 's/^HOSTNAME="myhost"/HOSTNAME="foohost"/' $var_TARGET_DIR/etc/rc.conf

PARTITIONS='/dev/sda *:ext4'
BLOCKDATA='/dev/sda1 raw no_label ext4;yes;/;target;no_opts;no_label;no_params'

And install the system according to that profile:

# aif -p automatic -c custom.aifprofile

Now sit back, and enjoy the automation :)

Tip: Watch the squid logs, specially that on the second run you get TCP_HIT and NONE

After the setup is done, the installed system should use your proxy for pacman/wget/etc.