Azure webservice + load balancer
This commit is contained in:
parent
31d5a09460
commit
9af7d146c4
13
webservice-balancer/Azure/Azure.Dockerfile
Normal file
13
webservice-balancer/Azure/Azure.Dockerfile
Normal file
@ -0,0 +1,13 @@
|
||||
FROM ubuntu
|
||||
|
||||
VOLUME /opt/app
|
||||
WORKDIR /opt/app
|
||||
|
||||
RUN apt update && apt install curl -y
|
||||
RUN curl -sL https://aka.ms/InstallAzureCLIDeb | bash
|
||||
RUN apt install jq -y
|
||||
|
||||
COPY . .
|
||||
RUN chmod +x ./deploy.sh
|
||||
|
||||
CMD ["bash", "-c", "az login;./deploy.sh"]
|
23
webservice-balancer/Azure/README.md
Normal file
23
webservice-balancer/Azure/README.md
Normal file
@ -0,0 +1,23 @@
|
||||
# Just some README
|
||||
W celu utworzenia zasobów z wykorzystaniem skryptów zawartych w tym folderze należy:
|
||||
- posiadać zainstalowanego `Dockera`
|
||||
- zbudować obraz i uruchomić kontener
|
||||
```bash
|
||||
docker build -f ./Azure.Dockerfile -t azure-image .
|
||||
docker run -it azure-image
|
||||
```
|
||||
- postępować zgodnie z instrukacjami wyświetlanymi w terminalu
|
||||
--------------------
|
||||
W celu usunięcia utworzonych zasobów uruchomić wcześniej stworzony kontener i wykonać w nim skrypt:
|
||||
|
||||
```bash
|
||||
./clean.sh
|
||||
```
|
||||
###### ...lub wyklikać w portalu Azure
|
||||
___
|
||||
|
||||
W przeprowadzonym teście uzyskano takie oto krzywe
|
||||
![krzywe czasów odpowiedzi](./test_results.png "Krzywe czasów odpowiedzi na żądania")
|
||||
___
|
||||
|
||||
To chyba wszystko
|
5
webservice-balancer/Azure/clean.sh
Executable file
5
webservice-balancer/Azure/clean.sh
Executable file
@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
RESOURCE_GROUP_NAME="webservice-s478841"
|
||||
|
||||
az group delete --name $RESOURCE_GROUP_NAME --yes
|
214
webservice-balancer/Azure/deploy.sh
Executable file
214
webservice-balancer/Azure/deploy.sh
Executable file
@ -0,0 +1,214 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
USERNAME="s478841"
|
||||
RESOURCE_GROUP_NAME="webservice-$USERNAME"
|
||||
VNET_NAME="webservice-vnet-$USERNAME"
|
||||
SUBNET_NAME="webservice-subnet-$USERNAME"
|
||||
LOADBALANCER_NAME="webservice-loadbalancer-$USERNAME"
|
||||
LOAD_BALANCER_PUBLIC_IP="webservice-loadbalancer-publicip-$USERNAME"
|
||||
LOCATION="uksouth"
|
||||
|
||||
CI_WEBSERVICE="#cloud-config
|
||||
runcmd:
|
||||
- cd /home/$USERNAME
|
||||
- git clone https://git.wmi.amu.edu.pl/s478841/DPZC-Hetzner.git
|
||||
- cd DPZC-Hetzner/webservice-balancer
|
||||
- chmod +x ./webservice
|
||||
- ./webservice
|
||||
"
|
||||
|
||||
# Create resource group
|
||||
echo "Creating RESOURCE GROUP..."
|
||||
az group create --name $RESOURCE_GROUP_NAME --location $LOCATION
|
||||
|
||||
echo "Creating VNET..."
|
||||
az network vnet create \
|
||||
--resource-group $RESOURCE_GROUP_NAME \
|
||||
--location $LOCATION \
|
||||
--name $VNET_NAME \
|
||||
--address-prefixes 10.1.0.0/16 \
|
||||
--subnet-name $SUBNET_NAME \
|
||||
--subnet-prefixes 10.1.0.0/24
|
||||
|
||||
|
||||
echo "Creating PUBLIC IP..."
|
||||
lbPublicIp=$(az network public-ip create \
|
||||
--resource-group $RESOURCE_GROUP_NAME \
|
||||
--name $LOAD_BALANCER_PUBLIC_IP \
|
||||
--sku Standard)
|
||||
|
||||
lbPublicIpAddr=$(echo $lbPublicIp | jq .publicIp.ipAddress)
|
||||
|
||||
|
||||
echo "Creating LOAD BALANCER..."
|
||||
az network lb create \
|
||||
--resource-group $RESOURCE_GROUP_NAME \
|
||||
--name $LOADBALANCER_NAME \
|
||||
--sku Standard \
|
||||
--public-ip-address $LOAD_BALANCER_PUBLIC_IP \
|
||||
--frontend-ip-name "$USERNAME"FrontEnd \
|
||||
--backend-pool-name "$USERNAME"BackEndPool
|
||||
|
||||
echo "Creating LOAD BALANCER HEALTH PROBE..."
|
||||
az network lb probe create \
|
||||
--resource-group $RESOURCE_GROUP_NAME \
|
||||
--lb-name $LOADBALANCER_NAME \
|
||||
--name "$USERNAME"HealthProbe \
|
||||
--protocol http \
|
||||
--port 8080 \
|
||||
--path /factors/10 \
|
||||
--interval 300
|
||||
|
||||
echo "Creating LOAD BALANCER RULE..."
|
||||
az network lb rule create \
|
||||
--resource-group $RESOURCE_GROUP_NAME \
|
||||
--lb-name $LOADBALANCER_NAME \
|
||||
--name "$USERNAME"HTTPRule \
|
||||
--protocol tcp \
|
||||
--frontend-port 8080 \
|
||||
--backend-port 8080 \
|
||||
--frontend-ip-name "$USERNAME"FrontEnd \
|
||||
--backend-pool-name "$USERNAME"BackEndPool \
|
||||
--probe-name "$USERNAME"HealthProbe \
|
||||
--idle-timeout 4
|
||||
|
||||
|
||||
echo "Creating NETWORK SECURITY GROUP..."
|
||||
az network nsg create \
|
||||
--resource-group $RESOURCE_GROUP_NAME \
|
||||
--name "$USERNAME"NSG
|
||||
|
||||
|
||||
echo "Creating NETWORK SECURITY GROUP RULES..."
|
||||
az network nsg rule create \
|
||||
--resource-group $RESOURCE_GROUP_NAME \
|
||||
--nsg-name "$USERNAME"NSG \
|
||||
--name "$USERNAME"NSGRuleHTTP \
|
||||
--protocol '*' \
|
||||
--direction inbound \
|
||||
--source-address-prefix '*' \
|
||||
--source-port-range '*' \
|
||||
--destination-address-prefix '*' \
|
||||
--destination-port-range 80 \
|
||||
--access allow \
|
||||
--priority 200
|
||||
|
||||
az network nsg rule create \
|
||||
--resource-group $RESOURCE_GROUP_NAME \
|
||||
--nsg-name "$USERNAME"NSG \
|
||||
--name "$USERNAME"NSGRuleHTTP \
|
||||
--protocol '*' \
|
||||
--direction inbound \
|
||||
--source-address-prefix '*' \
|
||||
--source-port-range '*' \
|
||||
--destination-address-prefix '*' \
|
||||
--destination-port-range 8080 \
|
||||
--access allow \
|
||||
--priority 205
|
||||
|
||||
az network nsg rule create \
|
||||
--resource-group $RESOURCE_GROUP_NAME \
|
||||
--nsg-name "$USERNAME"NSG \
|
||||
--name allowSSH \
|
||||
--protocol '*' \
|
||||
--direction inbound \
|
||||
--source-address-prefix '*' \
|
||||
--source-port-range '*' \
|
||||
--destination-address-prefix '*' \
|
||||
--destination-port-range 22 \
|
||||
--access allow \
|
||||
--priority 210
|
||||
|
||||
|
||||
array=("$USERNAME"NicVM1 "$USERNAME"NicVM2 "$USERNAME"NicVM3 "$USERNAME"NicVM4 "$USERNAME"NicVM5)
|
||||
for vmnic in "${array[@]}"; do
|
||||
echo "Creating NIC $vmnic..."
|
||||
az network nic create \
|
||||
--resource-group $RESOURCE_GROUP_NAME \
|
||||
--name $vmnic \
|
||||
--vnet-name $VNET_NAME \
|
||||
--subnet $SUBNET_NAME \
|
||||
--network-security-group "$USERNAME"NSG
|
||||
done
|
||||
|
||||
|
||||
echo "Creating SSH key..."
|
||||
az sshkey create \
|
||||
--resource-group $RESOURCE_GROUP_NAME \
|
||||
--name "$USERNAME"Key
|
||||
|
||||
|
||||
echo "Creating VM1..."
|
||||
az vm create \
|
||||
--resource-group $RESOURCE_GROUP_NAME \
|
||||
--name "$USERNAME"VM1 \
|
||||
--nics "$USERNAME"NicVM1 \
|
||||
--image Canonical:0001-com-ubuntu-server-focal:20_04-lts:latest \
|
||||
--admin-username $USERNAME \
|
||||
--size Standard_B1s \
|
||||
--custom-data "$CI_WEBSERVICE" \
|
||||
--ssh-key-name "$USERNAME"Key
|
||||
|
||||
echo " 2"
|
||||
az vm create \
|
||||
--resource-group $RESOURCE_GROUP_NAME \
|
||||
--name "$USERNAME"VM2 \
|
||||
--nics "$USERNAME"NicVM2 \
|
||||
--image Canonical:0001-com-ubuntu-server-focal:20_04-lts:latest \
|
||||
--admin-username $USERNAME \
|
||||
--size Standard_B1s \
|
||||
--custom-data "$CI_WEBSERVICE" \
|
||||
--ssh-key-name "$USERNAME"Key
|
||||
|
||||
echo "Creating VM3..."
|
||||
az vm create \
|
||||
--resource-group $RESOURCE_GROUP_NAME \
|
||||
--name "$USERNAME"VM3 \
|
||||
--nics "$USERNAME"NicVM3 \
|
||||
--image Canonical:0001-com-ubuntu-server-focal:20_04-lts:latest \
|
||||
--admin-username $USERNAME \
|
||||
--size Standard_B1s \
|
||||
--custom-data "$CI_WEBSERVICE" \
|
||||
--ssh-key-name "$USERNAME"Key
|
||||
|
||||
echo "Creating VM4..."
|
||||
az vm create \
|
||||
--resource-group $RESOURCE_GROUP_NAME \
|
||||
--name "$USERNAME"VM4 \
|
||||
--nics "$USERNAME"NicVM4 \
|
||||
--image Canonical:0001-com-ubuntu-server-focal:20_04-lts:latest \
|
||||
--admin-username $USERNAME \
|
||||
--size Standard_B1s \
|
||||
--custom-data "$CI_WEBSERVICE" \
|
||||
--ssh-key-name "$USERNAME"Key
|
||||
|
||||
echo "Creating VM5..."
|
||||
az vm create \
|
||||
--resource-group $RESOURCE_GROUP_NAME \
|
||||
--name "$USERNAME"VM5 \
|
||||
--nics "$USERNAME"NicVM5 \
|
||||
--image Canonical:0001-com-ubuntu-server-focal:20_04-lts:latest \
|
||||
--admin-username $USERNAME \
|
||||
--size Standard_DS1_v2 \
|
||||
--custom-data "$CI_WEBSERVICE" \
|
||||
--ssh-key-name "$USERNAME"Key
|
||||
|
||||
|
||||
array=("$USERNAME"NicVM1 "$USERNAME"NicVM2 "$USERNAME"NicVM3 "$USERNAME"NicVM4 "$USERNAME"NicVM5)
|
||||
for vmnic in "${array[@]}"; do
|
||||
az network nic ip-config address-pool add \
|
||||
--address-pool "$USERNAME"BackendPool \
|
||||
--ip-config-name ipconfig1 \
|
||||
--nic-name $vmnic \
|
||||
--resource-group $RESOURCE_GROUP_NAME \
|
||||
--lb-name $LOADBALANCER_NAME
|
||||
done
|
||||
|
||||
echo "They probably need to get up... Let's give'm a few seconds..."
|
||||
sleep 15
|
||||
|
||||
echo "Heya! I'm done! Here are some details:"
|
||||
echo " LoadBalancer IP: $lbPublicIpAddr"
|
||||
echo ""
|
||||
echo "Have fun, Mate!"
|
BIN
webservice-balancer/Azure/test_results.png
Normal file
BIN
webservice-balancer/Azure/test_results.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 31 KiB |
BIN
webservice-balancer/Azure/webservice
Normal file
BIN
webservice-balancer/Azure/webservice
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user