Server Setup

GlusterFS Load Balancing

by ,

We have by far the largest RPM repository with NGINX module packages and VMODs for Varnish. If you want to install NGINX, Varnish, and lots of useful performance/security software with smooth yum upgrades for production use, this is the repository for you.
Active subscription is required.

When you receive a lot of traffic and have a few servers at hand, you may want to implement load balancing.
Common scenario is that you would have two or more server assigned for PHP processing. How do you share the files between two or more instances?

If you have just two servers and don’t care about redundancy, you can simply share one directory with NFS or Samba protocol on one server, and mount on another. In fact, this kind of setup might produce the fastest file sharing:

mount -t cifs // /var/www/html -o guest,iocharset=utf8,file_mode=0777,dir_mode=0777,nounix,noserverino

If you want redundancy and failover, you will setup GlusterFS between two nodes.

Run this command on both servers:
mkdir /var/glusterfs/

On first server

The following commands will create networked “RAID storage” contained of two “bricks”: each located in /var/glusterfs/ directory.

gluster volume create example_com replica 2 force
gluster volume start example_com
gluster peer probe
gluster volume add-brick example_com

Now you need to link your site files to GlusterFS storage. You cannot use brick files directly, otherwise there will be no sync between the two servers.

You need to mount using network protocol. I.e. your site root directory is /var/www/html and GlusterFS brick on the same machine is in /var/glusterfs/

Most of the tutorials for GlusterFS setup want you to mount drives with the native glusterfs protocol.
But this is so slow! And not really optimized for PHP files. The best option is to mount with NFS. For this you have to disable built-in NFS server first:

systemctl disable nfs-server

Run this command to self mount:

mount -o tcp,vers=3 -t nfs /var/www/html/

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: