・L7での負荷分散ができる
・ディレクトリパスでのルールを作れる
・SSLオフロードできる
・AWSのApplication Load Barancerてきな感じ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# リソースグループ作成 az group create --name myResourceGroupAG --location eastus # 仮想ネットワーク作成 az network vnet create \ --name myVNet \ --resource-group myResourceGroupAG \ --location eastus \ --address-prefix 10.0.0.0/16 \ --subnet-name myAGSubnet \ --subnet-prefix 10.0.1.0/24 az network vnet subnet create \ --name myBackendSubnet \ --resource-group myResourceGroupAG \ --vnet-name myVNet \ --address-prefix 10.0.2.0/24 az network public-ip create \ --resource-group myResourceGroupAG \ --name myAGPublicIPAddress \ --allocation-method Static \ --sku Standard |
Cloud-initを作る
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
yuta@DESKTOP-V36210S:/tmp$ cat cloud-init.txt #cloud-config package_upgrade: true packages: - nginx - nodejs - npm write_files: - owner: www-data:www-data - path: /etc/nginx/sites-available/default content: | server { listen 80; location / { proxy_pass http://localhost:3000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection keep-alive; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } } - owner: azureuser:azureuser - path: /home/azureuser/myapp/index.js content: | var express = require('express') var app = express() var os = require('os'); app.get('/', function (req, res) { res.send('Hello World from host ' + os.hostname() + '!') }) app.listen(3000, function () { console.log('Hello world app listening on port 3000!') }) runcmd: - service nginx restart - cd "/home/azureuser/myapp" - npm init - npm install express -y - nodejs index.js yuta@DESKTOP-V36210S:/tmp$ |
ネットワークインターフェースとVMの作成
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
for i in `seq 1 2`; do az network nic create \ --resource-group myResourceGroupAG \ --name myNic$i \ --vnet-name myVNet \ --subnet myBackendSubnet az vm create \ --resource-group myResourceGroupAG \ --name myVM$i \ --nics myNic$i \ --image UbuntuLTS \ --admin-username azureuser \ --generate-ssh-keys \ --custom-data cloud-init.txt done |
アプリケーションゲートウェイ作成
1 2 3 4 5 6 7 8 9 10 11 12 13 |
address1=$(az network nic show --name myNic1 --resource-group myResourceGroupAG | grep "\"privateIpAddress\":" | grep -oE '[^ ]+$' | tr -d '",') address2=$(az network nic show --name myNic2 --resource-group myResourceGroupAG | grep "\"privateIpAddress\":" | grep -oE '[^ ]+$' | tr -d '",') az network application-gateway create \ --name myAppGateway \ --location eastus \ --resource-group myResourceGroupAG \ --capacity 2 \ --sku Standard_v2 \ --http-settings-cookie-based-affinity Enabled \ --public-ip-address myAGPublicIPAddress \ --vnet-name myVNet \ --subnet myAGSubnet \ --servers "$address1" "$address2" |
できた
フロントエンド
バックエンド
パブリックIPアドレスを確認
1 2 3 4 5 |
yuta@DESKTOP-V36210S:/tmp$ az network public-ip show \ > --resource-group myResourceGroupAG \ > --name myAGPublicIPAddress \ > --query [ipAddress] \> --output tsv 52.142.38.233 yuta@DESKTOP-V36210S:/tmp$ |
どうかく