How to create a HA MediaWiki

      No Comments on How to create a HA MediaWiki

Couple of weeks ago we had to simulate a disaster in one of our datacenters. During the simulation we had to test several application for availability and I noticed that our MediaWiki wasn’t available. The reason why was simple it was only available in our primary datacenter. In this case it wasn’t a big deal cause is was only a simulation, but when there is a real disaster a MediaWiki is in our case very helpful.

So I was looking for a solution to make our MediaWiki High Available. Unfortunately I couldn’t find a proper one. So I decided to create my own HA MediaWiki with the help of DRBD replication between 2 servers and an external MySQL Cluster.

What is DRBD?
The Distributed Replicated Block Device (DRBD) is a software-based, shared-nothing, replicated storage solution mirroring the content of block devices (hard disks, partitions, logical volumes etc.) between hosts.

MySQL Cluster
How to create a MySQL cluster? You can find it right here.
MySQL (Master-Master) cluster with High Availability – Part 1 of 2

Note: This guide is written for Debian 8 and written for a non-root user.
Commands that require elevated privileges are prefixed with [sudo]

Servers

WIKI01:
LAN-Eth0: 10.40.0.15/24
REPL-Eth1: 10.90.0.5/24
Additional 5GB Harddisk for DRDB

WIKI02:
LAN-Eth0: 10.40.0.16/24
REPL-Eth1: 10.90.0.6/24
Additional 5GB Harddisk for DRDB

Cluster-IP: 10.40.0.17/24

Install & Configure Apache and HDD on WIKI01 & WIKI02

First we need to install NTP, Apache and all requirements for MediaWiki

Stop Apache

Make sure Apache won’t start at startup cause we want Apache to be managed by Corosync

Show the current partitions
Note: The values may be different from those below.

As you see, /dev/sdb is not partitioned. We’re gonna create one big partition.

Run fdisk -l again, You should see a /dev/sdb1
Note: The values may be different from those below.

Create a physical volume of /dev/sdb1

Create a volume group

Create a logical volume of 500MB

Install & Configure DRBD on WIKI01 & WIKI02

Install the DRBD utilities

Load the DRBD kernel module:

To check if it is loaded. Output should be similar to this one:

Create a copy of the default DRBD config-file

Delete all the content of DRBD config-file

Open the drbd.conf file for editing. I use nano

Replace the contents of drbd.conf with this configuration.
Note: This config-file may differ from you own environment. Replace the values that are specific to your configuration.

Create the DRBD resource “Wiki”

Start the DRBD resource

Create a directory /data

Initialize DRBD on WIKI01

Start DRBD synchronization from WIKI01 (Primary) to WIKI02 (Secondary)

You can monitor with a simple command.

Wait with the next step until sync is at 100%.
Note: Output when it’s still replicating

Note: Output when it’s fully synced

Create a ext4 filesystem on /dev/drbd0

Create a mount from /dev/drbd0 to /data

Create a MediaWiki directory on /data

Create a symlink from /var/www/html/mediawiki to /data/mediawiki

Unmount the data directory

Stop the DRBD “Wiki” resource

Disable DRBD from autostart at startup

Initialize DRBD on WIKI02

Create here also a symlink from /var/www/html/mediawiki to /data/mediawiki

Stop the DRBD “Wiki” resource

Disable DRBD from autostart at startup

Install & Configure Corosync and Pacemaker on WIKI01 & WIKI02

First we need to add the repository to install Corosync and Pacemaker.

Update the repository and install Corosync and Pacemaker.

Stop Pacemaker service .

Create a copy of the default Corosync config-file

Delete all the content of Corosync config-file

open the corosync.conf file for editing. I use nano

Replace the contents of corosync.conf with this configuration.
Note: This config-file may differ from you own environment. Replace the values that are specific to your configuration.

Restart Corosync to load the new configuration.

Start Pacemaker.

Now that Corosync and Pacemaker is installed and configured on both servers let’s check if our cluster works.

The output should look something like this (if not, wait for 30 seconds, then run the command again):

Configure Cluster Properties

Now we’re ready to configure the properties of Pacemaker.
Note: All Pacemaker (crm) commands can be run from either node server, as it automatically synchronizes all cluster-related changes across all member nodes.

First we want to disable STONITH (Shoot The Other Node In The Head).
Note: STONITH is the ability to remove faulty nodes if they no longer meets the cluster requirements.

Second we want to ignore the quorum policy.
Note: This setting only applies to 2-node clusters.

Thirth and last we want to configure weight-points.
Note: Weight-points are useful when a node goes down and up, this configuration makes sure that the resources running on the other are kept there in case of flapping.

Create Cluster Resources

Now that we have configured the properties we’re ready to create resources.
Open a Pacemaker shell

Enter configuration mode

First: We start by monitoring pacemaker. If a node loses his network connection, we want to failover all resources to the other node.

Second: Add a Cluster-IP address for our MediaWiki cluster

Thirth: Add the DRBD “Wiki” resource

Fourth: Add the DRBD Filesystem.

Fifth: Add the Apache webserver

Now that we have added all our primitive components let’s add the rest of the configuration.

Next we need to tell Pacemaker to start a set of resources and consider the primitives in the set as having 2 states, Master and slave

Create a resource group for our cluster and add the Cluster-IP, Data-FS and WebServer
The order of resources is also the start en shutdown orderIn my case.
Startup: 1. Cluster-IP, 2. Data-FS, 3. WebSever
Shutdown : 1. WebServer, 2. Data-FS, 3. Cluster-IP

Create a location rule which will failover resources to another node.

Configure a colocation restraint, to specify that the MediaWiki-Cluster

The last step is startup order. The Master must be active before resource group can be started.

The configuration is now complete.
Let’s check if the config is done correctly

We shoud see the following output:
Note: This output may differ from you own environment.

If the config looks correctly you can commit the changes

Exit the Pacemaker shell and check if the Cluster-IP is up-and-running.

We shoud see the following output:
Note: This output may differ from you own environment.

As you can see the ms_DRBD-WIKI “Master” is started on WIKI01
Note: It could take a while before all the resources are started

Install & Configure MediaWiki and MySQL

Find out which node is currently the “Master”. In my case WIKI01

Go to the /tmp directory and download MediaWiki

Extract and copy the content to /var/www/html/mediawiki

Change the owner rights

SSH to your MySQL Cluster

Login into mysql and create a database for our MediaWiki

Create 2 users, one for each MediaWiki host. Replace <password> with your own.
Note: The values may be different than those below

Open a Webbrowser and go to http://<MediaWiki Cluster-IP>/mediawiki/.
Follow the steps and install your MediaWiki
Note: Enter your MySQL IP or FQDN at Database host for HA.

Congratz! You have created a working HA MediaWiki.

Leave a Reply

Your email address will not be published. Required fields are marked *