Create an auto-scaled Web cluster using arm and VMSS

Source: Internet
Author: User

In many business scenarios, the user's access, peak time is difficult to predict, especially when doing some marketing campaigns and promotions, exactly what size of the Web cluster deployment is appropriate, this has been a problem, the deployment of excessive will cause high costs and unnecessary waste of resources, deployment too little, if the peak, too late to deploy, Easy to create user access, poor user experience, loss of trade, and so on, of course, not to mention the operation and maintenance personnel at all times the nerve tightness of the real-time monitoring pressure situation, in order to take measures in time ...

In today's fast-paced cloud computing technology, this scenario is very discordant: VMSS, as a new approach to Azure computing, provides automatic scaling of contraction according to the pressure load, while supporting both Windows and Linux, while providing the IaaS level of control flexibility, It also provides a PAAs-level auto-scaling, ideal for scenarios such as stateless Web server applications, and this article describes how to create an auto-load-balanced Web server cluster that automatically scales with your CPU load through arm templates and VMSs:

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/845013/201610/845013-20161012233124015-585916935. PNG "style=" border:0px; "/>

In this template, you will create the following test environment:

    1. Defines a load balancer that is responsible for forwarding front-end Web requests to the backend Web cluster

    2. Create a Web cluster using VMSS

    3. Automate the installation of Apache Web servers, and PHP Web applications using custom scripting

    4. A rule that defines an auto-extended collection, which automatically expands or shrinks depending on the CPU load in the virtual machine's auto-scaling collection, and automatically adds or removes the virtual machine automatically in the load balancer

    5. Pressure test kit, can use Loadrunner,apache ab and so on, in this case, using PHP to generate pressure to meet CPU threshold requirements

    6. For the original arm template, refer to the Quick Start template for Azure:

Https://github.com/Azure/azure-quickstart-templates/tree/master/201-vmss-lapstack-autoscale

    1. I have modified the following templates that can be run directly on Azure China:

      Https://github.com/kingliantop/azurelabs/tree/master/AzureChinaARMTemplate/vmss-lapstack-autoscale

Template definition:

  1. For the basic definition of VMSS, the aforementioned documents have been introduced, not to repeat, we first look at the definition of load balancer, first we need to add a load balancer resources, this resource depends on the public IP address, the front-end address is the public IP address:

    650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/845013/201610/845013-20161012233124546-972973566. PNG "style=" border:0px; "/>

  2. Next we need to define the rules of load balancing, the front-end request through the DNS or public IP address in the future, through the default address distribution to the backend IP resource pool, the protocol is TCP, the front and back end ports are standard 80 ports, you can also set the load Balancer idle timeout time, This time will determine your connection idle time, the longest but set to 30 minutes, because we follow the main configuration is the HTTP request, so we mainly set a probe for 80 port to determine the health of the backend virtual machine:

    650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/845013/201610/845013-20161012233125281-1260912096. PNG "style=" border:0px; "/>

  3. To facilitate user-specific deployment and rapid scaling, Azure offers custom scripting extensions that allow you to run custom scripts, install your own software, deploy your own apps after virtual machine deployment is complete, and use the following to put your app in azure storage This example is placed on GitHub and then executed bash to install the configuration:

    650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/845013/201610/845013-20161012233125937-1810902755. PNG "style=" border:0px; "/>

    In this test, two PHP Web files are provided, one is index.php, which is used to show which server the current Web application is running on, and the other is do_work.php used to put pressure on the Web server, triggering automatic scaling.

  4. Finally, we need to configure the rules for VMSS auto-scaling, under what circumstances to automatically expand, under what circumstances, automatic contraction, in this case, we define the load of the average CPU in the entire VMSS in the last 5 minutes over 60% to automatically expand, less than 50% when the automatic contraction:

    650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/845013/201610/845013-20161012233126375-1864989197. PNG "style=" border:0px; "/>

  5. Finally we need to configure the parameter file, define the name of the VMSS, the initial in the VMSS need a few virtual machines, user name and password can:

    650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/845013/201610/845013-20161012233126812-590222009. PNG "style=" border:0px; "/>

  6. Finally, we use PowerShell to deploy, I have written a deploy.ps1 file, you can modify the next parameter under PowerShell, directly execute it, such as the name of the resource group you want, the deployment of the region and other parameters, and then execute under PowerShell:

    #用你的Azure账号登陆

    Login-azurermaccount-environmentname Azurechinacloud

    #执行部署脚本

    650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/845013/201610/845013-20161012233127250-10672170. PNG "style=" border:0px; "/>

  7. Once the deployment is complete, you can see that the new VMSS collection has been successfully deployed, including an extension set, a load balancer, a public IP address, and multiple storage accounts for distributing VMS, as you log into azure new portal,https://portal.azure.cn:

    650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/845013/201610/845013-20161012233127843-1353576136. PNG "style=" border:0px; "/>

  8. Open the virtual machine extension set, view the current instance, and see that there are currently 2 instances:

    650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/845013/201610/845013-20161012233128312-1142296003. PNG "style=" border:0px; "/>

9. Click on the load balancer, get the IP address or DNS of the public network, open in the browser, you can see the current connection is the 001 Web server, the page is a demo page to create pressure on the virtual machine; Open a browser, connect the load balancer, and see that the request is distributed to 002 Web server:

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/845013/201610/845013-20161012233128671-1407369363. PNG "style=" border:0px; "/>

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/845013/201610/845013-20161012233129109-389879525. PNG "style=" border:0px; "/>

10. On the current test page, enter 500 seconds, as the stress test duration, click "Do Work", then the PHP program will generate pressure, full CPU:

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/845013/201610/845013-20161012233130250-1585998276. PNG "style=" border:0px; "/>

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/845013/201610/845013-20161012233130671-2064743272. PNG "style=" border:0px; "/>

11. Wait about 5, 6 minutes later, 5 minutes of CPU load more than 60%, we open the new portal's Virtual Machine Extension Page Instance page, we can see, according to our definition of VMSS auto-scaling rules, the virtual machine began to automatically increase:

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/845013/201610/845013-20161012233131046-953388682. PNG "style=" border:0px; "/>

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/845013/201610/845013-20161012233131578-340847082. PNG "style=" border:0px; "/>

12. Test the site using a different browser, and also see that the site request will be distributed to the newly established server b,c,f and so on, indicating that the automatic expansion set is increasing the Web server, it will also automatically update the load balancer settings, so that the front-end client's request by default hash rules distributed to the backend server, To achieve dynamic load balancing:

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/845013/201610/845013-20161012233132203-2016924293. PNG "style=" border:0px; "/>

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/845013/201610/845013-20161012233132593-96508594. PNG "style=" border:0px; "/>

13. The pressure test is complete, the pressure of the virtual machine expansion set is gradually lower than 50%, this time, the entire virtual machine extension collection will monitor the load situation of the last 5 minutes, once the shrinkage requirements are met, the cooldown process will be executed, gradually remove the Web server, also removed from the load balancer, reduce costs:

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/845013/201610/845013-20161012233132953-857780302. PNG "style=" border:0px; "/>

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/845013/201610/845013-20161012233133281-823226437. PNG "style=" border:0px; "/>

With this test, we can easily use Vmss+arm to quickly build automated, extensible web clusters and deploy our applications using custom scripts.


Create an auto-scaled Web cluster using arm and VMSS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.