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:
In this template, you will create the following test environment:
- Defines a load balancer that is responsible for forwarding front-end Web requests to the backend Web cluster
- Create a Web cluster using VMSS
- Automate the installation of Apache Web servers, and PHP Web applications using custom scripting
- 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
- Pressure test kit, can use Loadrunner,apache ab and so on, in this case, using PHP to generate pressure to meet CPU threshold requirements
- 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
- 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:
- 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:
?
?
- 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:
?
- 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:
?
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.
?
- 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:
?
?
- 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:
- 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
#执行部署脚本
- 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:
- Open the virtual machine extension set, view the current instance, and see that there are currently 2 instances:
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:
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:
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:
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:
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:
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