Building AWS fault tolerant app with GlusterFS
Building fault-tolerant and scalable web application is a MUST for every serious business and platform. Here you can find nice overview of techniques to achieve that in AWS.
But since AWS is a platform which allows you to build whatever-you-want on the top of it, some extra work is needed to achieve completely redundant and fault tolerant web app.
Here are instructions how to install GlusterFS on two instances which will be in replication mode, so in case one instance goes down, another will continue working.
Familiarize yourself with GlusterFS HERE
The web app will have the following components:
- Elastic Load balancer in 2 AZ
- In each AZ one web server instance
- in each AZ one glusterFS instance
- RDS database with replication
GlusterFS server installation (you need to do this on 2 servers, one in each AZ)
Create a VPC, create 2 private subnets. In each private subnet, launch AmazonLinux 64-bit. Let's say that first server is having private IP GLU1 and second GLU2.
We will use XFS file system, which comes very good with GlusterFS
yum install xfsprogs.i686 xfsprogs.x86_64 xfsprogs-devel.x86_64 xfsprogs-qa-devel.x86_64
Create additional EBS volume, attach it as /dev/xvdb, create a single partition and create XFS file system, and mount to /exports/brick1
fdisk /dev/xvdb
mkfs.xfs /dev/xvdb1
mkdir -p /export/brick1
mount /dev/xvdb1 /export/brick1/
echo "/dev/xvdb1 /export/brick1 xfs defaults 0 0" >> /etc/fstab
Install GlusterFS (on both servers):
yum install glusterfs-geo-replication.x86_64 glusterfs-rdma.x86_64 glusterfs.x86_64 glusterfs-devel.x86_64 glusterfs-fuse.x86_64 glusterfs-server.x86_64 glusterfs-vim.x86_64
Configure GlusterFS primary server (this needs to be done only on primary)
gluster peer probe GLU-2
gluster volume create gv0 replica 2 GLU-1:/export/brick1 GLU-2:/export/brick1
gluster volume info
Basically, after this, you have created GlusterFS cluster, which consist of 2 servers. Each server is having separated EBS volume which is representing a "brick".
GlusterFS Client configuration
Now, after we setup GlusterFS servers, we need to setup also a clients. So basically, each web server will connect to a GlusterFS which is in the same AZ. So instance in AZ A will connect to GlusterFS in AZ A, and instance in AZ B will connect to GlusterFS server in AZ B. That way you will have fault-tolerance, so if one of those servers goes down, another will continue to work. ELB should take care of removing that instance since it will no longer return 200.
Installation on client side:
yum install glusterfs-fuse.x86_64 glusterfs.x86_64 glusterfs-devel.x86_64 glusterfs-vim.x86_64
Mounting GlusterFS server as a local mount:
create /mnt/glusterfs
mount.glusterfs GLU-1:gv0 /mnt/glusterfs
And on second web server/instance do that, too, but mount different GlusterFS server:
create /mnt/glusterfs
mount.glusterfs GLU-2:gv0 /mnt/glusterfs
Note: GlusterFS documentation said that you need to mount as mount.glusterfs GLU-2:/export/brick1 /mnt/glusterfs which is NOT WORKING!
Note2: You can install both server and client on the same machine, which is kinda handy!