High availability (HA) for Pi-hole (running two Pi-hole's)

With Pi-hole version 5, shouldn't the pihole-FTL.db be backed up as well?

EDIT:
Having read @DL6ER's comment above, trying to understand why pihole-FTL.db is not required. When gravity.db is transferred to the 2nd Pi, does pihole-FTL.db get auto-generated / auto-computed?

This is the long term database of queries for the device on which it is running. That database will continue running as-is on both instance of Pi-hole, recording the queries per the privacy setting on each device.

This seems rather straightforward and clear to me

2 Likes

I mean it’s not hard, you have a router setup as the dns on the network, set it up so that it forwards all dns queries to pi 1 by default, but if pi 1 isn’t active then it sends it to pi 2

Should be fairly straightforward thing to setup on your home router.

Have your preferred pi as dns server1 lets say 192.168.1.30

Then the other one as dns server2 at 192.168.1.31

Most home routers allow you to have two dns servers on the network, by default let’s say quad9 is 9.9.9.9 or 149.112.112.112.

Then just use your preferred script to get them to update one another

Thanks, this worked for me!

I used the following script to handle some - maybe unnecessary - stuff:

#!/bin/bash
#
#

/usr/bin/rsync "$@"
result=$?
(
	if [ $result -eq 0 ]; then
		ssh root@10.0.0.116 "sed -e 's|=10.0.0.2/23|=10.0.0.116/23|;s|IPV6_ADDRESS=xxx|IPV6_ADDRESS=xxx|' -i /etc/pihole/setupVars.conf"
		ssh root@10.0.0.116 "sed -e 's|10.0.0.2|10.0.0.116|;s|2003:e6:xxx|2003:fd:xxx|' -i /etc/pihole/local.list"
		ssh root@10.0.0.116 "pihole restartdns reload ; \
				systemctl restart lighttpd.service ; \
				systemctl restart pihole-FTL.service"
	fi
) >/dev/null 2>/dev/null </dev/null

exit $result

and this is how my lsyncd config looks like:

settings {
	logfile = "/var/log/lsyncd/lsyncd.log",
	statusFile = "/var/log/lsyncd/lsyncd.status",
	statusInterval = 30
}
 
sync {
	default.rsyncssh,
	delete = true,
	source = "/etc/pihole/",
	host = "root@10.0.0.116",
	targetdir = "/etc/pihole/",
	delay = 20,
	rsync = {
		binary = "/root/rsync-with-pihole-restart.sh",
		archive = true,
		whole_file = true,
		_extra = { "--omit-dir-times" }
		},
	filter = {
        filter = {
                '- pihole-FTL.db',
                '- pihole-FTL.db-journal',
                '- localversions',
                '- localbranches'
                }
}

sync {
	default.rsyncssh,
	delete = true,
	source = "/etc/dnsmasq.d/",
	host = "root@10.0.0.116",
	targetdir = "/etc/dnsmasq.d/",
	delay = 20,
	rsync = {
		binary = "/root/rsync-with-pihole-restart.sh",
		archive = true,
		whole_file = true,
		_extra = { "--omit-dir-times" }
		}
}

Cheers,
Bjoern

2 Likes

I too would like the ability to cluster 2 or more Pi-hole instances that doesn't require custom scripts that could inevitably break without me noticing. A clustering solution provided via the GUI would be such a great addition to the already great features of Pi-hole.

In addition to the syncing of adlists, whitelists etc the syncronisation of stats would be great also. I would likely plan to use a load balancer infront of the pi-holes so I personally wouldn't have the need for a cluster IP solution created/used by Pi-hole.

4 Likes

Just wanted to share my solution here with you incase sb is interested: GitHub - shaderecker/ansible-pihole: Bootstrap a Raspberry Pi with Ansible and install Docker + Pi-hole

  • Complete deployment automated in Ansible
  • Basic bootstrapping, configuration and updates
  • Pi-hole as docker container
  • High availability failover cluster with keepalived (IPv4 & IPv6)
  • Synchronisation of settings between Pi-hole instances with rsync:
    • gravity.db (Adlists, Domains, Clients, Groups, Group Assignments of all aforementioned items)
    • custom.list (Local DNS Records)
    • 05-pihole-custom-cname.conf (Local CNAME Records)
1 Like

Maybe better to create your own thread here to discuss.
Maybe if you agree, have a mod split this topic ?

I noticed you do a one on one rsync of the gravity dbase file:

Wouldn't that potentially also rsync the dbase file that might still be in transition performing some UPDATE query or something else ?
Isnt it safer to dump the dbase instead on the "primary" and copy the dump over to the "secondaries" eg:

sqlite3 /etc/pihole/gravity.db ".backup main gravity.db.dump"

And restore/import on the secondary hosts if checksum check (md5 or whatever) has changed with:

sudo -u pihole sqlite3 /etc/pihole/gravity.db ".restore main gravity.db.dump"

Would need to stop pihole-FTL to prevent tables being locked while importing.

EDIT: wrong dbase
EDIT2: looks like I'm able to split these posts to a new thread if you like ?

2 Likes

Please use Issues · shaderecker/ansible-pihole (github.com) for discussion.

3 Likes

Thank you for your suggestions, I moved the topic to GitHub Discussions:
save to directly rsync dbase? · Discussion #2 · shaderecker/ansible-pihole · GitHub

2 Likes

Yeah stupid of me.
Github is better spot for this.

I'd really like for this to be a built-in, official feature. I actually thought it already was - I've seen lots of folks talk about running two pi-holes and I saw the "Teleporter" tab in settings, so I just figured that was how you do it. Then I set up a second pi-hole today and realized "Teleporter" is just for manual backup and restore.

So, I figured I could still get a second pi-hole to be a backup DNS server, even if I have to manually "teleport" the settings and only one can run DHCP... but then I realized that there is no GUI configuration option to make my first pi-hole's DHCP server give out the second pi-hole's IP address as a second DNS server.

Given how many threads and custom scripts there are for this, I think it would make sense to make it an official feature of pi-hole.

5 Likes

Both can run DHCP provided the leases are from none overlapping ranges from within the same network.

My master pi-hole is running on a pi4B. All devices obtained a lease from this Pi. The secondary is a 3B, synced from the primary using GitHub - vmstan/gravity-sync: An easy way to synchronize the blocklist and local DNS configurations of multiple Pi-hole 5.x instances.. When I introduced the second dhcp service, existing devices still query the original dhcp server for lease renewal. New devices could take an IP from either dhcp service but because the 4B is faster than the 3B, devices tend to get the offer from the 4B first.

It would be nice for the gui to create an additional-dhcp.conf with the single line dhcp-option=6, etc but it only takes seconds manually.

1 Like

Honestly, this feature needs a "recommended minimum" for the system specs. That includes all non-Pi SBCs.

I have been waiting years for this feature. I don't understand why this has not been implemented yet or really any work has been done. It was requested almost 6 years ago and has just shy of twice the votes of the next most voted feature request. Yet you still have to do a ton of jank in order to get it working.

I run 3 piholes and have had 2 break down before I have had spend time to fix them.
Its a pain whitelisting and black listing.

That's why we have the teleporter function.

That works well on a fresh install.

I currently have 6 tabs open, 3 on Query log and 3 on white or black list.

I run a Dnsmasq server that load balances the 3 piholes and it provides fault tolerance DNS for my network.

It works equally well to duplicate settings between Pi-holes.