Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

An Auto-Scalable Magento Cluster in Containers

DZone's Guide to

An Auto-Scalable Magento Cluster in Containers

Head over to Docker Hub, grab your containers, then get ready to create a scalable, resilient Magento e-commerce solution.

· Cloud Zone
Free Resource

Are you joining the containers revolution? Start leveraging container management using Platform9's ultimate guide to Kubernetes deployment.

magento platform in cloudIf you're building an e-commerce project that requires a feature-rich platform, the Magento CMS is one of the most suitable and efficient systems to handle it with. Due to its flexible modular architecture and agile ecosystem, you can continually adapt, customize, and extend your website, benefiting from a large variety of embedded features like data catalog management, marketing tools, analytics, SEO engine optimization, reporting, etc. Another important point to consider when running an e-commerce project is ensuring its constant availability for lots of concurrent users. Thus, to enable such a solution with minimal effort, the Jelastic team has developed a dedicated auto-scalable clustered Magento package.

Being deployed in an almost one click, the Magento Cluster JPS by Jelastic runs a complex, container-based failover topology with a pair of interconnected Magento nodes, a load balancer in front of them, and two replicated database servers. In addition, it includes a number of supplementary components like user session storage for increased fault-tolerance, a Redis caching service, and an NGINX-based administration node to distribute static content and manage cluster configurations. Altogether, such an environment topology provides the sustainability your project needs.

Below, you’ll find some details on each cluster component's functions, preconfigured auto-scaling settings, and a simple step-by-step guide describing how to get your own highly available clustered Magento platform up and running within the cloud in several minutes.

Generally, the structure of the auto-scalable Magento Cluster solution by Jelastic can be displayed as follows:auto scalable magento platformHere, the following Docker images are utilized to unify and simplify the provisioning of application components:

  • Load Balancer (LB) – Varnish 4.1.5 (jelastic/varnish)
    Two Varnish load balancers to distribute incoming traffic within a cluster and to cache all static content; they are supplemented with NGINX servers that are run as an HTTPS proxy.
  • Application Server (AS) – NGINX 1.10.1 powered by PHP 7.0.10 (jelastic/nginxphp)
    Two NGINX PHP application servers to handle the Magento engine itself; they are automatically scaled based on the amount of incoming traffic.
  • Admin Node (AN) – NGINX 1.10.1 powered by PHP 7.0.10 (jelastic/nginxphp)
    NGINX PHP admin node to provide access to the Magento Admin Panel for managing orders, catalogs, content, cluster configurations, etc. and to share static content between application server instances via NFS.
  • Session Storage (SS) – Redis 3.2.9 (devbeta/redis)
    Redis storage node to retain user session parameters so that in case one application server node fails, the second one can retrieve the required data and continue serving clients without any notable interruption.
  • Cache (CH) – Redis 3.2.9 (devbeta/redis)
    Redis node to store the Magento cache, which helps to improve application response time due to faster page loading when processing similar subsequent requests.
  • Database (DB) – MySQL 5.7.latest (jelastic/mysql)
    Two MySQL database servers with asynchronous master-slave replication between them to achieve high availability, improve data protection, and alleviate system failures.

Here, each container within a cluster receives the default vertical scaling limit up to 8 cloudlets (equals to 1 GiB of RAM and 3.2 GHz of CPU) and a set of load alerts (to notify you when resource consumption is close to the limit).

Also, it’s worth noting that when you scale either the Load Balancer or Application Server layer, the appropriate LB configs (at either the newly created or the already existing instance(s) respectively) are automatically adjusted to include the data on all application server nodes the load should be distributed across. In addition, the AS layer is automatically scaled by the system based on the amount of incoming traffic in order to handle the changeable load – let’s consider this approach in more detail.

Magento Application Server Auto-Scaling Settings

As it was mentioned above, the number of application server nodes in our Magento Cluster is adjusted dynamically based on the received load by means of automatic horizontal scaling. Such a cluster size change is defined with the following conditions:

  • +1 node if CPU usage is more than 70% for at least 1 minute
  • -1 node if CPU usage is less than 20% for at least 1 minute

The appropriate modifications are automatically applied to add/remove application server nodes, whilst you receive the corresponding email message on each scaling operation. Each new application server instance is automatically added to the load balancer configs, whilst nodes within the LB layer are restarted to apply the updated settings.

The default automatic scaling conditions can be easily tuned by adjusting the appropriate trigger settings in accordance with the Automatic Horizontal Scaling guide.

Finally, let’s get to know how to launch the above-described auto-scalable and reliable Magento-based e-commerce platform. For that, log into your Jelastic Cloud dashboard and execute the next steps.

The package can be installed in one of the following ways:

https://github.com/jelastic-jps/magento/blob/master/magento19-php7-varnish-mysql-redis-storage/manifest.jpsrunning magento Click Import to continue.

Tip: Visit the  Jelastic JPS Collection to explore other useful pre-packaged solutions that can be easily installed to the Platform in one click. Just import any of them using the link to the  manifest.jps file within the appropriate repository.

In the installation box, type an Environment name and an optional Display Name (environment alias), select the preferable region (if several ones are available), and click Install.instant magento cluster deployThe environment installation and cluster configuration will take a few minutes. When it is done, you’ll see a box displaying your Magento Admin credentials.instant cluster deployClick Open in browser and log into the Magento Admin Panel with the received administration data.

auto scalable magento in docker
Here you can find a big variety of store management tools categorized within separate tabs according to the provisioned options – e.g. Sales, Catalog, Customers, Promotions, etc.

To start with, you can build a catalog for your online store as the very base of any e-commerce service. For that, you’ll need to compose the required catalog structure and fill it in with the proposed merch items.

Tip: Alternatively, Magento allows importing of the already existing goods collection, e.g. to transfer a catalog from the similar Magento platform at another host. However, this procedure could require a number of additional configurations – we’ll describe them in detail within the next publication of the Magento Cluster series to provide fuller guidance.

If deciding to build catalog from the scratch, switch to the Catalog > Manage Categories tab of the Magento Admin Panel to create the appropriate product categories and set a root category for your store.

running magento in cloud

After that, you can proceed with adding catalog subcategories to define a more precise hierarchical sections structure and filling them in with created products so that, subsequently, your customers can easily find and buy them.

Use this panel to monitor sales and customer activity, manage your catalog and its content, create promotions and newsletters, etc – in short, to implement all the staff that constitutes a high-quality and demanded service.

Using Containers? Read our Kubernetes Comparison eBook to learn the positives and negatives of Kubernetes, Mesos, Docker Swarm and EC2 Container Services.

Topics:
cloud ,magento ,docker ,high availability ,tutorial

Published at DZone with permission of Tetiana Markova, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}