Hello everyone,
I get asked a lot about how to make a redundant cacti setup specifically how to make the master poller redundant.
I thought I would do this writeup on how I created a redundant master poller using Mariadb replication and keepalived.
this is a simple setup but can become complicated if you want more out of it for example this setup uses MariaDB master to slave replication to replicate over the cacti DB and its changes from the primary server over to the secondary. However, changes from secondary won’t replicate to the master if you are looking for something like this then you need to look into MariaDB Master to Master replication.
but for most setups, this setup should work well
Here is the general layout we use keepalived to make sure the application is accessible in case of a failure keepalived uses VRRP ( Virtual Router Redundancy Protocol) to advertise a virtual IP from either the primary server or the secondary. Both servers as you see from the diagram have their own IP but on top of that have a virtual IP they will use depending on their state. The user will connect to the virtual IP instead of the server IP so in the case of a failure, the user would not know they have switched servers. We use MariaDB replication to ensure that the databases are the same on both servers.
Now for the setup
I will assume you have already installed cacti on each server you can if you are using virtual machines even use a clone of a single master poller instance. I would recommend Cacti 1.2.16 since there is a new system service you will see why soon.
If you don’t already have cacti Install consider using my cacti setup wizard script https://github.com/bmfmancini/cacti-install-wizard
Keepalived setup on the master server
First, we will install and configure keepalived.
After keepalived has been installed we would need to make an initial configuration for it.
I use the following config to make server A the master server.
In the above configuration what we are saying to keepalived is that this is the master server we ensure that the priority on the master server is higher than on the secondary server. This tells keepalived to broadcast the virtual ip address all traffic is now pointed to this server we also ensure to put a password on the VRRP instanced so not just any server can join our VRRP cluster.
Next we need to enable and start the keepalived service.
In the status output we should ensure that this server is showing in master state if you see something similar to the above then we are good to move on to the MariaDB config.
MariaDB config on the Master
Ok so in this part we need to configure MariaDB to be the master server we will need to modify the 50-server.conf file and put a few entries and also create a replication username and password to allow replication. From the secondary server since you already have cacti installed I assume you already have either MariaDB or MYSQL installed both of which this will work on.
First edit the 50-server.conf like so
Add the following lines
NOTE you may need to create the following path
Next we will enter the mysql shell and create the replication username and password.
Now we can move onto the secondary server
Keepalived configuration on secondary server
As we did with the primary server we will install and configure keepalived this is the config I used in my setup it is essentially the same as the master but we put the state to backup and priority to 100 instead of 200
Keepalived notification script
You saw that on the keepalived configuration there was a script called cacti-service.sh under notify what this script does is shutdown the cacti poller if you are using pre 1.2.16 cacti then it will shutdown cron. If you are using 1.2.16 you can have it shutdown the cacti service the issue of course with shuting down cron is other scheduled tasks are gone. I suppose you could delete file cron entire from cron.d and have the script re-create it should it enter master status.
In this case when the server enters backup mode the cron is stopped this prevents double polling and also prevents the servers writing double data to the RRD files if you copy and paste this code ensure to chmod 755 it
Mariadb setup on the secondary server
Next we will need to make a couple of changes to the 50-server file on the secondary server as well as make some shell changes.
In this case, we are excluding a few transient tables to be replicated from the primary database to the secondary database these tables hold temporary data and there is no need to replicate them. Doing so could also give you some grief.
Next enter the MySQL shell and use the following commands.
Remember to match the binary log file and the master position
from the command output, we got from the master server.
Now, let’s check the salve status we are looking for a status that the slave is waiting for the master to send events.
Success we are now seeing the slave talk to the master and waiting for an event to happen this is usually something like a new device or settings change in the cacti GUI.
Next you will do some verification and testing go to the primary server create a test device you should see that change reflected on the secondary server check out my video below to see this in action
Next you will need to setup some sort of shared storage i.e NFS share and mount it to /var/www/html/cacti/rra on both servers this will allow both servers to write data to the RRD files.
The shared storage could be like I said before NFS but could also be any other storage technology.
Let me know if you run into any issue with this tutorial !