How to optimize Varnish cache server in CWP – Control WebPanel Centos7/8, Almalinux, Rockylinux

Varnish is an HTTP accelerator designed for content-heavy dynamic web sites as well as APIs. In contrast to other web accelerators, such as Squid, which began life as a client-side cache, or Apache and nginx, which are primarily origin servers, Varnish was designed as an HTTP accelerator.

Here how you can optimize varnish cache server in CWP

Install Varnish cache from CWP Webserver Settings >> Webserver conf

For Centos 7/EL7 :

Edit this file : /etc/varnish/varnish.params

and replace all lines with the below configs :

# Varnish environment configuration description. This was derived from
# the old style sysconfig/defaults settings
# Set this to 1 to make systemd reload try to switch VCL without restart.
RELOAD_VCL=1
# Set WARMUP_TIME to force a delay in reload-vcl between vcl.load and vcl.use
# This is useful when backend probe definitions need some time before declaring
# configured backends healthy, to avoid routing traffic to a non-healthy backend.
#WARMUP_TIME=0
# Main configuration file. You probably want to change it.
VARNISH_VCL_CONF=/etc/varnish/default.vcl
# Default address and port to bind to. Blank address means all IPv4
# and IPv6 interfaces, otherwise specify a host name, an IPv4 dotted
# quad, or an IPv6 address in brackets.
# VARNISH_LISTEN_ADDRESS=192.168.1.5
VARNISH_LISTEN_PORT=82
# Admin interface listen address and port
VARNISH_ADMIN_LISTEN_ADDRESS=127.0.0.1
VARNISH_ADMIN_LISTEN_PORT=6082
# Shared secret file for admin interface
VARNISH_SECRET_FILE=/etc/varnish/secret
# Backend storage specification, see Storage Types in the varnishd(5)
# man page for details.
VARNISH_STORAGE="malloc,1024M"
# User and group for the varnishd worker processes
VARNISH_USER=varnish
VARNISH_GROUP=varnish
# Other options, see the man page varnishd(1)
DAEMON_OPTS="-p thread_pools=30 -p thread_pool_min=600 -p thread_pool_max=20000 -p connect_timeout=600 -p thread_pool_timeout=600 -P /run/varnish.pid"

then restart varnish server from cwp admin dashboard

For centos 8 stream/almalinux/rockylinux :

Edit this systemed service file : /usr/lib/systemd/system/varnish.service

Then find ExecStart= directive and replace the full line with below config :

ExecStart=/usr/sbin/varnishd -a :82 -f /etc/varnish/default.vcl -p thread_pools=30 -p thread_pool_min=600 -p thread_pool_max=20000 -s malloc,1G -p connect_timeout=600 -p thread_pool_timeout=600 -P /run/varnish.pid

it will look like below config example :

[Unit]
Description=Varnish Cache, a high-performance HTTP accelerator
After=network-online.target

[Service]
Type=forking
KillMode=process

# Maximum number of open files (for ulimit -n)
LimitNOFILE=131072

# Locked shared memory - should suffice to lock the shared memory log
# (varnishd -l argument)
# Default log size is 80MB vsl + 1M vsm + header -> 82MB
# unit is bytes
LimitMEMLOCK=85983232

# Enable this to avoid "fork failed" on reload.
TasksMax=infinity

# Maximum size of the corefile.
LimitCORE=infinity

ExecStart=/usr/sbin/varnishd -a :82 -f /etc/varnish/default.vcl -p thread_pools=30 -p thread_pool_min=600 -p thread_pool_max=20000 -s malloc,1G -p connect_timeout=600 -p thread_pool_timeout=600 -P /run/varnish.pid
ExecReload=/usr/sbin/varnishreload

[Install]
WantedBy=multi-user.target

Then run daemon reload command :

systemctl daemon-reload

After restart the varnish server from cwp dashbaord.

Back to top button