• How to Sync Files Between HA Web Servers with GlusterFS - Ubuntu

How to Sync Files Between HA Web Servers with GlusterFS. Lets install all required packages on the apache2 nodes:

Apache packages required:

apt install libapache2-mod-php7.0 apache2 php7.0 php7.0-mysql php7.0-fpm

Gluster packages required:

apt install glusterfs-server

You will need to add another virtual disk to the apache2 servers. I added a 5GB, since this is a POC and 5GB is enough for the wordpress files. After this, you need to use fdisk to create one partition. It should be fdisk /dev/vdb and n p enter enter enter w. After this, format it to xfs: mkfs.xfs -i size=512 /dev/vdb1. This is the end result you should reach:

Partitions table example:

root@wordpress-03:~# fdisk -l /dev/vdb
Disk /dev/vdb: 5 GiB, 5368709120 bytes, 10485760 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xe611892d

Device     Boot Start      End  Sectors Size Id Type
/dev/vdb1        2048 10485759 10483712   5G 83 Linux

Filesystem example:

root@wordpress-03:~# file -sL /dev/vdb1
/dev/vdb1: SGI XFS filesystem data (blksz 4096, inosz 512, v2 dirs)

After installing packages and configuring the new disk on all hosts, use the following commands to connect all nodes to gluster and also check the status:

gluster peer probe wordpress-02
gluster peer probe wordpress-03

Your status should look like this:

root@wordpress-01:~# gluster peer status
Number of Peers: 2

Hostname: wordpress-03
Uuid: c0c40d4d-4e77-40bc-ba71-d6ef0db54018
State: Peer in Cluster (Connected)

Hostname: wordpress-02
Uuid: e685a5c0-265b-4c07-9f5a-89f6b5ea1d07
State: Peer in Cluster (Connected)

Now you have to mount that filesystem and create a gluster volume. The fstab entry should look like this (please use the UUID of your partition, not the one from the example; you can find the UUID with the command blkid):

root@wordpress-01:~# grep vdb /etc/fstab
UUID=380cf10f-c266-44a8-8461-6dc832135efe /mnt/vdb1 xfs defaults 0 0

After mounting, mkdir /mnt/vdb1/brick. Do this on all hosts. When the xfs filesystem is mounted on all apache2 nodes, create the volume:

gluster volume create httpglustervol replica 2 wordpress-01:/mnt/vdb1/brick wordpress-02:/mnt/vdb1/brick wordpress-03:/mnt/vdb1/brick

After the volume was created, the volume status should look like this:

root@wordpress-01:~# gluster volume status
Status of volume: httpglustervol
Gluster process                             TCP Port  RDMA Port  Online  Pid
------------------------------------------------------------------------------
Brick wordpress-01:/mnt/vdb1/brick          49154     0          Y       1529
Brick wordpress-02:/mnt/vdb1/brick          49154     0          Y       1517
Brick wordpress-03:/mnt/vdb1/brick          49153     0          Y       1292
Self-heal Daemon on localhost               N/A       N/A        Y       7527
Self-heal Daemon on wordpress-03            N/A       N/A        Y       1313
Self-heal Daemon on wordpress-02            N/A       N/A        Y       6909

Task Status of Volume httpglustervol
------------------------------------------------------------------------------
There are no active volume tasks

The gluster setup is not done yet. Please keep in mind that you are not allowed to manually create files on /mnt/vdb1/brick. These files are managed by gluster, and only by gluster. Create the folder /mnt/httpd and add it to /etc/fstab like this:

localhost:/httpglustervol /mnt/httpd glusterfs defaults,_netdev 0 0

Using localhost is considered dangerous by some engineers as it can lead in some cases to problems at booting the system, because gluster is not ready to deliver the device. Normally this gets fixed by using mount -a after the system booted. Some users reported small issues here.

Now mount it, create a wordpress folder within (example mkdir /mnt/httpd/wordpress) and configure apache2 to point to this folder. Sample setting are bellow.

Settings for the available site or just /etc/apache2/sites-enabled/000-default.conf:

<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /mnt/httpd/wordpress


ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

Paragraph required within /etc/apache2/apache2.conf

<Directory /mnt/httpd/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>

You can now test the functionality of your web servers. SSH onto one of them, add some random php files to it and see if they replicate, and if all 3 nodes are delivering the content. Just to be sure you got it right, test the following:

• automatic replication of files within /mnt/httpd on all 3 nodes • php web content on all 3 nodes.


This article was last modified: Oct. 17, 2017, 1:40 p.m.

0 Comments

Please log in to leave a comment.

Add or change tags.

A comma-separated list of tags.

Share

Hacker News

Top