I recently wanted some kind of high availability for my private websites and applications, so I decided to setup a second server at my dads office as a failover system.

Install GlusterFs for file syncing.

The latest stable version for me was 3.8, but check the authors site, because GlusterFS is geeting new updates from time to time. It is recommended to use a separate partition for GlusterFS, but as I already got my setup up and runnig on the first node i am only covering the simple way.

@every node

# add-apt-repository ppa:gluster/glusterfs-3.8
# apt update
# apt install glusterfs-server
# update-rc.d glusterfs-server defaults

2. Setting up dns (makes things much easier)

@ every node

# nano /etc/hosts

192.168.255.101 node1 web02
192.168.255.102 node02 web02

Open Firewall

@ node1

#  gluster peer probe node2

@ node2

# gluster peer probe node1
# gluster peer status

Create a volume “cluster-data”

# gluster volume create cluster rep 2 transport tcp node1:/data node2:/data
# gluster volume start master

Mount the volume
Do this on each node, because we are planning to use our gluster file-system with the webserver on the nodes itself.

# mkdir /cluster

@ every node

# nano /etc/fstab
localhost:/cluster /cluster glusterfs defaults,_netdev 0 0
# mount -a

@ node1

# mkdir -p /cluster/etc
# mkdir -p /cluster/www
# mkdir -p /cluster/var/lib
# mkdir -p /cluster/log
# mv /etc/nginx /cluster/etc
# mv /etc/php /cluster/etc
# mv /etc/mysql /cluster/etc
# mv /var/lib/mysql /cluster/var/lib/mysql
# mv /var/lib/php /cluster/var/lib/php
# mv /var/www /cluster/www
# mv /var/log/nginx /cluster/log
# mv /var/log/mysql /cluster/log

@ every node, apart from node1

# rm -r /etc/nginx
# rm -r /etc/php
# rm -r /etc/mysql
# rm -r /var/lib/mysql
# rm -r /var/lib/php
# rm -r /var/www
# rm -r /var/log/nginx
# rm -r /var/log/mysql

@ every node

# ln -s /cluster/etc/nginx /etc/nginx 
# ln -s /cluster/etc/php /etc/php
# ln -s /cluster/etc/mysql /etc/mysql
# ln -s /cluster/db /var/lib/mysql
# ln -s /cluster/php /var/lib/php
# ln -s /cluster/www /var/www
# ln -s /cluster/log/nginx /var/log/nginx
# ln -s /cluster/log/mysql /var/log/mysql

Author: Anton Bracke

Software engineering student from Germany. Loves programming in PHP, JS and sometimes C.