LowEndBox - Cheap VPS, Hosting and Dedicated Server Deals

How to Setup a Highly Available WordPress Site From Scratch, Part 5

How to Setup a Highly Available WordPress Site From Scratch, Part 5In this tutorial series, we are setting up a highly available WordPress web site from scratch.

Part 1 – Introduction, Considerations, and Architecture
Part 2 – Setting Up the VPSes
Part 3 – Setting Up MariaDB Multi-Master Replication
Part 4 – File Replication and Setting Up DRBD
Part 5 – Setting Up OCFS2
Part 6 – Round-Robin DNS, Let’s Encrypt, & Conclusion

Setting Up OCFS2

OCFS2 (Oracle Cluster Filesystem 2) is simple to setup. Despite its proprietary-sounding name, it’s licensed under the Gnu GPL and can be installed via your normal package manager.

Place the following in /etc/ocfs/cluster.conf on both nodes:

    ip_port = 7777
    ip_address =
    number = 0
    name = web1.lowend.party
    cluster = ocfs2
    ip_port = 7777
    ip_address =
    number = 1
    name = web2.lowend.party
    cluster = ocfs2
    node_count = 2
    name = ocfs2

You can name your cluster (the “name =” directive) anything you want.

We want the cluster to start at boot-time, which is controlled by /etc/default/o2cb.  We could probably just change O2CB_ENABLED to “true” in that file, but it has this comment:

# This is a configuration file for automatic startup of the O2CB
# driver.  It is generated by running 'dpkg-reconfigure ocfs2-tools'.
# Please use that method to modify this file.

So run dpkg-reconfigure ocfs2-tools on both nodes.  Answer YES to the first question, and then accept defaults for all the rest.

Now we can make the filesystem.  We don’t want to make it on /dev/sdc1 but rather on the DRBD device:

root@web1:/etc/drbd.d# mkfs.ocfs2 -N 2 -L ocfs2drbd /dev/drbd0 
mkfs.ocfs2 1.8.5
Cluster stack: classic o2cb
Label: ocfs2drbd
Features: sparse extended-slotmap backup-super unwritten inline-data strict-journal-super xattr indexed-dirs refcount discontig-bg append-dio
Block size: 4096 (12 bits)
Cluster size: 4096 (12 bits)
Volume size: 10736005120 (2621095 clusters) (2621095 blocks)
Cluster groups: 82 (tail covers 8359 clusters, rest cover 32256 clusters)
Extent allocator size: 8388608 (2 groups)
Journal size: 67108864
Node slots: 2
Creating bitmaps: done
Initializing superblock: done
Writing system files: done
Writing superblock: done
Writing backup superblock: 2 block(s)
Formatting Journals: done
Growing extent allocator: done
Formatting slot map: done
Formatting quota files: done
Writing lost+found: done
mkfs.ocfs2 successful

Those flags mean “2 nodes, and label the volume ‘ocfs2drbd'”.

Now start/enable the cluster registration service on both nodes:

# systemctl enable ocfs2 && systemctl enable o2cb
Synchronizing state of ocfs2.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable ocfs2
Synchronizing state of o2cb.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable o2cb
# systemctl start ocfs2 && systemctl start o2cb

Mounting the Shared DRBD Volume

We’re going to mount /dev/drbd0 (the shared cluster volume) on /web.  First, create the following entry in /etc/fstab on both nodes:

/dev/drbd0     /web           ocfs2   noauto,noatime 0 0
Now rename the existing /web to /web.prev and mkdir /web on both nodes:

# systemctl stop nginx
# mv /web /web.prev
# mkdir /web

Finally mount it on both nodes:

# mount /web

If you get this error when trying to mount:

mount.ocfs2: Unable to access cluster service while trying initialize cluster

Try this:

/etc/init.d/o2cb restart

Now if you go into /web on one node and touch a file or copy a file to that directory, you’ll find it’s nearly-instantly available on the other node.  We’re enabled for multi-master so you can have nodes writing on both sides and changes will replicate bi-directionally.

Now on *one* node (it’s a shared volume, remember?) do this:

 mv /web.prev/www.lowend.party /web

And then cleanup on both nodes:

rm -rf /web.prev
systemctl start nginx

Next Part: Part 6 – Round-Robin DNS, Let’s Encrypt, & Conclusion

I'm Andrew, techno polymath and long-time LowEndTalk community Moderator. My technical interests include all things Unix, perl, python, shell scripting, and relational database systems. I enjoy writing technical articles here on LowEndBox to help people get more out of their VPSes.

No Comments

    Leave a Reply

    Some notes on commenting on LowEndBox:

    • Do not use LowEndBox for support issues. Go to your hosting provider and issue a ticket there. Coming here saying "my VPS is down, what do I do?!" will only have your comments removed.
    • Akismet is used for spam detection. Some comments may be held temporarily for manual approval.
    • Use <pre>...</pre> to quote the output from your terminal/console, or consider using a pastebin service.

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