Quickstart: Direct web traffic with Azure Application Gateway using Azure PowerShell
आलेख
In this quickstart, you use Azure PowerShell to create an application gateway. Then you test it to make sure it works correctly.
The application gateway directs application web traffic to specific resources in a backend pool. You assign listeners to ports, create rules, and add resources to a backend pool. For the sake of simplicity, this article uses a simple setup with a public frontend IP address, a basic listener to host a single site on the application gateway, a basic request routing rule, and two virtual machines in the backend pool.
Application Gateway frontend now supports dual-stack IP addresses (Preview). You can now create up to four frontend IP addresses: Two IPv4 addresses (public and private) and two IPv6 addresses (public and private).
Azure hosts Azure Cloud Shell, an interactive shell environment that you can use through your browser. You can use either Bash or PowerShell with Cloud Shell to work with Azure services. You can use the Cloud Shell preinstalled commands to run the code in this article, without having to install anything on your local environment.
To start Azure Cloud Shell:
Option
Example/Link
Select Try It in the upper-right corner of a code or command block. Selecting Try It doesn't automatically copy the code or command to Cloud Shell.
Go to https://shell.azure.com, or select the Launch Cloud Shell button to open Cloud Shell in your browser.
Select the Cloud Shell button on the menu bar at the upper right in the Azure portal.
To use Azure Cloud Shell:
Start Cloud Shell.
Select the Copy button on a code block (or command block) to copy the code or command.
Paste the code or command into the Cloud Shell session by selecting Ctrl+Shift+V on Windows and Linux, or by selecting Cmd+Shift+V on macOS.
For Azure to communicate between the resources that you create, it needs a virtual network. The application gateway subnet can contain only application gateways. No other resources are allowed. You can either create a new subnet for Application Gateway or use an existing one. You create two subnets in this example: one for the application gateway, and another for the backend servers. You can configure the Frontend IP address of the Application Gateway to be Public or Private as per your use case. In this example, you'll choose a Public Frontend IP address.
Create the subnet configurations using New-AzVirtualNetworkSubnetConfig.
Create the virtual network with the subnet configurations using New-AzVirtualNetwork.
Create the public IP address using New-AzPublicIpAddress.
Use New-AzApplicationGatewayIPConfiguration to create the configuration that associates the subnet you created with the application gateway.
Use New-AzApplicationGatewayFrontendIPConfig to create the configuration that assigns the public IP address that you previously created for the application gateway.
Use New-AzApplicationGatewayFrontendPort to assign port 80 to access the application gateway.
Application Gateway frontend now supports dual-stack IP addresses (Public Preview). You can now create up to four frontend IP addresses: Two IPv4 addresses (public and private) and two IPv6 addresses (public and private).
Create the backend pool
Use New-AzApplicationGatewayBackendAddressPool to create the backend pool for the application gateway. The backend pool is empty for now. When you create the backend server NICs in the next section, you'll add them to the backend pool.
Configure the settings for the backend pool with New-AzApplicationGatewayBackendHttpSetting.
Azure requires a listener to enable the application gateway for routing traffic appropriately to the backend pool. Azure also requires a rule for the listener to know which backend pool to use for incoming traffic.
Create a listener using New-AzApplicationGatewayHttpListener with the frontend configuration and frontend port that you previously created.
Use New-AzApplicationGatewayRequestRoutingRule to create a rule named rule1.
You can modify values of the Name and Tier parameters to use a different SKU. For example: Basic.
Backend servers
Now that you have created the Application Gateway, create the backend virtual machines which will host the websites. A backend can be composed of NICs, virtual machine scale sets, public IP address, internal IP address, fully qualified domain names (FQDN), and multitenant backends like Azure App Service.
In this example, you create two virtual machines to use as backend servers for the application gateway. You also install IIS on the virtual machines to verify that Azure successfully created the application gateway.
Create two virtual machines
Get the recently created Application Gateway backend pool configuration with Get-AzApplicationGatewayBackendAddressPool.
Create a network interface with New-AzNetworkInterface.
Create a virtual machine configuration with New-AzVMConfig.
Create the virtual machine with New-AzVM.
When you run the following code sample to create the virtual machines, Azure prompts you for credentials. Enter a user name and a password:
Although IIS isn't required to create the application gateway, you installed it in this quickstart to verify if Azure successfully created the application gateway.
Use IIS to test the application gateway:
Run Get-AzPublicIPAddress to get the public IP address of the application gateway.
Copy and paste the public IP address into the address bar of your browser. When you refresh the browser, you should see the name of the virtual machine. A valid response verifies that the application gateway was successfully created and it can successfully connect with the backend.
When you no longer need the resources that you created with the application gateway, delete the resource group. When you delete the resource group, you also delete the application gateway and all its related resources.
To delete the resource group, call the Remove-AzResourceGroup cmdlet:
इस मॉड्यूल में, आप कई सर्वरों पर लोड वितरित करके एप्लिकेशन लचीलापन में सुधार करना सीखेंगे और वेब ट्रैफ़िक को निर्देशित करने के लिए पथ-आधारित रूटिंग का उपयोग करेंगे।