|
| 1 | +--- |
| 2 | +title: Private Link for Azure Database for MariaDB (Preview) CLI setup method |
| 3 | +description: Learn how to configure private link for Azure Database for MariaDB from Azure CLI |
| 4 | +author: kummanish |
| 5 | +ms.author: manishku |
| 6 | +ms.service: mariadb |
| 7 | +ms.topic: conceptual |
| 8 | +ms.date: 01/09/2020 |
| 9 | +--- |
| 10 | + |
| 11 | +# Create and manage Private Link for Azure Database for MariaDB (Preview) using CLI |
| 12 | + |
| 13 | +A Private Endpoint is the fundamental building block for private link in Azure. It enables Azure resources, like Virtual Machines (VMs), to communicate privately with private link resources. In this article, you will learn how to use the Azure CLI to create a VM in an Azure Virtual Network and an Azure Database for MariaDB server with an Azure private endpoint. |
| 14 | + |
| 15 | +> [!NOTE] |
| 16 | +> This feature is available in all Azure regions where Azure Database for MariaDB supports General Purpose and Memory Optimized pricing tiers. |
| 17 | +
|
| 18 | +## Prerequisites |
| 19 | + |
| 20 | +To step through this how-to guide, you need: |
| 21 | + |
| 22 | +- An [Azure Database for MariaDB server](quickstart-create-mariadb-server-database-using-azure-cli.md). |
| 23 | + |
| 24 | +[!INCLUDE [cloud-shell-try-it.md](../../includes/cloud-shell-try-it.md)] |
| 25 | + |
| 26 | +If you decide to install and use Azure CLI locally instead, this quickstart requires you to use Azure CLI version 2.0.28 or later. To find your installed version, run `az --version`. See [Install Azure CLI](/cli/azure/install-azure-cli) for install or upgrade info. |
| 27 | + |
| 28 | +## Create a resource group |
| 29 | + |
| 30 | +Before you can create any resource, you have to create a resource group to host the Virtual Network. Create a resource group with [az group create](/cli/azure/group). This example creates a resource group named *myResourceGroup* in the *westeurope* location: |
| 31 | + |
| 32 | +```azurecli-interactive |
| 33 | +az group create --name myResourceGroup --location westeurope |
| 34 | +``` |
| 35 | + |
| 36 | +## Create a Virtual Network |
| 37 | +Create a Virtual Network with [az network vnet create](/cli/azure/network/vnet). This example creates a default Virtual Network named *myVirtualNetwork* with one subnet named *mySubnet*: |
| 38 | + |
| 39 | +```azurecli-interactive |
| 40 | +az network vnet create \ |
| 41 | + --name myVirtualNetwork \ |
| 42 | + --resource-group myResourceGroup \ |
| 43 | + --subnet-name mySubnet |
| 44 | +``` |
| 45 | + |
| 46 | +## Disable subnet private endpoint policies |
| 47 | +Azure deploys resources to a subnet within a virtual network, so you need to create or update the subnet to disable private endpoint network policies. Update a subnet configuration named *mySubnet* with [az network vnet subnet update](https://docs.microsoft.com/cli/azure/network/vnet/subnet?view=azure-cli-latest#az-network-vnet-subnet-update): |
| 48 | + |
| 49 | +```azurecli-interactive |
| 50 | +az network vnet subnet update \ |
| 51 | + --name mySubnet \ |
| 52 | + --resource-group myResourceGroup \ |
| 53 | + --vnet-name myVirtualNetwork \ |
| 54 | + --disable-private-endpoint-network-policies true |
| 55 | +``` |
| 56 | +## Create the VM |
| 57 | +Create a VM with az vm create. When prompted, provide a password to be used as the sign-in credentials for the VM. This example creates a VM named *myVm*: |
| 58 | +```azurecli-interactive |
| 59 | +az vm create \ |
| 60 | + --resource-group myResourceGroup \ |
| 61 | + --name myVm \ |
| 62 | + --image Win2019Datacenter |
| 63 | +``` |
| 64 | + Note the public IP address of the VM. You will use this address to connect to the VM from the internet in the next step. |
| 65 | + |
| 66 | +## Create an Azure Database for MariaDB server |
| 67 | +Create a Azure Database for MariaDB with the az mariadb server create command. Remember that the name of your MariaDB Server must be unique across Azure, so replace the placeholder value in brackets with your own unique value: |
| 68 | + |
| 69 | +```azurecli-interactive |
| 70 | +# Create a logical server in the resource group |
| 71 | +az mariadb server create \ |
| 72 | +--name mydemoserver \ |
| 73 | +--resource-group myResourcegroup \ |
| 74 | +--location westeurope \ |
| 75 | +--admin-user mylogin \ |
| 76 | +--admin-password <server_admin_password> \ |
| 77 | +--sku-name GP_Gen5_2 |
| 78 | +``` |
| 79 | + |
| 80 | +Note the MariaDB Server ID is similar to ```/subscriptions/subscriptionId/resourceGroups/myResourceGroup/providers/Microsoft.DBforMariaDB/servers/servername.``` |
| 81 | +You will use the MariaDB Server ID in the next step. |
| 82 | + |
| 83 | +## Create the Private Endpoint |
| 84 | +Create a private endpoint for the MariaDB server in your Virtual Network: |
| 85 | +```azurecli-interactive |
| 86 | +az network private-endpoint create \ |
| 87 | + --name myPrivateEndpoint \ |
| 88 | + --resource-group myResourceGroup \ |
| 89 | + --vnet-name myVirtualNetwork \ |
| 90 | + --subnet mySubnet \ |
| 91 | + --private-connection-resource-id "<MariaDB Server ID>" \ |
| 92 | + --group-ids mariadbServer \ |
| 93 | + --connection-name myConnection |
| 94 | + ``` |
| 95 | + |
| 96 | +## Configure the Private DNS Zone |
| 97 | +Create a Private DNS Zone for MariDB server domain and create an association link with the Virtual Network. |
| 98 | +```azurecli-interactive |
| 99 | +az network private-dns zone create --resource-group myResourceGroup \ |
| 100 | + --name "privatelink.database.azure.com" |
| 101 | +az network private-dns link vnet create --resource-group myResourceGroup \ |
| 102 | + --zone-name "privatelink.database.azure.com"\ |
| 103 | + --name MyDNSLink \ |
| 104 | + --virtual-network myVirtualNetwork \ |
| 105 | + --registration-enabled false |
| 106 | +
|
| 107 | +#Query for the network interface ID |
| 108 | +networkInterfaceId=$(az network private-endpoint show --name myPrivateEndpoint --resource-group myResourceGroup --query 'networkInterfaces[0].id' -o tsv) |
| 109 | + |
| 110 | + |
| 111 | +az resource show --ids $networkInterfaceId --api-version 2019-04-01 -o json |
| 112 | +# Copy the content for privateIPAddress and FQDN matching the Azure database for MariaDB name |
| 113 | + |
| 114 | + |
| 115 | +#Create DNS records |
| 116 | +az network private-dns record-set a create --name mydemoserver --zone-name privatelink.database.azure.com --resource-group myResourceGroup |
| 117 | +az network private-dns record-set a add-record --record-set-name mydemoserver --zone-name privatelink.database.windows.net --resource-group myResourceGroup -a <Private IP Address> |
| 118 | +``` |
| 119 | + |
| 120 | +## Connect to a VM from the internet |
| 121 | + |
| 122 | +Connect to the VM *myVm* from the internet as follows: |
| 123 | + |
| 124 | +1. In the portal's search bar, enter *myVm*. |
| 125 | + |
| 126 | +1. Select the **Connect** button. After selecting the **Connect** button, **Connect to virtual machine** opens. |
| 127 | + |
| 128 | +1. Select **Download RDP File**. Azure creates a Remote Desktop Protocol (*.rdp*) file and downloads it to your computer. |
| 129 | + |
| 130 | +1. Open the downloaded.rdp* file. |
| 131 | + |
| 132 | + 1. If prompted, select **Connect**. |
| 133 | + |
| 134 | + 1. Enter the username and password you specified when creating the VM. |
| 135 | + |
| 136 | + > [!NOTE] |
| 137 | + > You may need to select **More choices** > **Use a different account**, to specify the credentials you entered when you created the VM. |
| 138 | +
|
| 139 | +1. Select **OK**. |
| 140 | + |
| 141 | +1. You may receive a certificate warning during the sign-in process. If you receive a certificate warning, select **Yes** or **Continue**. |
| 142 | + |
| 143 | +1. Once the VM desktop appears, minimize it to go back to your local desktop. |
| 144 | + |
| 145 | +## Access the MariaDB server privately from the VM |
| 146 | + |
| 147 | +1. In the Remote Desktop of *myVM*, open PowerShell. |
| 148 | + |
| 149 | +2. Enter `nslookup mydemoserver.mariadb.privatelink.database.azure.com`. |
| 150 | + |
| 151 | + You'll receive a message similar to this: |
| 152 | + ```azurepowershell |
| 153 | + Server: UnKnown |
| 154 | + Address: 168.63.129.16 |
| 155 | + Non-authoritative answer: |
| 156 | + Name: mydemoserver.mariadb.privatelink.database.azure.com |
| 157 | + Address: 10.1.3.4 |
| 158 | +
|
| 159 | +3. Test the private link connection for the MariaDB server using any available client. In the example below I have used [MySQL Workbench](https://dev.mysql.com/doc/workbench/wb-installing-windows.html) to do the operation. |
| 160 | +
|
| 161 | +4. In **New connection**, enter or select this information: |
| 162 | +
|
| 163 | + | Setting | Value | |
| 164 | + | ------- | ----- | |
| 165 | + | Connection Name| Select the connection name of your choice.| |
| 166 | + | Hostname | Select *mydemoserver.mariadb.privatelink.database.azure.com* | |
| 167 | + | Username | Enter username as *username@servername* which is provided during the MariaDB server creation. | |
| 168 | + | Password | Enter a password provided during the MariaDB server creation. | |
| 169 | + || |
| 170 | +
|
| 171 | +5. Select **Test Connection** or **OK**. |
| 172 | +
|
| 173 | +6. (Optionally) Browse databases from left menu and Create or query information from the MariaDB database |
| 174 | +
|
| 175 | +8. Close the remote desktop connection to myVm. |
| 176 | +
|
| 177 | +## Clean up resources |
| 178 | +When no longer needed, you can use az group delete to remove the resource group and all the resources it has: |
| 179 | +
|
| 180 | +```azurecli-interactive |
| 181 | +az group delete --name myResourceGroup --yes |
| 182 | +``` |
| 183 | + |
| 184 | +## Next steps |
| 185 | +Learn more about [What is Azure private endpoint](https://docs.microsoft.com/azure/private-link/private-endpoint-overview) |
0 commit comments