[squid-users] Howto make Squid config dependent on hostname?

Amos Jeffries squid3 at treenet.co.nz
Fri Sep 16 07:50:37 UTC 2022


On 16/09/22 15:26, Grant Taylor wrote:
> On 9/15/22 8:29 AM, Hildegard Meier wrote:
>> Hello,
> 
> Hi,
> 
>> we have two Squid servers (Linux hosts) and each shall have the very 
>> same config file /etc/squid/squid.conf which is versioned and deployed 
>> from a central deployment server.  So each host shall have deployed 
>> the same files.
>>
>> Each of the two shall have the other configured as sibling cache peer.
>>
>> So node1 shall have
>> cache_peer node2.examlpe.com sibling 3128 3130
>>
>> and node2 shalle have
>> cache_peer node1.examlpe.com sibling 3128 3130
> 
> I have no idea if it will work or not, but I might be tempted to try -- 
> what I first saw as -- Solaris's "mailhost" or "losthost" name overloading.
> 
> Meaning that you would have a single identical entry in the config file 
> on both systems:
> 
>     cache_peer peer-cache-node.example.com sibling 3128 3130
> 
> And then each host would use /etc/hosts to resolve the 
> peer-cache-node.example.com name to it's neighbor's IP.  E.g.
> 
> node1:/etc/hosts
>     ...
>     192.0.2.1    node1.example.com
>     192.0.2.2    node2.example.com peer-cache-node.example.com
>     ...
> 
> node2:/etc/hosts
>     ...
>     192.0.2.1    node1.example.com peer-cache-node.example.com
>     192.0.2.2    node2.example.com
>     ...
> 
> I sort of suspect that the nodes already have a per-node /etc/hosts file.
> 
> This is untested and wild speculation on my part.  Can / will someone 
> with more experience comment on the viability of such "mailhost" or 
> "loghost" use?

This config does work.


Although, I personally would first look at the system being used to 
distribute the config files. All the ones I am aware of some sort of 
macro substitution in files as they are pushed out for exactly this purpose.


Alternatively the cache_peer config settings can be pushed as a separate 
file in /etc/squid/conf.d/cache_peer.conf and the main config file use 
'include' directive to load it.


Cheers
Amos


More information about the squid-users mailing list