Introduction à Squid

Squid est un serveur web proxy qui optimise le fonctionnement du site Web en mettant les pages en cache afin qu’elles soient chargées plus rapidement, ce qui améliore le temps de réponse pour les pages que les utilisateurs visitent le plus fréquemment. Squid fournit des services de proxy et de cache pour le protocole Hypertext Transport Protocol (HTTP), le protocole FTP (File Transfer) et d'autres protocoles populaires. Squid est surtout utilisé pour accélérer un serveur web en mettant en cache des demandes répétées, aidant ainsi la sécurité par filtrage du trafic ou pour limiter l’accès des utilisateurs à des pages spécifiques.

Squid supporte les objets de données FTP, gopher, ICAP, ICP, HTCP, et HTTP.

Squid se compose :

  • d'un programme de serveur principal Squid
  • de programmes optionnels de traitement et d'authentification personnalisés
  • d'outils de gestion et d'outils clients

Installation et exécution de Squid

Le package “squid” fournit le serveur proxy de mise en cache Squid. Exécuter la commande “rpm -q squid” pour voir si le package squid est installé. Sinon, exécuter la commande suivante en tant qu'utilisateur root pour l'installer :

~]# yum install squid

Exécuter la commande “systemctl start squid” en tant qu'utilisateur root pour démarrer Squid :

~]# systemctl start squid

Squid va maintenant commencer à écouter le port 3128 (port par défaut) sur toutes les interfaces de réseau de la machine. Exécuter la commande “systemctl start squid” pour confirmer que Squid est en cours d'exécution.

En voici un exemple :

~]# systemctl status squid
● squid.service - Squid caching proxy
   Loaded: loaded (/usr/lib/systemd/system/squid.service; disabled; vendor preset: disabled)
   Active: active (running) since Wed 2016-04-06 13:15:05 CEST; 2min 17s ago
[output truncated]

Exécuter la commande “ps -eZ | grep squid” pour afficher les processus de Squid :

~]# ps -eZ | grep squid
unconfined_u:system_r:squid_t:s0 2522 ?        00:00:00 squid
unconfined_u:system_r:squid_t:s0 2524 ?        00:00:00 squid
unconfined_u:system_r:squid_t:s0 2526 ?        00:00:00 ncsa_auth
unconfined_u:system_r:squid_t:s0 2527 ?        00:00:00 ncsa_auth
unconfined_u:system_r:squid_t:s0 2528 ?        00:00:00 ncsa_auth
unconfined_u:system_r:squid_t:s0 2529 ?        00:00:00 ncsa_auth
unconfined_u:system_r:squid_t:s0 2530 ?        00:00:00 ncsa_auth
unconfined_u:system_r:squid_t:s0 2531 ?        00:00:00 unlinkd

Si vous êtes intéressés par les statistiques de Squid en environnement de ligne de commande, utiliser l'outil “squidclient” qui peut accéder au service Squid et extraire des statistiques.

Ainsi, pour obtenir des statistiques sur la performance en général, exécuter la commande suivante sur le serveur Squid :

~]# squidclient -p squid-port mgr:info

Pour stopper Squid, exécutez cette commande :

~]# systemctl stop squid

Les fichiers journaux du serveur proxy de Squid se trouvent dans le répertoire “/var/log/squid/”. Le fichier journal qui stocke des informations sur les requêtes proxy se trouve dans le fichier “/var/log/squid/access.log”.

Configuration Squid

Pour configurer Squid, ajuster les directives dans le fichier de configuration. Squid est normalement configuré selon les prérequis d'un réseau donné en ligne de commande et en modifiant le fichier de configuration Squid situé dans “/etc/squid/squid.conf”, qui contient le minimum de configurations conseillées.

Maintenant que notre Squid est installé, nous allons sauvegarde le fichier de configuration original.

~] mv /etc/squid/squid.conf /etc/squid/squid.conf.org

Créer un nouveau fichier “/etc/squid/squid.conf” avec le contenu suivant. Modifier l'ACL (de l'anglais Access Control List) à la ligne mynetwork pour définir le réseau d'origine pour votre réseau local. Il s'agit du réseau où les systèmes client utilisent le serveur de Squid comme proxy.

Note:

L'ordre des éléments qui se trouvent dans le fichier de configuration /etc/squid/squid.conf est important car Squid le lit à partir du début.

#
# Recommended minimum configuration:
#
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 all differents Safe_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
#
acl oowy.lan src 10.75.168.0/24
http_access allow oowy.lan
 
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

Démarrer le service et l'activer au démarrage :

~]#  systemctl enable squid
~]#  systemctl start squid

Si le parefeu est activé, autoriser le port de Squid.

~]#  firewall-cmd --add-port=3128/tcp --permanent

Configurer votre navigateur web pour qu'il utilise le serveur proxy.

Ajouter les lignes suivantes dans le fichier “/etc/squid/squid.conf” pour remplacer l'exemple d'adresse IP :

cache_dir ufs /var/spool/squid 500 16 256

Créer des répertoires cache par la commande suivante :

~]# systemctl restart squid

Squid commence maintenant à écouter le port 3128 (port par défaut) sur toutes les interfaces de réseau de la machine.

Configurer votre navigateur, par exemple Firefox, afin d'utiliser Squid en tant que serveur proxy HTTP avec l'hôte comme adresse IP de la machine et le port 3128.

Chaque fois que nous modifions ou mettons à jour le serveur proxy Squid, nous devons vérifier que notre fichier squid.conf est exempt d'erreurs. C'est une tâche facile.

Pour vérifier si le fichier squid.conf contient des erreurs de syntaxe et des avertissements, squid nous mets à disposition deux options intéressantes : “parse” et “reconfigure”

Pour vérifier la configuration de notre proxy squid, il suffit de faire :

# squid -k parse
2021/10/24 18:41:40| Startup: Initializing Authentication Schemes ...
2021/10/24 18:41:40| Startup: Initialized Authentication Scheme 'basic'
2021/10/24 18:41:40| Startup: Initialized Authentication Scheme 'digest'
2021/10/24 18:41:40| Startup: Initialized Authentication Scheme 'negotiate'
2021/10/24 18:41:40| Startup: Initialized Authentication Scheme 'ntlm'
2021/10/24 18:41:40| Startup: Initialized Authentication.
2021/10/24 18:41:40| Processing Configuration File: /etc/squid/squid.conf (depth 0)
2021/10/24 18:41:40| Processing: visible_hostname proxy.oowy.lan
2021/10/24 18:41:40| Processing: http_port 0.0.0.0:3128
2021/10/24 18:41:40| Processing: dns_v4_first on
2021/10/24 18:41:40| Processing: cache_mem 1024 MB
2021/10/24 18:41:40| Processing: access_log /var/log/squid/access.log combined
2021/10/24 18:41:40| Processing: acl SSL_ports port 443
2021/10/24 18:41:40| Processing: acl Safe_ports port 80          # http
2021/10/24 18:41:40| Processing: acl Safe_ports port 21          # ftp
2021/10/24 18:41:40| Processing: acl Safe_ports port 443         # https
2021/10/24 18:41:40| Processing: acl Safe_ports port 70          # gopher
2021/10/24 18:41:40| Processing: acl Safe_ports port 210         # wais
2021/10/24 18:41:40| Processing: acl Safe_ports port 1025-65535  # unregistered ports
2021/10/24 18:41:40| Processing: acl Safe_ports port 280         # http-mgmt
2021/10/24 18:41:40| Processing: acl Safe_ports port 488         # gss-http
2021/10/24 18:41:40| Processing: acl Safe_ports port 591         # filemaker
2021/10/24 18:41:40| Processing: acl Safe_ports port 777         # multiling http
2021/10/24 18:41:40| Processing: acl CONNECT method CONNECT
2021/10/24 18:41:40| Processing: http_access deny !Safe_ports
2021/10/24 18:41:40| Processing: http_access deny CONNECT !SSL_ports
2021/10/24 18:41:40| Processing: http_access allow localhost manager
2021/10/24 18:41:40| Processing: http_access deny manager
2021/10/24 18:41:40| Processing: include /etc/squid/conf.d/*.conf
2021/10/24 18:41:40| Processing Configuration File: /etc/squid/conf.d/global.conf (depth 1)
2021/10/24 18:41:40| Processing: acl WL_global dstdomain .cloudfront.net .amazonaws.com
2021/10/24 18:41:40| Processing: acl WL_global dstdomain .mariadb.org .mysql.com .mongodb.org .percona.com .postgresql.org
2021/10/24 18:41:40| Processing: acl WL_global dstdomain coregate003.as44099.net .clara.net .grita.fr .runiso.com
2021/10/24 18:41:40| Processing: acl WL_global dstdomain .docker.com .docker.io .k8s.io .kubernetes.io .quay.io
2021/10/24 18:41:40| Processing: acl WL_global dstdomain .ssl.gstatic.com .gcr.io .google.com .google.co.uk .googleapis.com .googleusercontent.com .google.fr
2021/10/24 18:41:40| Processing: acl WL_global dstdomain client.wns.windows.com .microsoft.com login.live.com .msftconnecttest.com .windowsupdate.com .windows.net .vo.msecnd.net .passport.net .powershellgallery.com .onestore.ms .s-microsoft.com
2021/10/24 18:41:40| Processing: acl WL_global dstdomain .almalinux.org .ansible.com .centos.org .debian.org .fedoraproject.org .oracle.com .redhat.com .ubuntu.com
2021/10/24 18:41:40| Processing: acl WL_global dstdomain .gnupg.net .nginx.com .nginx.org .python.org pypi.org .golang.org
2021/10/24 18:41:40| Processing: acl WL_global dstdomain .github.com .githubusercontent.com .gitlab.com .launchpad.net
2021/10/24 18:41:40| Processing: acl LAN_global src all
2021/10/24 18:41:40| Processing: http_access allow LAN_global WL_global
2021/10/24 18:41:40| Processing Configuration File: /etc/squid/conf.d/global_mirrors.conf (depth 1)
2021/10/24 18:41:40| Processing: acl WL_global_mirrors dstdomain .mirrors.ovh.net mirror.math.princeton.edu mirror.liquidtelecom.com packages.vmware.com .sury.org
2021/10/24 18:41:40| Processing: acl WL_global_mirrors dstdomain .remirepo.net ftp.pbone.net .ircam.fr .packagist.org .yarnpkg.com
2021/10/24 18:41:40| Processing: acl LAN_global_mirrors src all
2021/10/24 18:41:40| Processing: http_access allow LAN_global_mirrors WL_global_mirrors
2021/10/24 18:41:40| Processing Configuration File: /etc/squid/conf.d/global_others.conf (depth 1)
2021/10/24 18:41:40| Processing: acl WL_global_others dstdomain .clamav.net .datadoghq.com .dell.com .elasticsearch.org .eset.com .java.com .jenkins.io .jenkins-ci.org .letsencrypt.org .slack.com
2021/10/24 18:41:40| Processing: acl WL_global_others dstdomain .elastic.co .zend.com
2021/10/24 18:41:40| Processing: acl LAN_global_others src all
2021/10/24 18:41:40| Processing: http_access allow LAN_global_others WL_global_others
2021/10/24 18:41:40| Processing Configuration File: /etc/squid/conf.d/oowy_vpn.conf (depth 1)
2021/10/24 18:41:40| Processing: acl WL_oowy_vpn dstdomain .amazon.com .google.com
2021/10/24 18:41:40| Processing: acl LAN_oowy_vpn src 10.75.180.0/24
2021/10/24 18:41:40| Processing: http_access allow LAN_oowy_vpn WL_oowy_vpn
2021/10/24 18:41:40| Processing: http_access allow localhost
2021/10/24 18:41:40| Processing: http_access deny all
2021/10/24 18:41:40| Processing: coredump_dir /var/spool/squid
2021/10/24 18:41:40| Processing: refresh_pattern ^ftp:           1440    20%     10080
2021/10/24 18:41:40| Processing: refresh_pattern ^gopher:        1440    0%	1440
2021/10/24 18:41:40| Processing: refresh_pattern -i (/cgi-bin/|\?) 0     0%	0
2021/10/24 18:41:40| Processing: refresh_pattern .               0	20%     4320
2021/10/24 18:41:40| Initializing https proxy context

Nous pouvons filtrer avec un simple “grep

# squid -k parse | grep 'error'

Maintenant nous pouvons recharger notre serveur proxy squid sans redémarrer le daemon squid comme suit :

# squid -k reconfigure

Annexe

http://www.squid-cache.org/

https://access.redhat.com/documentation/fr-fr/red_hat_enterprise_linux/7/html/networking_guide/ch-squid_server

https://www.formatux.fr/formatux-services/module-090-squid/index.html

https://linuxhint.com/squid-proxy-configuration-linux/

https://gist.github.com/ypid/5484043

https://blog.last.fm/2007/08/30/squid-optimization-guide

https://meta.wikimedia.org/wiki/Squid_performance_tuning

https://www.christianschenk.org/blog/tuning-and-hardening-squid/

http://cosmolinux.no-ip.org/raconetlinux/html/17-squid.html

# Network parameters
visible_hostname proxy.oowy.lan
 
# Squid normally listens to port 3128
http_port 0.0.0.0:3128
 
# Location of the host-local IP name-address associations database.
hosts_file /etc/hosts
 
# This option reverses the order of preference to make Squid contact
# dual-stack websites over IPv4 first. Squid will still perform both
# IPv6 and IPv4 DNS lookups before connecting.
dns_v4_first on
 
# specify a list of DNS name servers : OpenDNS
dns_nameservers 208.67.222.222 208.67.220.220
 
# This stops squid from holding onto ram that it is no longer actively using.
memory_pools off
 
# 
#'cache_mem' specifies the ideal amount of memory to be used for:
#	* In-Transit objects
#	* Hot Objects
#	* Negative-Cached objects
cache_mem 1024 MB
 
# If enabled, squid will keep statistics on each client. This can become a memory hog after a while, so it’s best to keep it disabled.
client_db off
 
# Buffers the write-out to log files. This can increase performance slightly.
buffered_logs on
 
# Configures whether and how Squid logs HTTP and ICP transactions.
access_log /var/log/squid/access.log combined
 
# Deny caching for all connections
no_cache deny all
 
#
# Recommended minimum configuration:
#
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 all differents Safe_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
#
 
# Include acl
include /etc/squid/conf.d/*.conf
 
http_access allow localhost
 
# And finally deny all other access to this proxy
http_access deny all
 
# 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
cat /etc/squid/conf.d/global.conf 
# ----- Amazon
acl WL_global dstdomain .cloudfront.net .amazonaws.com 
 
# ----- BDD mariadb/mysql
acl WL_global dstdomain .mariadb.org .mysql.com .mongodb.org .percona.com .postgresql.org
 
# ----- Claranet
acl WL_global dstdomain coregate003.as44099.net .clara.net .grita.fr .runiso.com 
 
# ----- Container
acl WL_global dstdomain .docker.com .docker.io .k8s.io .kubernetes.io .quay.io
 
# ----- google 
acl WL_global dstdomain .ssl.gstatic.com .gcr.io .google.com .google.co.uk .googleapis.com .googleusercontent.com .google.fr
 
# ----- Microsoft 
acl WL_global dstdomain client.wns.windows.com .microsoft.com login.live.com .msftconnecttest.com .windowsupdate.com .windows.net .vo.msecnd.net .passport.net .powershellgallery.com .onestore.ms .s-microsoft.com
 
# ----- OpenSource
acl WL_global dstdomain .almalinux.org .ansible.com .centos.org .debian.org .fedoraproject.org .oracle.com .redhat.com .ubuntu.com 
acl WL_global dstdomain .gnupg.net .nginx.com .nginx.org .python.org pypi.org .golang.org
 
# ----- Source code
acl WL_global dstdomain .github.com .githubusercontent.com .gitlab.com .launchpad.net 
 
## ----- Apply rules
acl LAN_global src all
http_access allow LAN_global WL_global
cat /etc/squid/conf.d/global_mirrors.conf 
# ----- Opensource mirror
acl WL_global_mirrors dstdomain .mirrors.ovh.net mirror.math.princeton.edu mirror.liquidtelecom.com packages.vmware.com .sury.org
acl WL_global_mirrors dstdomain .remirepo.net ftp.pbone.net .ircam.fr .packagist.org .yarnpkg.com 
 
## ----- Apply rules
acl LAN_global_mirrors src all
http_access allow LAN_global_mirrors WL_global_mirrors
# cat /etc/squid/conf.d/oowy_vpn.conf 
#
# Create ACl for Oowy VPN users
# Date : XX/XX/XXX
 
acl WL_oowy_vpn dstdomain .amazon.com .google.com
acl LAN_oowy_vpn src 10.75.180.0/24
http_access allow LAN_oowy_vpn WL_oowy_vpn
Ce site web utilise des cookies. En utilisant le site Web, vous acceptez le stockage de cookies sur votre ordinateur. Vous reconnaissez également que vous avez lu et compris notre politique de confidentialité. Si vous n'êtes pas d'accord, quittez le site.En savoir plus