Moodle HA setup using docker over AWS
Blog: NASSCOM Official Blog
In traditional way most of the organizations host their moodle app in the single server, which includes Application/DB even though maintaining the server to be a backup (application/db) still it can not be false into failover/high availability setup. This blog illustrates how we can host a moodle app with High availability over AWS.
The following are the topics which we will discuss in detail in this Tutorial
- Introduction to the Moodle Hosting
- Goal of HA & Auto Scaling
- Components we used for HA
- Key considerations for moodle cluster design
- Proposed Solution & Architecture
- Creating Docker image for Moodle App sample data
- EFS file System setup for MoodleData
- Lessons learned/ Outcome/
Introduction to the Moodle Hosting:
Moodle is the most widely used one of open-source LMS application (Learning Management System). It is used for various forms of learning; to mention a few,blended learning, distance education, flipped classroom are some of its uses. It is especially used for e-learning projects in schools, universities, workplaces, etc. The best part about Moodle is that it’s highly customisable as per requirement. we can get more info about from official site, https://moodle.org/
Goal of HA & Auto Scaling:
HA availability: To achieve system HA we analyze failure of moodle components and decoupled it with redundant(Multi Zone Availability)service availability by using Amazon Web Services with the help of AutoScaling. Autoscaling scales up or scaled down the computing resources automatically according to the current needs of the application by adjusting utilization threshold limits.
- Non production/off-season system will be running with minimal configuration which reduces the advanced resource provisioning costs.
- Peak (or) production hours system scales up according to needs without external changes.
- Decoupled architecture increases the availability of an application.
Components we used for HA:
- Amazon Elastic Container Services(ECS).
- EC2 AutoScaling Group.
- EC2 Instances in Multi Availability zones.
- Amazon Machine Image (Amazon Linux Image-latest).
- Elastic Load Balancer.
- Security Group.
- Amazon Elastic File System or NFS file system.
- Amazon Simple Notification Service.
- Amazon Relational Database Service (RDS).
- Amazon ElastiCache.
- Identity Access Management.
- Amazon S3.
- Amazon Container Registry(ECR).
- Amazon Internet Gateway for public subnets.
- Amazon NatGateway Service for private subnets.
Moodledata: Moodle application stores the uploaded data in the moodledata directory which needs to be setupKey considerations for moodle cluster design: in a shared file system which can be accessible to the autoscaling group.
session cache: user session data to maintain application state as they work. We are using Amazon Elasticache service to maintain users active sessions in multiple availability zones if the container gets stopped.
Database: Used Amazon Aurora Relational Database Service with high availability setup.
Source code management: git and jenkins services are used to manage the source code keep update on all servers.
Proposed Solution & Architecture:
Let’s have a look at each area and we briefed how we make the system high available. (What and why
- Moodle app needs to be created as a docker image which we can run over Elastic Container Service.
- Database is stored in Amazon Aurora RDS(Mysql) and Moodle App container will connect.RDS designed in Multi-AZ database for redundancy and automated snapshots for backups, This takes a lot of the hassle out of managing a database and the point in time restore provides a real piece of mind.
- Users logged in sessions stored in Amazon Redis Cache Service to make all active sessions available if instances scale up .
- MoodleData stored in NFS file system, which will be auto mounted to ECS instances & docker containers. We avoided EFS as it has performance issues.
- S3 bucket used for load entry point configuration files to docker image whenever container gets started. (Application,WebServer,PHP).
- Ex: php.ini,confguration.php and nginx.conf
- Moodle data preserved over Gluster NFS. The reason we choose the NFS rather than EFS, EFS has limitations in performance issues.
- CacheStore used to store in Redis ,Which will make the userdata load faster rather than the traditional moodledata path.
- Any modifications in “plugins/application data ” need to maintain up to date over git/and docker image which brings back the system back when the container gets restarted. We used Jenkins to build the application docker images, whenever changes in plugins information entirely built the latest source and updated to ECS containers.
- Except ALB all resources are running in a private network multi zone availability.
- AutoScaling Policies defined to serve the requests from 1 to unlimited, resources scaled up based Requests.
- We used CloudFlare to protect DDOS/SQL mitigations from endpoint and also CDN for static Content.
Finally we achieved a HA solution for the AWS Hosted moodle application, with our approach by cutting down the costs of the standard method and increasing system availability.
In our further post we describe resources configurations and deployment source using github and CFT.
Creating Docker image for Moodle App
Make a moodle application docker image where the moodledata configuration points to EFS storage like below.
Docker file: “ GitHub Link which pointed to EFS”
Moodle Container Contains:
- Operating System (Ubuntu-18)
- Web Server ( Nginx)
- PHP7.x (incl. php-curl, php-mysql,php-redis,etc.)
- Ghostscript and syslog service
EFS file System for MoodleData: Amazon Elastic File System provides a simple and scalable NFS file system which is maintained by Amazon Web Services. Which is built to scale on at most petabytes without disturbing running apps.Growing and shrinking automatically as you add and remove files, eliminating the need to provision and manage capacity to accommodate growth.
Setup efs file system by following the below reference guide and move moodledata inside.
Efs endpoint ex: “fs-ID.efs.us-region.amazonaws.com”
Elastic Container Services for Managing Docker Containers: (Amazon ECS) is a highly scalable, fast, container management service that makes it easy to run, stop, and manage Docker containers on a cluster. We used this cluster to maintain all the time application containers to be up based on requests.
Creation of cluster and more info you can find from below link:
Auto Scaling Launch Configuration for ScalingUp Instances Access to Moodledata:
Update EC2 Launch configuration template userdata which keep mounting EFS file system to the scaling ecs nodes.
- yum install -y nfs-utils
- mkdir /moodle_data
- chmod 755 /moodle_data/
- echo “fs-e5c2befc.efs.us-region.amazonaws.com:/ /var/www/moodledata nfs4
- nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 0 0″ >> /etc/fstab
Amazon Application Load Balancer: Amazon Elastic LoadBalancer serves as the single point of contact for clients . The load balancer termites https requests and distributes incoming application traffic across multiple docker containers according to the optimal routing mechanism.
This article was originally created at https://ktree.com/blog/moodle-ha-setup-using-docker-over-aws.html
The post Moodle HA setup using docker over AWS appeared first on NASSCOM Community |The Official Community of Indian IT Industry.