VMmanager 5 KVM: Administrator guide

Speed up OS installation using a caching proxy-server

A caching proxy-server allows to speed up the installation of GNU/Linux, FreeBSD. It caches packages that are downloaded from the mirrors and repositories during OS installation.

We recommend that you use squid as a caching proxy server. 

View details

Installing and configuring squid on CentOS7

Install squid:

yum install squid.x86_64
systemctl enable squid.service

The configuration file is /etc/squid/squid.conf.

Restart squid to apply the changes:

systemctl restart squid.service
Note
Allow connections to the squid TCP port in your firewall settings. By default squid uses port 3128/TCP.

squid 3.5 configuration file by default looks like the following: 

Squid configuration file
[root@test squid]# cat /etc/squid/squid.conf
#
# Recommended minimum configuration:
#

# Example rule allowing access from your local networks.
# Adapt to list your (internal) IP networks from where browsing
# should be allowed
acl localnet src 10.0.0.0/8    # RFC1918 possible internal network
acl localnet src 172.16.0.0/12    # RFC1918 possible internal network
acl localnet src 192.168.0.0/16    # RFC1918 possible internal network
acl localnet src fc00::/7       # RFC 4193 local private network range
acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines

acl SSL_ports port 443
acl Safe_ports port 80        # http
acl Safe_ports port 21        # ftp
acl Safe_ports port 443        # https
acl Safe_ports port 70        # gopher
acl Safe_ports port 210        # wais
acl Safe_ports port 1025-65535    # unregistered ports
acl Safe_ports port 280        # http-mgmt
acl Safe_ports port 488        # gss-http
acl Safe_ports port 591        # filemaker
acl Safe_ports port 777        # multiling http
acl CONNECT method CONNECT

#
# Recommended minimum Access Permission configuration:
#
# Deny requests to certain unsafe ports
http_access deny !Safe_ports

# Deny CONNECT to other than secure SSL ports
http_access deny CONNECT !SSL_ports

# Only allow cachemgr access from localhost
http_access allow localhost manager
http_access deny manager

# We strongly recommend the following be uncommented to protect innocent
# web applications running on the proxy server who think the only
# one who can access services on "localhost" is a local user
#http_access deny to_localhost

#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
#

# Example rule allowing access from your local networks.
# Adapt localnet in the ACL section to list your (internal) IP networks
# from where browsing should be allowed
http_access allow localnet
http_access allow localhost

# And finally deny all other access to this proxy
http_access deny all

# Squid normally listens to port 3128
http_port 3128

# Uncomment and adjust the following to add a disk cache directory.
#cache_dir ufs /var/spool/squid 100 16 256

# Leave coredumps in the first cache dir
coredump_dir /var/spool/squid

#
# Add any of your own refresh_pattern entries above these.
#
refresh_pattern ^ftp:        1440    20%    10080
refresh_pattern ^gopher:    1440    0%    1440
refresh_pattern -i (/cgi-bin/|\?) 0    0%    0
refresh_pattern .        0    20%    4320

Main parameters of the squid configuration file

View details

ACL

Access control list  (ACL) is used for access management.

Access lists in the squid configuration files are specified as: 

acl aclname acltype argument ...
acl aclname acltype "file" ...
View details


Main types of access subjects:

  1. acltype = src.
    acl localnet src <network_address>/<network mask> — a list of IP addresses as the access object.
  2. acltype = port.
    acl SSL_ports port <port or range of ports> — a list of ports as the access object.
  3. acltype = method.
    acl CONNECT method <method> — HTTP-request method {GET, POST, CONNECT...}.

HTTP_ACCESS

Access operations in the squid configuration files are specified as follows: 

http_access allow|deny [!]aclname ...
View details

Example:

    • http_access allow localnet — allow access for localnet;
    • http_access deny CONNECT !SSL_ports — deny CONNECT to all ports except for SSL;
    • http_access deny all — deny access for all.

The rules are checked one by one as they are added in the configuration file until a rule for the access subject is found. If the access operations are not specified in the configuration file, the access request will be denied. If there are no "access" lines present, the default is to deny the request.   If none of the "access" lines cause a match, the default is the opposite of the last line in the list. If the last line was denied, the default is allowed. Conversely, if the last line is allowed, the default will be denied. We recommend that you have a "deny all" entry at the end of your access lists to avoid potential confusion. 

HTTP_PORT

IP addresses of the sockets on which  squid will wait for requests from HTTP-clients are specified as follows: 

http_port <port> [mode] [options]
http_port <hostname>:<port> [mode] [options]
http_port <IP-address>:<port> [mode] [options]

E.g., http_port 3128

CACHE_DIR

By default, cache is stored only in memory. To store cache on a disk, you need to add the cache_dir parameter in the configuration file:

cache_dir Type Directory-Name Fs-specific-data [options]
View details

For "ufs":

cache_dir Type Directory-Name Mbytes L1 L2 [options]
View details

COREDUMP_DIR

By default, Squid Squid doesn't change its current directory at startup. To use a specific directory, you need to add the coredump_dir parameter into the configuration file: 

coredump_dir Directory-Name
View details

E.g., coredump_dir /var/spool/squid.

REFRESH_PATTERN

The refresh_pattern parameters allow defining whether data in the cache are fresh or stale. When accessing the old cache data, they are synchronized with the data of the original source. Refresh_pattern are specified in the configuration file as follows: 

refresh_pattern [-i] regex min percent max [options]
View details

Processing  refresh_pattern starts the algorithm. The first entry which matches is used.

FRESH if expire > now, else STALE
STALE if age > max
FRESH if lm-factor < percent, else STALE
FRESH if age < min
else STALE

The cache object is considered:

1. With the explicit expiry time:

    1. Fresh, if it has not expired yet.
    2. Otherwise, it is considered stale. 

2. Stale, if its age has exceeded the maximum period;

3. Fresh, if its age doesn't exceed the specified number of % of the object lifetime. 

4. Fresh, if its age is less than the minimum expiry time.

5. Stale.

E.g., refresh_pattern ^gopher: 1440 0% 1440.

Check squid


  1. Download a file using wget through proxy, e.g.:

    http_proxy=http://127.1.1.1:3128/ wget -O /dev/null http://ftp.freebsd.org/pub/FreeBSD/ports/ports/ports.tar.gz
  2. View the squid log in /var/log/squid/access.log. Make sure that the following record exists:

    1381394282.324 12352 1.1.1.1 TCP_MISS/200 52127893 GET http://ftp.freebsd.org/pub/FreeBSD/ports/ports/ports.tar.gz - DIRECT/2001:6c8:130:800::4 application/x-gzip
  3. when you download the file for the second time "TCP_MISS" must be changed into "TCP_HIT" or "TCP_HIT_MEM", e.g.:

    1381394328.563 235 1.1.1.1 TCP_HIT/200 52127902 GET http://ftp.freebsd.org/pub/FreeBSD/ports/ports/ports.tar.gz - NONE/- application/x-gzip

VMmanager configuration

Navigate to Cluster settings → PolicyHTTP proxy for IPv4 or HTTP proxy for IPv6. Enter an IPv4–address in the following format: http://<IP>:<Port>/, e.g. http://127.1.1.1.1:3128/. Enter an IPv6–address in the following format: http://[<IP>]:<Port>/, e.g. http://[1111:2222:3333::4444]:3128/. Enter a real IP-address to which virtual machines can connect. If the proxy is set up on the server with the control panel, you cannot specify the loopback-address as a parameter, as this IP must be accessible from any cluster node.