Charanjeet Kaur Charanjeet Kaur - 2 months ago 14
Linux Question

Can we have two varnish on two ports running on same system?

I was just wandering if we can have two varnish instances running on separate ports on the same machine?

I was trying to implement active-active mode on local.

Answer

Yes you can. Not sure what you're doing, but you can either run two varnish processes, each on separate ports, or one varnish instance listening to two ports. Examples of each:

varnishd -a 0.0.0.0:3000 -f /etc/varnish/default_1.vcl -i varnish_1 -n /var/lib/varnish/ubuntu1.dev/varnish_1
varnishd -a 0.0.0.0:3001 -f /etc/varnish/default_2.vcl -i varnish_2 -n /var/lib/varnish/ubuntu1.dev/varnish_2

The above commands start two varnish daemons, listening on ports 3000 and 3001, with different config files, instance names, and working directories. They must have different working directories or conflicts will arise with the shared memory file (shm).

A more common scenario is a single varnish daemon bound to two ports (this is also a better setup).

varnishd -a 0.0.0.0:3000,0.0.0.0:3001 -f /etc/varnish/default.vcl