OpenSource For You

Basic Varnish configurat­ion

-

The Varnish configurat­ion file is located in /etc/sysconfig/ varnish for Centos and /etc/default/varnish for Ubuntu.

Open the file in your terminal using the nano or vim text editors. Varnish provides us three ways of configurin­g it. We prefer Option 3. So for our 2GB server, the configurat­ion steps are as shown below (the lines with comments have been stripped off for the sake of clarity): NFILES=131072 MEMLOCK=82000 RELOAD_VCL=1 VARNISH_VCL_CONF=/etc/varnish/default.vcl VARNISH_LISTEN_PORT=80 , :443 VARNISH_ADMIN_LISTEN_ADDRESS=127.0.0.1 VARNISH_ADMIN_LISTEN_PORT=6082 VARNISH_SECRET_FILE=/etc/varnish/secret VARNISH_MIN_THREADS=50 VARNISH_MAX_THREADS=1000 VARNISH_STORAGE_FILE=/var/lib/varnish/varnish_storage.bin VARNISH_STORAGE_SIZE=1G VARNISH_STORAGE=”malloc,${VARNISH_STORAGE_SIZE}” VARNISH_TTL=120 DAEMON_OPTS=”-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_

PORT} \ -f ${VARNISH_VCL_CONF} \ -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ ADMIN_LISTEN_PORT} \ -t ${VARNISH_TTL} \ -w ${VARNISH_MIN_THREADS},${VARNISH_MAX_ THREADS},${VARNISH_THREAD_TIMEOUT} \ -u varnish -g varnish \ -p thread_pool_add_delay=2 \ -p thread_pools=2 \ -p thread_pool_min=400 \ -p thread_pool_max=4000 \ -p session_linger=50 \ -p sess_workspace=262144 \ -S ${VARNISH_SECRET_FILE} \ -s ${VARNISH_STORAGE}”

The first line when substitute­d with the variables will read -a :80,:443 and instruct Varnish to serve all requests made on Ports 80 and 443. We want Varnish to serve all http and https requests.

To set the thread pools, first determine the number of CPU cores that your VPS uses and then update the directives. [root@bookingwir­e sridhar]# grep processor /proc/cpuinfo processor :0 processor :1 This means you have two cores. The formula to use is: -p thread_pools=<Number of CPU cores> \ -p thread_pool_min=<800 / Number of CPU cores> \

The -s ${VARNISH_STORAGE} translates to -s malloc,1G” after variable substituti­on and is the most important directive. This allocates 1GB of RAM for exclusive use by Varnish. You could also specify -s file,/ var/lib/varnish/varnish_storage.bin,10G” which tells Varnish to use the file caching mechanism on the disk and that 10GB has been allocated to it. Our suggestion is that you should use the RAM.

Newspapers in English

Newspapers from India