Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>i had nearly the same problem with servers hosted by acquia.</p> <p>A way to solve it was to : - set the backend IPs from the hoster servers by acquia in a separate vcl - build a croned script that regulary updates that vcl if the backend changed - restart the varnish to put the new backends in production</p> <pre><code>#!/usr/bin/python2.7 import socket import subprocess import re # # Do a nslookup and return the list of the IPs # def _nslookup(host): ips = "" ips = socket.getaddrinfo(host ,0,0,0,0) ip_list = [] for result in ips: ip_list.append(result[-1][0]) ip_list = list(set(ip_list)) return ip_list # # Compare current backends with the list returned by nslookup # def _compare_backends_vcl(host_name, group_name): current_ips = [] current_ips = _nslookup(host_name) # Get current backends current_backends = [] list = subprocess.Popen("/usr/bin/varnishadm backend.list | grep " + group_name + " | awk '{print $1}'", shell=True, stdout=subprocess.PIPE) backend = "" for backend in list.stdout: current_backends.append(re.sub(r'^.*\((.*),.*,.*$\n', r'\1', backend)) # Due to varnish bug that is not removing backends (old ones are still declared in backend.list # we are forced to add backends # So the nslookup should be part of the current set of backends # if set(current_ips).symmetric_difference(current_backends): if set(current_ips).difference(current_backends): # List is present so difference exist print "_compare: We have to update " + group_name return True else: return False # # Write the corresponding file # def _write_backends_vcl(host_name, group_name): TEMPLATE_NODE = '''backend %s { \t.host = "%s"; \t.port = "80"; \t.probe = %s; }''' vcl_file = open("/etc/varnish/" + group_name + "_backends.vcl", 'w') host_num = 1 hosts = _nslookup(host_name) for host in hosts: vcl_file.write(TEMPLATE_NODE % (group_name + "_" + str(host_num), host, group_name + "_probe")) vcl_file.write("\n\n") host_num +=1 vcl_file.write("director " + group_name + "_default round-robin {\n") for i in range(len(hosts)): node = group_name + "_" + str(i+1) vcl_file.write("\t{ .backend = %s; }\n" % node) vcl_file.write("}\n") vcl_file.close() # Main do_reload = "" if _compare_backends_vcl("myhost.prod.acquia-sites.com", "MYHOST_CONFIG"): do_reload = True _write_backends_vcl("myhost.prod.acquia-sites.com", "MYHOST_CONFIG") if do_reload: print "Reloading varnish" subprocess.Popen(['sudo', '/etc/init.d/varnish', 'reload']) exit(1) else: # print "Everything is ok" exit(0) </code></pre> <p>then, the corresponding vcl looks like :</p> <pre><code>backend MYHOST_CONFIG_1 { .host = "XX.XX.XX.XX"; .port = "80"; .probe = MYHOST_CONFIG_probe; } backend MYHOST_CONFIG_2 { .host = "XX.XX.XX.XX"; .port = "80"; .probe = MYHOST_CONFIG_probe; } director MYHOST_CONFIG_default round-robin { { .backend = MYHOST_CONFIG_1; } { .backend = MYHOST_CONFIG_2; } } </code></pre> <p>You have to setup the MYHOST_CONFIG_probe probe and to set MYHOST_CONFIG_default as a director for your config. Beware that varnish stores all the backend, and so you have to restart it regularly to purge the defective servers</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload