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

This might work for some people....
UPDATED: Confirmed this works (Implemented on my systems)

LSYNCD
https://github.com/axkibe/lsyncd

I haven't tested on pihole yet, but I use it at work to keep a HA pair of servers in sync.
You have the option to select/exclude dirs/files you want sync'd

Both Servers

sudo mkdir /etc/lsyncd
sudo vi /etc/lsyncd/lsyncd.conf
sudo mkdir /var/log/lsyncd
sudo touch /var/log/lsyncd/lsyncd.status
sudo touch /var/log/lsyncd/lsyncd.log

=

On the Primary PiHole (IP=192.168.1.1)

sudo vi /etc/lsyncd/lsyncd.conf.lua

settings {
  logfile = "/var/log/lsyncd/lsyncd.log",
  statusFile = "/var/log/lsyncd/lsyncd.status",
  statusInterval = 20
}
 
sync {
  default.rsyncssh,
  delete = false,
  source = "/etc/pihole/",
  host = "192.168.1.2",
  targetdir = "/etc/pihole/",
  excludeFrom = "/etc/lsyncd/lsyncd.exclude",
  delay = 20,
  rsync = {
    archive = true,
    owner = true,
    perms = true,
    group = true,
    compress = false,
    whole_file = true,
  }
}

=
On the Secondary PiHole (IP = 192.168.1.2)

sudo vi /etc/lsyncd/lsyncd.conf.lua

settings {
  logfile = "/var/log/lsyncd/lsyncd.log",
  statusFile = "/var/log/lsyncd/lsyncd.status",
  statusInterval = 20
}
 
sync {
  default.rsyncssh,
  delete = false,
  source = "/etc/pihole/",
  host = "1912.168.1.1",
  targetdir = "/etc/pihole/",
  excludeFrom = "/etc/lsyncd/lsyncd.exclude",
  delay = 20,
  rsync = {
    archive = true,
    owner = true,
    perms = true,
    group = true,
    compress = false,
    whole_file = true,
  }
}

=
On both servers...

cat /etc/lsync/lsyncd.exclude
setupVars.conf
local.list
localbranches
localversions
dhcp.leases
install.log
local.list
*.db
*.db-journal
.gravity*
.list*
whitelist/.git*

=
Usage

sudo systemctl status lsyncd -l
sudo systemctl force-reload lsyncd
sudo systemctl start lsyncd
sudo systemctl restart lsyncd

If you are using any crontab entries to update adlists/whitelists/...etc, this might conflict?

2 Likes