Lo que tenemos que hacer es cambiar el puerto que usa el Apache por defecto (80) por otro, digamos el 8888. Luego hay que configurar el Varnish para que use el puerto 80 para mostrar el contenido que sale por el nuevo puerto 8888 del Apache.
Proceso
Descargamos el varnish-3.0.2-1.el5 y lo instalamos por yum.
Para cambiar el puerto del Apache, hay que acceder al VHM, entrar a la sección "Tweak Settings" y configurar así
Luego hay que configurar el Varnish para que use el puerto 80.
Accedemos al archivo /etc/sysconfig/varnish
Allí debemos configurar las siguientes líneas de modo que queden así
En el archivo completo deberán quedar así
# Maximum number of open files (for ulimit -n)
NFILES=131072
# Locked shared memory (for ulimit -l)
# Default log size is 82MB + header
MEMLOCK=82000
# Maximum size of corefile (for ulimit -c). Default in Fedora is 0
# DAEMON_COREFILE_LIMIT="unlimited"
# Set this to 1 to make init script reload try to switch vcl without restart.
# To make this work, you need to set the following variables
# explicit: VARNISH_VCL_CONF, VARNISH_ADMIN_LISTEN_ADDRESS,
# VARNISH_ADMIN_LISTEN_PORT, VARNISH_SECRET_FILE, or in short,
# use Alternative 3, Advanced configuration, below
RELOAD_VCL=1
# This file contains 4 alternatives, please use only one.
## Alternative 1, Minimal configuration, no VCL
#
# Listen on port 6081, administration on localhost:6082, and forward to
# content server on localhost:8080. Use a fixed-size cache file.
#
#DAEMON_OPTS="-a :6081 \
# -T localhost:6082 \
# -b localhost:8080 \
# -u varnish -g varnish \
# -s file,/var/lib/varnish/varnish_storage.bin,1G"
## Alternative 2, Configuration with VCL
#
# Listen on port 6081, administration on localhost:6082, and forward to
# one content server selected by the vcl file, based on the request. Use a
# fixed-size cache file.
#
DAEMON_OPTS="-a :80 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
-u varnish -g varnish \
-S /etc/varnish/secret \
-s file,/var/lib/varnish/varnish_storage.bin,1G"
## Alternative 3, Advanced configuration
#
# See varnishd(1) for more information.
#
# # 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=
VARNISH_LISTEN_PORT=80
#
# # Telnet 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
#
# # The minimum number of worker threads to start
VARNISH_MIN_THREADS=1
#
# # The Maximum number of worker threads to start
VARNISH_MAX_THREADS=1000
#
# # Idle timeout for worker threads
VARNISH_THREAD_TIMEOUT=120
#
# # Cache file location
VARNISH_STORAGE_FILE=/var/lib/varnish/varnish_storage.bin
#
# # Cache file size: in bytes, optionally using k / M / G / T suffix,
# # or in percentage of available disk space using the % suffix.
VARNISH_STORAGE_SIZE=1G
#
# # Backend storage specification
VARNISH_STORAGE="file,${VARNISH_STORAGE_FILE},${VARNISH_STORAGE_SIZE}"
#
# # Default TTL used when the backend does not specify one
VARNISH_TTL=120
#
# # DAEMON_OPTS is used by the init script. If you add or remove options, make
# # sure you update this section, too.
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 \
-S ${VARNISH_SECRET_FILE} \
-s ${VARNISH_STORAGE}"
#
## Alternative 4, Do It Yourself. See varnishd(1) for more information.
#
# DAEMON_OPTS=""
Luego para decirle al Varnish (puerto 80) que muestre el contenido que sale por el Apache (puerto 8888) había que configurar el archivo /etc/varnish/default.vcl
Debe quedar de una forma análoga a
Luego habría que reiniciar el Apache y el Varnish y listo.
Pruebas
Varnish acelera la navegación en sitios web donde el usuario no ha iniciado sesión. Es decir, trabaja sólo con usuarios anónimos. Esto se debe a que no funciona si el sistema usa cookies para la navegación. De allí que Varnish no funciona en Drupal 6 porque muchos módulos crean cookies para trackear la actividad de usuarios anónimos. Está es la razon porque aparece la distribución Pressflow que hackea el core para evitar que se creen cookies cuando el usuario no está logueado. Cabe decir que en Drupal 7 se puede usar sin problemas.
Entonces, Varnish sólo te servirá bajo estas condiciones. Si deseas probarlo en Drupal 6, tienes que descargar Pressflow y reemplazar todos los archivos de su core en tu instalación de Drupal 6 porque sólo así funcionará. Luego tienes que activar el modo "caché externa" dentro de la sección Performance (admin/settings/performance)
Para testear lo que se hace generalmente es usar el comando ab que viene con Apache. Para eso te logueas por consola y DENTRO de tu servidor pones algo como
ab -n 100 http://myweb.com/mi-first-page-in-varnish
y observas el número de request por segundos que te sale en la respuesta. Si te sale superior a 1000 entonces está funcionando. Si te sale menos de 50 entonces debes revisar si has activado el modo cache externa en tu sitio de Drupal.
Por otro lado, debes ir a tu página web y con el Firebug (addon de Firefox) observar las etiquetas que te salen en las cabeceras. Allí te debe salir algo como:
Una herramienta para testear la velocidad que puedes usar externamente es
Gracias a Luis Huacho y Jaime de la Cruz por la ayuda.
================================
Actualización 13/01/2012
Se tiene que configurar lo siguiente para que el servidor permita descargar archivos de más de 10 MB
Tomado de