Squid - Optimizing Web Delivery

mail

Ipc::Mem::Segment::create failed to shm_open(/squid-cf__metadata.shm): (17) File exists

Situation

systemctl restart squid; systemctl -l status squid

Job for squid.service failed because the control process exited with error code. See "systemctl status squid.service" and "journalctl -xe" for details.
 squid.service - Squid caching proxy
   Loaded: loaded (/usr/lib/systemd/system/squid.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Fri 2017-09-22 15:32:50 CEST; 6ms ago
  Process: 24042 ExecStop=/usr/sbin/squid -k shutdown -f $SQUID_CONF (code=exited, status=0/SUCCESS)
  Process: 26536 ExecStart=/usr/sbin/squid $SQUID_OPTS -f $SQUID_CONF (code=exited, status=1/FAILURE)
  Process: 26530 ExecStartPre=/usr/libexec/squid/cache_swap.sh (code=exited, status=0/SUCCESS)
 Main PID: 23577 (code=killed, signal=TERM)

Sep 22 15:32:50 isbinfrepo systemd[1]: Starting Squid caching proxy...
Sep 22 15:32:50 isbinfrepo squid[26536]: Ipc::Mem::Segment::create failed to shm_open(/squid-cf__metadata.shm): (17) File exists
Sep 22 15:32:50 isbinfrepo systemd[1]: squid.service: control process exited, code=exited status=1
Sep 22 15:32:50 isbinfrepo systemd[1]: Failed to start Squid caching proxy.
Sep 22 15:32:50 isbinfrepo systemd[1]: Unit squid.service entered failed state.
Sep 22 15:32:50 isbinfrepo systemd[1]: squid.service failed.
Similar error referring to a different file : Ipc::Mem::Segment::create failed to shm_open(/squid-cf__queues.shm): (17) File exists

Details

This _may_ be due to SE Linux (source).

Solution

  1. grep 'cache_effective_user' /etc/squid/squid.conf || chown nobody: /dev/shm/squid-cf*
  2. Try again :
    systemctl restart squid; systemctl -l status squid
    If ok, enjoy and don't go further. Otherwise continue
  3. rm /dev/shm/squid-cf__*
  4. Try again :
    systemctl restart squid; systemctl -l status squid
    Was ok here for me
mail

Squid configuration directives

cache_effective_user
  • Purpose : If Squid is started by root, it will change its effective/real UID/GID to cache_effective_user / cache_effective_group
  • Default value : nobody
cache_dir
  • Format : cache_dir type directory MBytes L1 L2 [options]
    • type : storage system to use. Only ufs is built-in by default.
    • directory : top-level directory where cache files will be stored. Must exist and be writable by the Squid process owner (with default settings : root)
    • Mbytes : amount of disk space to use under directory
    • L1 : number of first-level subdirectories which will be created under directory (defaults to 16)
    • L2 : number of second-level subdirectories which will be created under each first-level directory (defaults to 256)
  • Default value : No disk cache. Store cache objects in memory only.
http_port
No default value, but Squid is initially configured to listen on port 3128.
mail

Squid

Setup

Squid can be installed very easily :

Configuration

Configuration file : /etc/squid/squid.conf, details in Squid configuration directives.

How to enable disk caching (i.e. set cache_dir)

  1. set the corresponding path / options for cache_dir in /etc/squid/squid.conf
  2. create the top-level cache directory :
    cacheDir='/data/squidCache'; mkdir -p "$cacheDir"; chown squid: "$cacheDir"
  3. create the L1 subdirectories of "$cacheDir" :
    squid -zNF
    2017/09/22 15:14:37| Set Current Directory to /var/spool/squid
    2017/09/22 15:14:37| Creating missing swap directories
    2017/09/22 15:14:37| /data/squidCache exists
    2017/09/22 15:14:37| Making directories in /data/squidCache/00
    2017/09/22 15:14:37| Making directories in /data/squidCache/01
    2017/09/22 15:14:37| Making directories in /data/squidCache/02
    
    2017/09/22 15:14:37| Making directories in /data/squidCache/0E
    2017/09/22 15:14:38| Making directories in /data/squidCache/0F
  4. you can then start Squid :
    systemctl start squid