Upload
takayoshi-tanaka
View
73
Download
1
Embed Size (px)
Citation preview
Linux on Azure の世界
Azure Linux Agent/Extensions概説とAADとの連携など「いろいろ」CLR/H in Tokyo 第11回
@tanaka_733
自己紹介お仕事◦ OpenShift◦ .NET Core on Red Hat Enterprise Linux (RHEL)◦ Red Hat Solutions on Azure (RHEL, OpenShift etc)
個人◦ Microsoft MVP for Visual Studio andDevelopment Technologies◦ C#, .NET Core + Azure
◦ Build InsiderでC#関連の記事を執筆していたりします◦ 最新連載: Roslyn SDKによる拡張の作り方
今日のGOAL◦Linux ユーザー向け Azure CLI おさらい
◦Azure上のLinuxが起動しなくなったら?
◦Azure Linux Agent に注目
◦Azure Linux Extension でアカウント制御や診断も
◦Azure AD と Linuxを組み合わせるシナリオの紹介
◦AnsibleでAzureリソースを制御してみよう
◦Azure File Storageでファイル共有してみよう
Azure CLI for Linux users
Linuxユーザー向けAzure CLI
• 現状の安定版。とりあえずこれで当面問題ない。
xplat Azure CLI (nodejs)
• 実験的実装?ディストリによってはPythonはデフォで入っていたりする
Azure CLI (python, preview)
• PowerShell on Linux, .NET Core を利用
• PowerShellになじみがあれば、使いやすい
Azure PowerShell on Linux
インストール方法をざっくり紹介
xplat azure cli (nodejs)
# subscription-manager repos –enable rhel-server-rhscl-7-rpms# yum -y install nodejs010# scl enable nodejs010 bash# npm install -g azure-cli# cat <<EOF \ > /etc/profile.d/enablenodejs010.sh> #!/bin/bash> source scl_source enable nodejs010> EOF
$ azure --completion | sudo tee /etc/bash_completion.d/azure.completion
RHEL: SCL経由でnodejsをインストールし、ログイン後に自動的に有効化するほかのOSでは、適宜nodejsをインストールし、npmでインストール
bash completion の有効化
Azure CLI (Python)
# yum install -y gcc libffi-devel python-devel openssl-devel$ curl -L https://aka.ms/InstallAzureCli | sudo bash
$ vim ~/.bashrcsource /usr/local/az/az.completion
https://github.com/Azure/azure-cli
インストール後の初期設定で、bash-completionなどが設定できるが、非rootユーザーだとうまく動かないので、手動対応が必要
Azure PowerShell on Linux
# wget https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-alpha.9/powershell-6.0.0_alpha.11-1.el7.centos.x86_64.rpm# yum localinstall powershell-6.0.0_alpha.11-1.el7.centos.x86_64.rpm
PS /home/user1> Install-Package -Name AzureRM.NetCore.Preview -Source https://www.powershellgallery.com/api/v2 -ProviderName NuGet -ExcludeVersion -Destination /home/user1/.local/share/powershell/Modules PS /home/user1> Import-Module AzureRM.NetCore.PreviewPS /home/user1> Login-AzureRMAccountVERBOSE: To sign in, use a web browser to open the page https://aka.ms/devicelogin. Enter the code AAAAAAAAA to authenticate.
Preview版で利用可能http://tech.tanaka733.net/entry/azure-powershell-preview-on-linux.NET Coreを先にインストールしておくこと
Linux on Azure Troubleshooting
LinuxをAzureで動かすためにMarketPlace経由 = お手軽、早い◦ OSの利用に関する追加コストがある場合、利用料金に含まれることが多い
◦ ただし、MSDN特典での無料使用分では負担できないことが多い = クレジットカードでの追加精算が必要
◦ RHELの場合、Subscriptionは利用料金に含まれる = 利用時間のみコストが発生◦ なお、一部のProductしか使えないので、使いたい場合はVHDのアップロードが必要
VHDのアップロード = 柔軟◦ 対応していれば任意のOSを動かせる
◦ 割と手順は長め
◦ https://azure.microsoft.com/ja-jp/documentation/articles/virtual-machines-linux-redhat-create-upload-vhd/◦ 手順の10のdracut.confの編集時、既存driverがある場合を考慮して先頭に空白入れるのが吉
add_drivers+=” hv_vmbus hv_netvsc hv_storvsc”
ありがちなトラブル
• Boot Diagnosticsをチェック
• VHDを別VMにアタッチして調査
VMが起動しない
• VMAccess Extensionsでリセット
• VHDを別VMにアタッチして編集
ユーザー・パスワード忘れた
Boot Diagnostics
VHDのアタッチによる回復◦ VHDをバックアップ
◦トラブル対象のVMを削除(VHDは残す)
◦ Rescue (という名前の普通の)VMを起動
◦ VHDをアタッチして編集
◦編集したVHDを使ってVNを作成
https://blogs.msdn.microsoft.com/linuxonazure/2016/10/09/linux-recovery-fixing-non-boot-issues-related-to-kernel-problems-using-chroot/
https://blogs.msdn.microsoft.com/linuxonazure/2016/10/09/linux-recovery-manually-fixing-non-boot-issues-related-to-kernel-problems/
Azure Linux Agent/Extensions 概説
Azure Linux Agent (waagent)Linuxのサービスとして動く
Azureサービス層と通信する
LinuxをAzure上で動かすために必須の機能を提供◦ Image Provisioning
◦ Networking◦ ホスト名変更時に内部DNSを更新
◦ Kernel
◦ Diagnostics
◦ SCVMM Deployments
◦ VM Extension
Install Azure Linux AgentBinary Install
◦ それぞれのディストリごとのリポジトリ経由で (下はRHELの例)
Advanced Install
◦ RHELの場合、リポジトリ経由以外ではサポート対象外となります
# subscription-manager repos --enable rhel-7-server-extras-rpms # yum -y install WALinuxAgent# systemctl enable waagent.service# systemctl start waagent.service
# python setup.py install --register-service
DEMO: Agentをdisableして起動
Agentのログファイル/var/log/waagent.log
2016/06/23 03:56:28 Azure Linux Agent Version: WALinuxAgent-2.0.162016/06/23 03:56:28 Linux Distribution Detected : redhat2016/06/23 03:56:28 Module /lib/modules/3.10.0-327.18.2.el7.x86_64/kernel/drivers/ata/ata_piix.ko driver for ATAPI CD-ROM is already present.2016/06/23 03:56:28 VMM Init script not found. Provisioning for Azure2016/06/23 03:56:28 IPv4 address: 10.0.0.42016/06/23 03:56:28 MAC address: 00:0D:3A:40:06:2C2016/06/23 03:56:28 Probing for Azure environment.2016/06/23 03:56:28 DoDhcpWork: Setting socket.timeout=10, entering recv2016/06/23 03:56:28 Set default gateway: 10.0.0.12016/06/23 03:56:28 Discovered Azure endpoint: 168.63.129.162016/06/23 03:56:28 Fabric preferred wire protocol version: 2015-04-052016/06/23 03:56:28 Negotiated wire protocol version: 2012-11-302016/06/23 03:56:28 SetBlockDeviceTimeout: Update the device sda with timeout 3002016/06/23 03:56:28 SetBlockDeviceTimeout: Update the device sdb with timeout 3002016/06/23 03:56:28 SetBlockDeviceTimeout: Update the device sdc with timeout 3002016/06/23 03:56:28 SetBlockDeviceTimeout: Update the device sdd with timeout 3002016/06/23 03:56:28 Retrieved GoalState from Azure Fabric.2016/06/23 03:56:28 ExpectedState: Started
Agentのログファイル(失敗時)/var/log/waagent.log
2016/06/23 04:14:41 Processing completed for Microsoft.OSTCExtensions.LinuxDiagnostic-2.3.9003
2016/06/23 04:14:41 Found Plugin: Microsoft.OSTCExtensions.VMAccessForLinux version: 1.3.0.1
2016/06/23 04:14:41 ERROR:HandlerManifest.json not found.
2016/06/23 04:14:41 Finished processing ExtensionsConfig.xml
2016/06/23 04:14:41 ERROR:Failed to get manifestdata.
2016/06/23 04:14:41 Successfully reported handler status
2016/06/23 04:15:06 ERROR:Failed to get manifestdata.
2016/06/23 04:15:31 ERROR:Failed to get manifestdata.
2016/06/23 04:15:56 ERROR:Failed to get manifestdata.
2016/06/23 04:16:22 ERROR:Failed to get manifestdata.
2016/06/23 04:16:47 ERROR:Failed to get manifestdata.
Azure Linux ExtensionAzure上で動かすのに便利な機能を提供◦ VMAccess
◦ VMDiagnostics
◦ DSCForLinux
◦ OmsAgent
◦ etc
現状、GitHubのページが一番の情報源
https://github.com/Azure/azure-linux-extensions
Portal経由でのインストール
インストールできるのはいくつかの拡張のみ
コマンドでのインストール$ azure vm extension-image list -l {location}
$ azure vm extension set {vm_resource_group_name} {vm_name} {Type} {Publisher} {Version} {option_parameter}
ARMテンプレートでの自動化{
"apiVersion": "[variables('api-version')]","type": "Microsoft.Compute/virtualMachines/extensions","name": "[concat(parameters('vmName'),'/enablevmaccess')]","location": "[resourceGroup().location]","dependsOn": ["[concat('Microsoft.Compute/virtualMachines/', parameters('vmName'))]"
],"properties": {"publisher": "Microsoft.OSTCExtensions","type": "VMAccessForLinux","typeHandlerVersion": "1.4","autoUpgradeMinorVersion": "true","settings": { },"protectedSettings": {"username": "[parameters('userName')]","password": "[parameters('password')]","reset_ssh": "[parameters('resetSSH')]","ssh_key": "[parameters('sshKey')]","remove_user": "[parameters('userNameToRemove')]"
}}
}
https://github.com/Azure/azure-quickstart-templates/tree/master/201-vmaccess-on-ubuntu
VMAccess Extensionユーザーの作成、削除、パスワードリセットなどを行う◦特定の操作をするときに、必要があればインストールを行う
$ azure vm extension set <resource-group> <vm-name> \VMAccessForLinux Microsoft.OSTCExtensions 1.4 \--private-config-path protected.json
$ azure vm reset-access <resource-group> <vm-name>
{"username": "currentusername","password": "newpassword"
}
{"username": "newusername","ssh_key": "contentofsshkey","expiration": "2016-12-31"
}
DEMO: ユーザー作成、リセットVMAccess Extensionでユーザー作成、パスワードリセット
$ tail -F /var/log/azure/{ProviderName}/{Version}
でログをチェック
VMDiagnostics ExtensionRequirement◦Azure Linux Agent >= 2.0.6
◦Azure Storage Account ◦ ZRS is unavailable
◦ Use Table Storage
Install Diagnostics ExtensionVM Diagnositc用の専用コマンド
もしくは、通常のコマンド
$ azure vm enable-diag --storage-account-name {storage_account_name} {vm_resource_group_name} {vm_name}
$ cat PrivateConfig.json{
"storageAccountName":"account","storageAccountKey":"foobarbazkey"
}$ azure vm extension set {vm_resource_group_name} {vm_name} LinuxDiagnosticMicrosoft.OSTCExtensions 2.3 --private-config-path PrivateConfig.json
Install Diagnostics ExtensionARMTemplateに記述して起動時にインストール可◦ただし、現状のデフォルト設定がえらく冗長
いったん、ポータルでVM作成ウィザードを進め、最後にTemplateとして保存するのがよさそう
VMDiagnosticsStorage Explorerを使えば、Linux, MacOSなどでも簡単にアクセス可能
AADとLinuxの連携
AAD OpenID ConnectOpenShiftなどOpenID Connectに対応している製品で利用可能
https://docs.openshift.com/container-platform/3.3/install_config/configuring_authentication.html#OpenID
AAD OpenID Connectはv2(組織アカウントと個人アカウントを区別しない)があるが、ドキュメントが混ざっていて、混同しやすい印象…
https://azure.microsoft.com/ja-jp/documentation/articles/active-directory-protocols-openid-connect-code/
認証するだけならあまり問題はでないが、ユーザーの属性をマッピングする部分などは念入りにテストが必要
AAD DS によるLDAP認証LinuxのユーザーをLDAP認証させることが可能
クラウド上のLinuxでは…◦オンプレADをVPN越しに利用
◦ AAD を利用したいが…
AADはLDAP認証サーバーとしては使えないAAD DSを使おうAAD DSがASMのみの対応という問題がある
AAD DS and LDAP with ARM
AAD
DS
VNET (ASM) VNET (ARM)
VNET Peering
LDAP
bindAAD
ARM でもAD DS使いたい
10.0.0.X
nameserver 10.0.0.X
AAD DS and LDAP with ARMARM でもAD DS使いたいVNETにAADのアドレスを設定しましょう
ARM側のVNETにも Peering越しのASMでのアドレスを指定
http://www.rebeladmin.com/2016/04/step-step-guide-enable-azure-ad-domain-services/
Azure上では /etc/resolv.conf は自動生成されるので注意
https://azure.microsoft.com/ja-jp/documentation/articles/virtual-networks-manage-dns-in-vnet/
ARM側で起動したVM上でいろいろ設定
https://azure.microsoft.com/ja-jp/documentation/articles/active-directory-ds-admin-guide-join-rhel-linux-vm/
AnsibleによるAzureリソースの管理
ARM用にAnsibleをセットアップする認証用のAAD アプリを作成し、IAMRoleに追加する◦ 旧ポータルでの作成推奨(現時点)、ただし新ポータルだと無期限のKeyを作成できる
◦ IAMRoleはSubscriptionに紐づければ全部操作できる。本番利用では最小限に
Ansibleは極力最新版をインストール、Azure Python SDK必須
http://tech.tanaka733.net/entry/ansible-azure
Ansibleのドキュメントが少ないのは、なんとも…
DemoVMAccess Extensionでユーザー作成、パスワードリセット
$ tail -F /var/log/azure/{ProviderName}/{Version}
でログをチェック
Azure File Storageによるファイル共有の利用
Azure File StorageをマウントするSMBによる共有
https://azure.microsoft.com/ja-jp/documentation/articles/storage-how-to-use-files-linux/
現状、Linux側ではCIFSの対応が完全ではないので、同じLocationのストレージのみの対応だったりする
より高度なファイル共有シナリオでは、
(例えばRed Hatだと)GlusterFS などの利用の検討になるかと思われます
今日のまとめ◦Linux ユーザー向け Azure CLI おさらい
◦Azure上のLinuxが起動しなくなったら?
◦Azure Linux Agent に注目
◦Azure Linux Extension でアカウント制御や診断も
◦Azure AD と Linuxを組み合わせるシナリオの紹介
◦AnsibleでAzureリソースを制御してみよう
◦Azure File Storageでファイル共有してみよう
今日触れていないこともっとRed Hat Solutions on Azure特有のこと◦需要があれば話します
OMSによるLinuxリソース監視◦来週のTokyo jazug night「OpenShift on Azure」で少し触れる予定
SQLServer on Linux (on Azure)◦時(Public Preview)が来れば(調べてから)話す
Service Fabric for Linux◦いつか話す