blog
How to Migrate Standalone Moodle to a Clustered Database Scalable Setup
Online Learning nowadays is quickly gaining traction since the COVID-19 pandemic happened. Most of the educational institutions are having to set up platforms for online learning, and pretty much all students are having to access the platform for learning and interacting with the teachers. Moodle is one of the open source learning management systems for online learning,
Having high availability of the Moodle platform is a must for institutions, otherwise it will interrupt and stop the online learning process. With a lot of students accessing the platform at the same time, the availability and scalability is important. At this point, educational institutions need to have knowledge and architecting the platform high availability and scalability of the Moodle. If you would like to know more about how to migrate standalone Moodle into a Clustered Database Scalable, you can follow this guideline.
Moodle in “Single Point of Failure” Mode
The standalone Moodle platform consists of one server, and everything installed on the server (the database and application server in one place). Or you have 2 servers, which is for the application server and database server as described in the below picture:
Both architectures lack the availability and scalability of service. From the availability perspective, you can imagine, if the server crashes, you do not have any services running on the server. If the application server crashes or database crashes, the service stops operating.
On the other hand, scalability is also important, more users means more traffic and more connections to the database. Scalability can be achieved by adding more resources in the servers, or adding more servers so the traffic can be distributed across the nodes, otherwise performance will suffer.
Converting From Standalone to Clustered Database
Migrating your standalone node to a clustered database may take some time, and it is not a risk-free operation. Below are the steps we need to take:
- You need to take a backup (use mysqldump or xtrabackup).
- Install database in all replica database nodes.
- Restore the backup into the replica nodes.
- Connect the replica node into the master.
- Setup ProxySQL and keepalived in front of the database nodes
- Configure the ProxySQL load balancers (eg. create hostgroups, servers, users).
- Point the Moodle configuration to the new Virtual IP Address.
How ClusterControl Can Assist
ClusterControl is database management software that helps you to deploy, monitor, and manage your open source database. We will try to migrate from standalone Moodle architecture as shown below:
To a clustered database architecture based on replication:
You will need at least two servers for the database, and two for database proxy (we will use ProxySQL as load balancer) and keepalived service for serving a Virtual IP Address.
Assuming we have standalone MySQL database running:
Adding more database nodes in ClusterControl is really straightforward, you can go to the Cluster Menu on the right side of your cluster and Add Replication Slave.
It will show new dialogue for Adding New Slave, you just need to fill the IP address and then just click the Add New Slave button as shown below:
As you can see from the screenshot, it is possible to seed the slave with data from an existing backup. This is to avoid streaming all data from the running master database. Once the slave database is deployed, it will be primed with master data and ClusterControl will make sure the slave syncs up with the master.
You can repeat the step to add another replica node.
The new architecture will be as shown below:
The next step is to add a load balancer in front of the database. A load balancer like ProxySQL is useful as it can redirect write requests to the master and the read requests to the slaves. In this way, you are distributing the Moodle traffic. Note that it is also possible to do a master-master setup based on Galera Cluster for MySQL or MariaDB.
We will use two load balancers for highly availability. You can go to Manage -> Load Balancers in the cluster.
You need to fill some information like server address, administrative and monitor password, add the moodle user into ProxySQL, and then just click Deploy ProxySQL. It will trigger a new job. Repeat deployment on the other load balancer node.
Last thing is to configure keepalived for the load balancers. Go to Manage -> Load Balancers, there is tab for Keepalived
You just need to choose the load balancer type, and add it to keepalived. Fill the Virtual IP Address and Network interface. Click Deploy Keepalived button.
The final architecture of our clustered highly available Moodle database will be as shown below:
You just need to change the connection configuration in config.php pointing the dbhost to the Virtual IP Address that we had configured.
After all migrated to Clustered Database, you might want to put some monitoring in your Moodle database, which you can follow this guideline.