![]() |
![]()
| ![]() |
![]()
NAMEvmod_dynamic - Varnish dynamic backends module SYNOPSISimport dynamic [as name] [from "path"] new xdirector = dynamic.director(STRING port, STRING host_header, ENUM share, PROBE probe, ACL whitelist, DURATION ttl, DURATION connect_timeout, DURATION first_byte_timeout, DURATION between_bytes_timeout, DURATION domain_usage_timeout, DURATION first_lookup_timeout, INT max_connections, INT proxy_header, BLOB resolver, ENUM ttl_from, DURATION retry_after, BACKEND via) DESCRIPTIONThis module provides a varnish director for dynamic creation of backends based on calls to
While standard varnish backends defined in VCL may also be defined in terms of host names, changes of the name service information will only be picked up with a VCL reload. In contrast, for dynamic backends provided by this module,
In addition, with a getdns <https://getdnsapi.net/>
BACKEND SHARINGThe share parameter specifies if backends are shared per director or per hostname.
PROBINGA probe to be used with dynamically created backends can be specified. With share = HOST, the Host: header for probes defaults to the backend's hostname (host argument to the .backend() method). With share = DIRECTOR, the probe is not specific to any particular host. If the probe has the .request attribute set, it will be used as the probe request. Otherwise, if a host_header argument was given to dynamic.director(), it will be used for the probe's Host header, otherwise Varnish-Cache core code will send the backend's IP Address as the Host header. Consider setting the initial attribute of probes at least as high as the threshold attribute. Otherwise transactions that trigger the first lookup of a domain will see a sick backend and fail. Irrespective of the initial attribute, transactions may still fail for backends which are actually sick. This can be mitigated using the retry transition in VCL. TTLS FROM DNSWith the default system resolver, TTLs from DNS are not supported
optimally. While a good combination of a ttl parameter in combination
with a system name service caching service like nscd(8) can achieve
good results, to use TTLs from DNS, we recommend to compile this module with
getdns <https://getdnsapi.net/>
sub vcl_init { See ref_ttl_from for details. NAMESDirectors and backends created by this vmod follow this naming scheme, which will be referred to as <name> in the following documentation
port may be represented symbolically (http by default) STATISTICSDynamic backends are created and deleted on demand and can be monitored just like VCL-defined backends. Their statistics will appear in VSM-tools like varnishstat as: VBE.<configname>.<name>.* LOGGINGThis module may log VCL_Log, Error, and Debug records following a common pattern: vmod-dynamic: %s %s %s %s [ %s ] Lookup timestamps are also logged to help troubleshooting, using regular Timestamp records with the following pattern for event labels: vmod-dynamic <vcl>.<name> <Lookup|Results|Update> When a lookup thread is terminated, either because the VCL is cooling down or the domain_usage_timeout triggered, Timestamp records are logged with the event: vmod-dynamic <vcl>.<name> Done Not all logs belong to HTTP transactions, especially since DNS lookups happen in the background. In order to capture all logs from this module the simplest way with varnishlog is the following: varnishlog -g raw -q '* ~ vmod-dynamic' It displays any individual record that contains the string vmod-dynamic whether it belongs to a transaction or not. When a lookup fails, the backends are left untouched and the error will be logged with the following event: getaddrinfo <errno> (<reason>) new xdirector = dynamic.director(STRING port, STRING host_header, ENUM share, PROBE probe, ACL whitelist, DURATION ttl, DURATION connect_timeout, DURATION first_byte_timeout, DURATION between_bytes_timeout, DURATION domain_usage_timeout, DURATION first_lookup_timeout, INT max_connections, INT proxy_header, BLOB resolver, ENUM ttl_from, DURATION retry_after, BACKEND via)new xdirector = dynamic.director(
If there is more than one DNS response, the minimum if taken as the DNS ttl. For no resolver, only "cfg" is valid.
Parameters to set attributes of backends See varnish documentation for details
probe www_probe { BACKEND xdirector.backend(STRING host="", STRING port="")
BACKEND xdirector.service(STRING service)
VOID xdirector.debug(BOOL)
new xresolver = dynamic.resolver(BOOL set_from_os, INT parallel)new xresolver = dynamic.resolver( Create parallel getdns <https://getdnsapi.net/>
Parameters:
Additional configuration of the resolver contexts is possible through the methods documented below. Attempts to call these methods from outside vcl_init{} will trigger a VCL failure. BLOB xresolver.use()return a reference to the dynamic.resolver() object for use as a parameter to the dynamic.director() constructor. BOOL xresolver.set_resolution_type(ENUM {RECURSING, STUB})Specifies whether DNS queries are performed with nonrecurive lookups or as a stub resolver. May only be called from vcl_init{} See <https://getdnsapi.net/documentation/spec/#83-contexts-for-basic-resolution> BOOL xresolver.clear_namespaces()Clear the list of namespaces to be configured, see below. May only be called from vcl_init{} BOOL xresolver.add_namespace(ENUM)BOOL xresolver.add_namespace( Add a namespace to the list of namespaces to be queried. This method only adds the namespace to an internal list, The actual configuration is only done once xresolver.set_namespaces() is called. May only be called from vcl_init{} See <https://getdnsapi.net/documentation/spec/#83-contexts-for-basic-resolution> Notice that not all namespaces are available on all platforms. VCL load will fail with error 312 (The library did not have the requested API feature implemented.) in this case when xresolver.set_namespaces() is called. BOOL xresolver.set_namespaces()Apply namespace configuration, see above. May only be called from vcl_init{} BOOL xresolver.clear_transports()Clear the list of transports to be configured, see below. May only be called from vcl_init{} BOOL xresolver.add_transport(ENUM {UDP, TCP, TLS})Add a transport to the list of transports to be tried. This method only adds the transport to an internal list, The actual configuration is only done once xresolver.set_transports() is called. May only be called from vcl_init{} See <https://getdnsapi.net/documentation/spec/#83-contexts-for-basic-resolution> BOOL xresolver.set_transports()Apply transport configuration, see above. May only be called from vcl_init{} BOOL xresolver.set_idle_timeout(DURATION)Specifies the duration the API will leave an idle TCP or TLS connection open for (idle means no outstanding responses and no pending queries). May only be called from vcl_init{} BOOL xresolver.set_limit_outstanding_queries(INT)May only be called from vcl_init{} BOOL xresolver.set_timeout(DURATION)May only be called from vcl_init{} BOOL xresolver.set_follow_redirects(ENUM)BOOL xresolver.set_follow_redirects( May only be called from vcl_init{} FULL EXAMPLE: BEHAVE LIKE SQUIDFor illustrative purposes, here is an example to turn Varnish into a caching forward proxy for any host. This example is for http only, for https support, via support from the proxy_via_6 branch is required. While the same functionality could be achieved without it, this
example uses vmod_re <https://code.uplex.de/uplex-varnish/libvmod-re>
vcl 4.1; import dynamic; import re; backend proforma None; acl ipv4_only { "0.0.0.0"/0; } sub vcl_init { PITFALLSThere is no support for lookups limited to IPv4 or IPv6 only. However it can be achieved by the means of a white list: acl ipv4_only { "0.0.0.0"/0; } acl ipv6_only { "::0"/0; } With that you can restrict backends to the desired IP network, and monitor error logs with the whitelist mismatch event. Knowing which addresses were rejected, you can fix your domains registration (DNS records, hosts file etc). SEE ALSO
BREAKING CHANGES2.0 (2019-07-13)
ACKNOWLEDGEMENTSWe thank the various people and companies having made vmod_dynamic a reality: vmod_dynamic is based upon vmod_named developed and maintained from 2015 to 2017 by Dridi Boukelmoune (github @dridi) and supported by Varnish Software. Maintenance and improvements 2017 - 2019: Generally sponsored by Spring Media and various unnamed UPLEX clients. SRV record support and getdns integration in 2019 was supported by GOG.com Code was written mostly by Geoffrey Simmons and Nils Goroll from UPLEX with additional contributions by: Ricardo Nabinger Sanchez and Ryan Steinmetz. Thank you to all! COPYRIGHTCopyright (c) 2015-2016 Dridi Boukelmoune Copyright 2017-2019 UPLEX - Nils Goroll Systemoptimierung Authors: Dridi Boukelmoune <dridi.boukelmoune@gmail.com>
|