GFS-Moo : Moodle, GlusterFS, LAMP on Cloud
Tags: webdev, bash, cloud, aws
Published: 2022-03-03 01:30:45

## DAY 17 - GFS-Moo -  Script For Moodle, GlusterFS, LAMP on Cloud- Day Seventeen

 
[![Image tweet](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jfjzxg64r7q0i8ra6b8t.png)![Image Cover](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tz08fx9pqj6fmdz17j0w.png)](https://twitter.com/intent/tweet?text=GFS-Moo%20%2C%20an%20automated%20solution%20for%20IAAS%20for%20Moodle%2C%20LAMP%2C%20GlusterFS%20by%20%40anuvindhs%0A%23cloud%20%23aws%20%23bash%20%23webdev%0Ahttps%3A%2F%2Fdev.to%2Faws-builders%2Fgfs-moo-moodle-glusterfs-lamp-on-cloud-3m0i%20%0A)


[100 days of Cloud on GitHub](https://github.com/anuvindhs/100daysofcloud) - [Read On iCTPro.co.nz](https://ictpro.co.nz) - [Read on Dev.to](https://dev.to/anuvindhs)



------
## Do you want to create a 
-  scalable E-learing Solution with Moodle ,
-  Single server e-learning IAAS Solution ,
-  Gluster File System &
-  LAMP server 

**With-out worrying about** **complex Setup** ?




![Image cover 2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d68rlny9p15nnirjt8kf.png)


> Let us read, and let us dance; these two amusements will never do any harm to the world. – _Voltaire_

Here is a one click solution for your Moodle Infrastructure.

## Why GlusterFS for Moodle?  

During a rearchitecting phase for Moodle server, We found out that Moodle is  not performing as expected when its been clustered. 

Files are stored in $CFG->dataroot (moodledata) need to be accessed by all front end clustered servers & Database. 

I tried integrating AWS EFS ( even though running on GlusterFS on backend), AWS S3fs (AWS S3 as a filesystem), Microsoft Azure File Storage   was not giving the results as expected. 

Unfortunately the results was devastating , the time to first byte always takes more than fourteen seconds https://moodle.org/mod/forum/discuss.php?d=418443  . I have seen cases of thirty mins in moodle community discussion (https://moodle.org/mod/forum/discuss.php?d=405061 )  

There are complex solutions available on the worldWideWeb , but I wanted a simple ,effective and easy to setup Solution. 

**Solution One** 

If you are using public cloud provider like AWS, Attaching a Multi attach EBS to servers will resolve the issue.  $CFG->dataroot (moodledata) have to be in the Multi attach EBS. 

The Limitation to this solution is Multi-Attach for io1 volumes is available in the following Regions only: us-east-1 , us-west-2 , eu-west-1 , and ap-northeast-2 . It can change in future but by the time I am writing this post this are the only available regions. 

 

If you are considering data sovereignty or for any other compliance requirement you need a different approach. 

 

**Solution Two** 

Using GlusterFS  

 

### What is GlusterFS? 

GlusterFS (Gluster File System) is an open source Distributed File System that can scale out in building-block fashion to store multiple petabytes of data. 

 

How can you integrate to your architecture ? 

Introducing GFS-Moo , Gluster file system for Moodle. 

This tutorial will help you to implement GlusterFS for your Moodle  

I will be using AWS EC2 to implement the GFS-Moo. 

 



## Architecture


![Image Architecture](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5wb8ov0ftx8wbnu84z4s.png)

In this blog I will be showing you how to install and configure Moodle with Gluster File System

## How to ?

You can run this script in any Debian based Linux instance. 

Supports **On-Prem & Public Cloud**, here i am using **AWS** for demonstration purpose.


### Step 1 - Launching EC2 Instances

- Login to AWS Console and Create three EC2 (Ubuntu)
- Create Three Ec2 Instance with Security Group as shown below,(**if you want to install just Moodle on a single server 
 launch one EC2 with Moodle Security group**)
- **Note own all Public IP address** of instance (if you have attached EIP then note down EIP)

For **Security Groups** Please refer from [GitHub Repo](https://github.com/anuvindhs/GFS-Moo)

### Step 2 Rename EC2 

Let's Re-name  Servers on Console

|  Server   | Rename to   | Public IP   |
| :------------: | :------------: | :------------: |
|Server 1    | GFS-Moo-01  |ip1 (use your server1 public IP) |
|Server 2 | GFS-Moo-02  |ip2 (use your server2 public IP) |
|Server 3 | GFS-Moo-03  |ip3 (use your server3 public IP) |


### Step 3 lets install LAMP, Moodle & GFS.

- Use Putty to SSH into all three Servers, [Configure putty](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/putty.html)
- If you want to use muti-SSH try [mRemoteNG](https://mremoteng.org/) 
- Also Note down the Public IP for all three servers, for the easy of understanding.

#### Basic Installation

SSH into Servers **orderly** and run commands


Get root privilages to run command 
```bash
sudo su -
```

|  Stage | On Server | Command   |
| :------------: | :------------: |:------------ |
|  1 | **GFS-Moo-03** |`wget https://raw.githubusercontent.com/anuvindhs/GFS-Moo/main/install.sh ` </br> `chmod u+x install.sh ` </br> `./install.sh`|
|  2 |**GFS-Moo-02** |`wget https://raw.githubusercontent.com/anuvindhs/GFS-Moo/main/install.sh ` </br> `chmod u+x install.sh ` </br> `./install.sh`|
| 3 | **GFS-Moo-01** |`wget https://raw.githubusercontent.com/anuvindhs/GFS-Moo/main/install.sh ` </br> `chmod u+x install.sh ` </br> `./install.sh`|

[Inspect install.sh Code](https://github.com/anuvindhs/GFS-Moo/blob/main/install.sh) 

## Demo 

### Installing on GFS-Moo-03
- Step 1
![Image Wget](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o8uyri5q33cbevof536f.png)

- Step 2
 - As we are installing **GFS+Moodle+LAMP** select option **5** 
   ![Image GFSmoomenu](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1n2i2k3vhhnt1do8s8k0.png)

- Step 3
 - Enter the Public IP Address for GFS
 ![Image IP](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1cmqzz5xqgajkl0amp5s.png)
 
   ![Image moodleinstall](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hg0yinkoim0z5zit7r6s.png)
 
 **Visit the IP http://yourip** , you can see Moodle installation page

- Step 4 GFS

 - Now you will be asked to enter current host , lets **select 3** , and press **Enter**.

 ![Image host3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p1hgyjg99928tsl4a3g5.png)
 
 - Results
 ![Image Results](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/229e112wjefpnfq7iimh.png)

### Installing on GFS-Moo-02

 - Follow Similar instruction as GFS-Moo-03
 ![Image gfs2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fyquomdnin68pbwy7pqo.png)
 
### Installing on GFS-Moo-01 (MasterNode for GFS)
- Follow Similar instruction as GFS-Moo-03
-  As we are running this script on Master node which is GFS-Moo-01, The script will try to probe the other nodes. This is why its **important** to run the script in other two nodes initially.

![Image probing](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w47anhkxahlxuf2z2715.png)
 

## Setup Moodle Connect your Database

- Get your DB Credentials. , if you don't know how to create RDS , Follow this [Tutorial](https://aws.amazon.com/getting-started/hands-on/create-mariadb-db/)

- Goto any of one server and get the Moodle link , or got http://**Public IP** of that server.
![Image moodle](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4qqz54s5xhxquj2jkte2.png)

- Setup Moodle, go to link provided by script.
and setup your Moodle.  

 ![Image moodlesetup](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gkpqnvzy7wr6ltk9guk0.png)

- Now do the Same with other two servers, make sure you enter same username and password, if you are doing this on an existing Moodle server update **config.php** file from the Moodle folder


 
## Now lets mount the gluster folder to moodledata folder

Now run this command on all servers

```
sudo mount -t glusterfs gfs-moo-01:/gv0 /var/www/moodledata
```

## Test Replication

- goto Moodledata folder (/var/www/moodledata)

```
touch test.txt
```
- Now check on other serves on same folder. You will be able to see the replicated test.txt file.


Congratulations ... You have successfully configured glusterfs for Moodle

----------

**✅Connect with me on [Twitter](https://twitter.com/intent/follow?ref_src=anuvindhs&screen_name=anuvindhs)
 🤝🏽Connect with me on [Linkedin](https://www.linkedin.com/in/anuvindhs)
🧑🏼‍🤝‍🧑🏻 Read more post on [dev.to](https://dev.to/anuvindhs) or  [iCTPro.co.nz](https://ictpro.co.nz)
💻 Connect with me on [GitHub](https://github.com/anuvindhs)**
   

{% user anuvindhs %}