Azure CLI를 사용하여 Microsoft Azure(WebApp)에서 Grafana 설정

목표 :
  • Azure CLI를 사용하여 Microsoft Azure에서 Grafana WebApp 생성
  • 데이터베이스는 mysql Azure Database for MySQL single server입니다.

  • 전제 조건:


  • 리소스 생성:
  • App Service 플랜
  • 스토리지 계정
  • 앱 서비스
  • Azure Database for MySQL 단일 서버

  • 스크립트

    $ResourceGroupName      = "suryarg"
    $LocationName           = "eastus2"
    $ACRName                = "suryacr"
    $ACRUrl                 = "$ACRName.azurecr.io"
    
    $AppServicePlan         = "suryaasp"
    $AppServicePlanSku      = "S1"
    $StorageAccountName     = "suryastorageaccountsa"
    $StorageAccountSku      = "Standard_ZRS"
    $StorageAccountShare    = "suryasgrafana"
    $WebAppName             = "suryawagrafana"
    



    $MYSQLServer            = "suryamysql"
    $MYSQLDB                = "grafana"
    
    #(Basic, Gen 5 hardware, 1 vCores).
    $MYSQLServerSku         = "B_Gen5_1"
    $MYSQLUsername          = "suryauser"
    $MYSQLPassword          = "surya@pass@2022"
    $IP                     = (Invoke-WebRequest -uri "https://api.ipify.org/").Content
    



    #Create App Service Plan
    az appservice plan create --resource-group $ResourceGroupName --name $AppServicePlan --is-linux --sku $AppServicePlanSku    
    
    #Create a Storage Account
    az storage account create --resource-group $ResourceGroupName --name $StorageAccountName --kind StorageV2 --sku $StorageAccountSku
    
    #Create an Storage Account File Share
    az storage share-rm create --resource-group $ResourceGroupName --storage-account $StorageAccountName --name $StorageAccountShare --access-tier "TransactionOptimized" --quota 64
    
    #Create an Webapp for Grafana
    az webapp create --resource-group $ResourceGroupName --name $WebAppName --plan $AppServicePlan -i "$ACRUrl/grafana:SuryaLatest"
    
    #Create MYSQL Server for Grafana Database
    az mysql server create --resource-group $ResourceGroupName --name $MYSQLServer --location $LocationName --admin-user $MYSQLUsername --admin-password $MYSQLPassword --sku-name $MYSQLServerSku --storage-size 5120
    
    #Create MYSQL Database
    az mysql db create --resource-group $ResourceGroupName --server-name $MYSQLServer --name $MYSQLDB
    



    #Create Storage Mount for Grafana WebApp
    $storageaccountkey  =   $(az storage account keys list --resource-group $ResourceGroupName --account-name $StorageAccountName --query [0].value -o tsv)
    
    az webapp config storage-account add --resource-group $ResourceGroupName --name $WebAppName --custom-id "grafana" --storage-type "AzureFiles" --share-name $StorageAccountShare --account-name $StorageAccountName --access-key $storageaccountkey  --mount-path "/var/lib/grafana"
    az webapp config storage-account add --resource-group $ResourceGroupName --name $WebAppName --custom-id "config" --storage-type "AzureFiles" --share-name $StorageAccountShare --account-name $StorageAccountName --access-key $storageaccountkey  --mount-path "/etc/grafana"
    az webapp config storage-account add --resource-group $ResourceGroupName --name $WebAppName --custom-id "log" --storage-type "AzureFiles" --share-name $StorageAccountShare --account-name $StorageAccountName --access-key $storageaccountkey  --mount-path "/var/log/grafana"
    



    #Set an Environment Variable for Grafana WebApp
    $envg0 = "mysql"
    az webapp config appsettings set --resource-group $ResourceGroupName --name $WebAppName --settings GF_DATABASE_TYPE=$envg0
    
    $envg1 = "mysql://$($MYSQLUsername)@$($MYSQLServer):$($MYSQLPassword)@$($MYSQLServer).mysql.database.azure.com:3306/$($MYSQLDB)"
    az webapp config appsettings set --resource-group $ResourceGroupName --name $WebAppName --settings GF_DATABASE_URL=$envg1
    
    $envg2="/etc/grafana/custom.ini"
    az webapp config appsettings set --resource-group $ResourceGroupName --name $WebAppName --settings GF_PATHS_CONFIG=$envg2
    
    $envg3="console file"
    az webapp config appsettings set --resource-group $ResourceGroupName --name $WebAppName --settings GF_LOG_MODE=$envg3
    
    $envg4="/var/log/grafana"
    az webapp config appsettings set --resource-group $ResourceGroupName --name $WebAppName --settings GF_PATHS_LOGS=$envg4
    
    
    az webapp config appsettings set --resource-group $ResourceGroupName --name $WebAppName --settings WEBSITES_PORT=3000
    



    #Allow WebApp IP Address in MySQL Server
    $WebAppAllIP = (az webapp show --resource-group $ResourceGroupName --name $WebAppName --query possibleOutboundIpAddresses --output tsv).split(",")
    foreach($singleIP in $WebAppAllIP)
    {
        az mysql server firewall-rule create --resource-group $ResourceGroupName --server $MYSQLServer --name $WebAppAllIP.IndexOf($singleIP) --start-ip-address $singleIP --end-ip-address $singleIP
    }
    
    #Allow Current IP Address in MySQL Server
    az mysql server firewall-rule create --resource-group $ResourceGroupName --server $MYSQLServer --name AllowMyIP --start-ip-address $IP --end-ip-address $IP
    


    출력 :








    _____________________________________엑스______________________________________

    좋은 웹페이지 즐겨찾기