- 追加された行はこの色です。
- 削除された行はこの色です。
#author("2020-08-06T02:07:35+00:00","","")
#mynavi(Azureメモ)
#setlinebreak(on);
* 目次 [#e47b545e]
#contents
- 関連
-- [[Azureメモ]]
- 参考
-- [[macOS での Azure CLI のインストール:https://docs.microsoft.com/ja-jp/cli/azure/install-azure-cli-macos?view=azure-cli-latest]]
-- [[Azure CLI を使用してサインインする:https://docs.microsoft.com/ja-jp/cli/azure/authenticate-azure-cli?view=azure-cli-latest]]
* インストール [#mede3398]
#html(<div class="pl10">)
** Azure CLI (Mac) [#if6ccc68]
#html(<div class="pl10">)
#myterm2(){{
brew update && brew install azure-cli
}}
#html(</div>)
** Azure Functions Core Tools (Mac) [#b2b8e0d6]
#html(<div class="pl10">)
https://docs.microsoft.com/ja-jp/azure/azure-functions/functions-run-local?tabs=macos%2Ccsharp%2Cbash
v2.x
#myterm2(){{
brew tap azure/functions
brew install azure-functions-core-tools
}}
v3.x
#myterm2(){{
brew tap azure/functions
brew install azure-functions-core-tools@3
# if upgrading on a machine that has 2.x installed
brew link --overwrite azure-functions-core-tools@3
}}
#html(</div>)
#html(</div>)
* ログイン [#v21f0b37]
#html(<div class="pl10">)
#myterm2(){{
az login
}}
ローカルのストレージエミュレータを使用する場合
https://docs.microsoft.com/ja-jp/azure/developer/azure-cli/azure-cli-configuration#cli-configuration-values-and-environment-variables
#myterm2(){{
export AZURE_STORAGE_CONNECTION_STRING="UseDevelopmentStorage=true"
}}
※以降の az storage コマンドはローカルのエミュレータに対して発行される。
#html(</div>)
* サブスクリプションの設定 [#lbaf5088]
#html(<div class="pl10">)
以下を実施しておくと、以降の操作時に個別にサブスクリプションを指定する必要がなくなる。
#myterm2(){{
az account set --subscription サブスプリプションID
}}
#html(</div>)
* リージョン一覧の確認 [#r761a5d3]
#html(<div class="pl10">)
#myterm2(){{
az account list-locations -o table
}}
#html(</div>)
* リソースグループの作成 [#v8e25144]
#html(<div class="pl10">)
#myterm2(){{
# リソースグループの作成
echo az group create
az group create \
--name $resourceGroup \
--location $region
}}
#html(</div>)
* Blobストレージの操作 [#g29086ae]
#html(<div class="pl10">)
** ストレージアカウントの作成 [#f19a9e2a]
#html(<div class="pl10">)
#myterm2(){{
echo az storage account create
az storage account create \
--name $storageAccountName \
--location $region \
--resource-group $resourceGroup \
--sku $storageSku
}}
#html(</div>)
** ストレージアカウントの接続文字列の確認 [#eeeb9149]
#html(<div class="pl10">)
#myterm2(){{
az storage account show-connection-string --name $storageAccountName
}}
#html(</div>)
** ストレージコンテナの作成 [#bcda0c9b]
#html(<div class="pl10">)
#myterm2(){{
az storage container create \
--name $storageContainerName \
--resource-group $resourceGroup \
--account-name $storageAccountName
}}
#html(</div>)
** ストレージコンテナの一覧 [#nca87c41]
#html(<div class="pl10">)
#myterm2(){{
az storage container list
}}
#html(</div>)
** Blobオブジェクトの一覧 [#nff73cfa]
#html(<div class="pl10">)
#myterm2(){{
az storage blob list -c コンテナ名
}}
#html(</div>)
** Blobオブジェクトのアップロード [#kc97c05f]
#html(<div class="pl10">)
#myterm2(){{
az storage blob upload -f ファイルPATH -c コンテナ名 -n オブジェクト名
}}
#html(</div>)
** Blobオブジェクトのダウンロード [#r46c69a6]
#html(<div class="pl10">)
#myterm2(){{
az storage blob download -f 出力ファイルPATH -c コンテナ名 -n オブジェクト名
}}
#html(</div>)
#html(</div>)
* Azure Function の開発 [#vf10d2c1]
#html(<div class="pl10">)
** ローカル関数プロジェクトの作成 [#m782a70a]
#html(<div class="pl10">)
#myterm2(){{
func init LocalFunctionProj --dotnet
}}
#html(</div>)
** 関数をプロジェクトに追加 [#ce8dceac]
#html(<div class="pl10">)
#myterm2(){{
func new --name HttpExample --template "HTTP trigger"
}}
#html(</div>)
** 関数をローカルで実行する [#scd496d3]
#html(<div class="pl10">)
#myterm2(){{
func start
}}
#html(</div>)
** Application Insights コンポーネント作成 [#l68f10da]
#html(<div class="pl10">)
#myterm2(){{
# Application Insights 拡張が利用できない場合は追加インストール
x=`az monitor app-insights --help 2>&1`
if [ "$?" != "0" ]; then
az extension add -n application-insights
fi
az monitor app-insights component create \
--app $insightsName \
--location $insightsRegion \
--resource-group $resourceGroup \
--query-access Enabled \
--retention-time $insightsDays \
--subscription $subscriptionId
}}
#html(</div>)
** プレミアムプランの作成 [#xc0e0ef1]
#html(<div class="pl10">)
#myterm2(){{
az functionapp plan create \
--name $funcPlanName \
--resource-group $resourceGroup \
--location $region \
--sku $funcPlanSku
}}
#html(</div>)
** 関数アプリの作成 [#m743add3]
#html(<div class="pl10">)
#myterm2(){{
az functionapp create \
--name $funcAppName \
--storage-account $storageAccountName \
--plan $funcPlanName \
--resource-group $resourceGroup \
--functions-version $funcVersion \
--app-insights $insightsName
}}
#html(</div>)
** 関数アプリのVNet統合(プレビュー版の為、将来で変更/削除される可能性あり) [#rf2b29f9]
#html(<div class="pl10">)
#myterm2(){{
az functionapp vnet-integration add \
--name $funcAppName \
--resource-group $resourceGroup \
--vnet $vnetName \
--subnet $funcSubnetName
}}
#html(</div>)
** 関数アプリの設定/環境変数を確認する [#ya366f35]
#html(<div class="pl10">)
#myterm2(){{
az functionapp config appsettings list -n $funcAppName -g $resourceGroup -o table
}}
#html(</div>)
** 関数アプリの環境変数を設定する [#zb9ed1c1]
#html(<div class="pl10">)
#myterm2(){{
az functionapp config appsettings set \
--name $funcAppName \
--resource-group $resourceGroup \
--settings "ENV1=XXXX" "ENV2=YYYY"
}}
※設定した値は環境変数として取得できる。
#html(</div>)
** 関数をデプロイする [#m104bb8a]
#html(<div class="pl10">)
#myterm2(){{
az functionapp deployment source config-zip -g リソースグループ -n 関数名 --src ZIPファイルPATH
}}
参考
[[Azure Functions の zip デプロイ:https://docs.microsoft.com/ja-jp/azure/azure-functions/deployment-zip-push]]
[[Azure Functions のデプロイ テクノロジ:https://docs.microsoft.com/ja-jp/azure/azure-functions/functions-deployment-technologies]]
#html(</div>)
** Premium プランの関数アプリを作成する [#ib558d67]
#html(<div class="pl10">)
[[Azure FunctionsからVMにアクセスする]] を参照。
#html(</div>)
#html(</div>)
* 仮想ネットワーク/仮想マシン [#cdc27d86]
#html(<div class="pl10">)
** NSG(ネットワークセキュリティグループの)作成 [#e7436dac]
#html(<div class="pl10">)
#myterm2(){{
az network nsg create \
--resource-group $resourceGroup \
--name $nsgName
}}
#html(</div>)
** NSGルールの追加 [#j451ebeb]
#html(<div class="pl10">)
#myterm2(){{
az network nsg rule create \
--resource-group $resourceGroup \
--nsg-name $nsgName \
--name $nsgPubRuleName \
--access Allow \
--protocol Tcp \
--direction Inbound \
--priority 100 \
--source-address-prefix Internet \
--source-port-range "*" \
--destination-port-range $nsgPubInboundPort
}}
#html(</div>)
** 仮想ネットワーク 及び サブネット作成 [#kd431857]
#html(<div class="pl10">)
#myterm2(){{
az network vnet create \
--name $vnetName \
--resource-group $resourceGroup \
--address-prefixes $vnetPrefix \
--subnet-name $vmSubnetName \
--subnet-prefixes $vmSubnetPrefix \
--network-security-group $nsgName
}}
#html(</div>)
** 利用できるVMイメージの確認 [#x49e7017]
#html(<div class="pl10">)
#myterm2(){{
az vm image list -o table
}}
#html(</div>)
** 仮想マシンの作成 [#c37701b0]
#html(<div class="pl10">)
#myterm2(){{
az vm create \
--resource-group $resourceGroup \
--name $vmName \
--image $vmImage \
--generate-ssh-keys \
--subnet $vmSubnetName \
--vnet-name $vnetName \
--private-ip-address $vmIpAddress \
--admin-username $vmUser \
--output json \
--verbose
# --public-ip-address "" # TODO: 踏み台以外はPublicアクセスなしにする
}}
#html(</div>)
** VMのポート開放 [#qc3799fa]
#html(<div class="pl10">)
#myterm2(){{
az vm open-port \
--resource-group $resourceGroup \
--name $vmName \
--port 8086
}}
#html(</div>)
** VMのIPアドレス確認 [#fb464a8a]
#html(<div class="pl10">)
#myterm2(){{
az vm list-ip-addresses -o table
}}
#html(</div>)
#html(</div>)