Rocky LinuxにAzure PowerShellやAzure CLIをインストール

2019-10-27Azure,PowerShell/Azure CLI,RockyLinux/CentOS

Rocky LinuxへAzure PowerShellやAzure CLIをインストールする手順纏めです。

    • PowerShellをインストール
    • Azure PowerShellをインストール
    • Azure CLIをインストール
    • Azure Developer CLIをインストール

※Rocky Linux release 9.3 (Blue Onyx)を利用しています。
※ 手順は root ユーザーで実行されています。root ユーザー以外の場合はsudo を使用して実行してください。

スポンサーリンク

Rocky LinuxにAzure PowerShellをインストール

PowerShellインストール後にAz PowerShell モジュールをインストールします。

PowerShellインストール

PowerShellをインストールします。

Linux に PowerShell をインストールする
Red Hat Enterprise Linux (RHEL) への PowerShell のインストール

Microsoft 製品の Linux ソフトウェア リポジトリをインストール後にパッケージインストールします。

Linux Software Repository for Microsoft Products

 

#Microsoft製品のリポジトリをインストール

[root@test-vm-01 ~]# curl -sSL -O https://packages.microsoft.com/config/rhel/9/packages-microsoft-prod.rpm
[root@test-vm-01 ~]# ls -alh packages-microsoft-prod.rpm 
-rw-r–r–. 1 root root 6.8K 2月 24 13:34 packages-microsoft-prod.rpm
[root@test-vm-01 ~]# rpm -i packages-microsoft-prod.rpm
警告: packages-microsoft-prod.rpm: ヘッダー V4 RSA/SHA256 Signature、鍵 ID be1229cf: NOKEY
[root@test-vm-01 ~]# rm packages-microsoft-prod.rpm
rm: 通常ファイル 'packages-microsoft-prod.rpm’ を削除しますか? y

#PowerShellをインストール

[root@test-vm-01 ~]# dnf install powershell -y
Extra Packages for Enterprise Linux 9 – x86_64 32 kB/s | 36 kB 00:01
Extra Packages for Enterprise Linux 9 – x86_64 3.7 MB/s | 20 MB 00:05
packages-microsoft-com-prod 7.3 MB/s | 6.4 MB 00:00

~中略~

依存関係が解決しました。
================================
パッケージ Arch バージョン リポジトリー サイズ
================================
インストール:
powershell x86_64 7.4.1-1.rh packages-microsoft-com-prod 67 M
依存関係のインストール:
libicu x86_64 67.1-9.el9 baseos 9.6 M

~中略~

インストール済み:
libicu-67.1-9.el9.x86_64 powershell-7.4.1-1.rh.x86_64

完了しました!

[root@test-vm-01 ~]# pwsh
PowerShell 7.4.1
PS /tmp>

バイナリからPowerShellをインストール

バイナリからインストールも出来ます。

バイナリ アーカイブ

※依存関係となるlibicuを先にインストールしています。

 
[root@test-vm-01 ~]# dnf install -y libicu
[root@test-vm-01 ~]#
rpm -i https://github.com/PowerShell/PowerShell/releases/download/v7.4.1/powershell-7.4.1-1.rh.x86_64.rpm
[root@test-vm-01 ~]# pwsh
PowerShell 7.4.1
PS /tmp>

rpmで指定するURLは以下のURLのリンク先のGitHubで確認出来ます。

安定板リリース
LTS リリース

Azure PowerShellをインストール

Azure PowerShellをインストールします。
PowerShellでAzモジュールをインストールします。

Azure PowerShell を Linux にインストールする

※Get-InstalledModuleでインストールしたAzモジュールのバージョンが確認できます。

Azure PowerShellをインストール

[root@test-vm-01 ~]# pwsh

PowerShell 7.4.1
PS /tmp> Install-Module -Name Az -Repository PSGallery -Force
PS /tmp> Get-InstalledModule -Name Az

Version Name Repository Description
——- —- ———- ———–
11.3.1 Az PSGallery Microsoft Azure PowerShell – Cmdlets to manage resources…

 

Azure PowerShellでサインイン

Azureへサインインします。

サインイン

SSHなどCLI接続している場合にはデバイスコード認証を利用します。
デバイスコード認証の場合はUseDeviceAuthenticationパラメーターを指定します。

デバイス コード認証

Azure PowerShellでサインイン

[root@test-vm-01 ~]# pwsh
PS /tmp> Connect-AzAccount -UseDeviceAuthentication

WARNING: To sign in, use a web browser to open the page
https://microsoft.com/devicelogin(URL) and enter the code
HFXXQ2XXS(デバイスコード) to authenticate.
 

Account               SubscriptionName               TenantId
——-               —————-               ——–
アカウント名 サブスクリプション名 テナントID

 表示されているURLとデバイスコードを入力してサインインします。

※リモート接続時(CLI)にConnect-AzAccountを使用するとWARNING: Interactive authentication is not supported in this session, please run cmdlet 'Connect-AzAccount -UseDeviceAuthentication’.というエラーメッセージが表示されます。

PowerShellアンインストール

PowerShellをアンインストールする場合の手順です。

PowerShell のアンインストール

※PowerShellと一緒にAzモジュールもアンインストールされます。

PowerShellをアンインストール
[root@test-vm-01 ~]# dnf remove powershell -y
依存関係が解決しました。
===============================================
 パッケージ    Arch      バージョン       リポジトリー                    サイズ
===============================================
削除中:
 powershell    x86_64    7.4.1-1.rh       @packages-microsoft-com-prod    173 M
未使用の依存関係の削除:
 libicu        x86_64    67.1-9.el9       @baseos                          33 M

~中略~

削除しました:
  libicu-67.1-9.el9.x86_64             powershell-7.4.1-1.rh.x86_64

完了しました!

—広告—

Rocky LinuxにAzure CLIインストール

Azure CLIをインストール

Azure CLIをインストールします。

Linux に Azure CLI をインストールする

先にMicrosoft 製品の Linux ソフトウェア リポジトリをインストールします。

Linux Software Repository for Microsoft Products

az –versionを使用してインストール確認します。

Azure CLIをインストール

#Microsoft製品のリポジトリをインストール

[root@test-vm-01 ~]# curl -sSL -O https://packages.microsoft.com/config/rhel/9/packages-microsoft-prod.rpm
[root@test-vm-01 ~]# ls -alh packages-microsoft-prod.rpm 
-rw-r–r–. 1 root root 6.8K 2月 24 13:34 packages-microsoft-prod.rpm
[root@test-vm-01 ~]# rpm -i packages-microsoft-prod.rpm
警告: packages-microsoft-prod.rpm: ヘッダー V4 RSA/SHA256 Signature、鍵 ID be1229cf: NOKEY
[root@test-vm-01 ~]# rm packages-microsoft-prod.rpm
rm: 通常ファイル 'packages-microsoft-prod.rpm’ を削除しますか? y

#Azure CLIをインストール

[root@test-vm-01 ~]# dnf install azure-cli
メタデータの期限切れの最終確認: 0:56:24 前の 2024年02月24日 13時51分05秒 に実施しました。
依存関係が解決しました。
==============================================
パッケージ アーキテクチャー バージョン リポジトリー サイズ
==============================================
インストール:
azure-cli x86_64 2.57.0-1.el9 packages-microsoft-com-prod 33 M

~中略~

インストール済み:
azure-cli-2.57.0-1.el9.x86_64

完了しました!

[root@test-vm-01 ~]# az –version
azure-cli 2.57.0

core 2.57.0
telemetry 1.1.0

Dependencies:
msal 1.26.0
azure-mgmt-resource 23.1.0b2

Python location '/usr/bin/python3.9’
Extensions directory '/root/.azure/cliextensions’

Python (Linux) 3.9.18 (main, Jan 4 2024, 00:00:00)
[GCC 11.4.1 20230605 (Red Hat 11.4.1-2)]

Legal docs and information: aka.ms/AzureCliLegal

Your CLI is up-to-date.

Azure CLIでサインイン

Azureへサインインします。

Azure CLI を使用してサインインする

対話形式でサインインします。

Azure CLI を使用した対話形式でのサインイン

※色々なサインイン方法が利用できます。

Azureへサインイン

[root@test-vm-01 ~]# az login
To sign in, use a web browser to open the page
https://microsoft.com/devicelogin(URL) and enter the code
HFXXQ2XXS(デバイスコード) to authenticate.

[
 {
  "cloudName": “AzureCloud",
  "homeTenantId": “テナントID",
  "id": “サブスクリプションID",
  "isDefault": true,
  "managedByTenants": [],
  "name": “サブスクリプション名",
  "state": “Enabled",
  "tenantId": “テナントID",
  "user": {
   "name": “ユーザー名",
  "type": “user"
  }
 }
]

表示されているURLとデバイスコードを入力してサインインします。

 

—広告—

Azure Developer CLIインストール

Azure Developer CLIをインストールします。
インストール用のシェルが用意されているので利用します。

Azure Developer CLI をインストールまたは更新する

azd versionでインストール確認しています。

Azure Developer CLIをインストール

[root@test-vm-01 ~]# curl -fsSL https://aka.ms/install-azd.sh | bash
azd-linux-amd64
NOTICE.txt
install-azd: Successfully installed to /opt/microsoft/azd
install-azd: Symlink created at /usr/local/bin/azd and pointing to /opt/microsoft/azd/azd-linux-amd64
install-azd:
install-azd: The Azure Developer CLI collects usage data and sends that usage data to Microsoft in order to help us improve your experience.
install-azd: You can opt-out of telemetry by setting the AZURE_DEV_COLLECT_TELEMETRY environment variable to 'no’ in the shell you use.
install-azd:
install-azd: Read more about Azure Developer CLI telemetry: https://github.com/Azure/azure-dev#data-collection

[root@test-vm-01 ~]# azd version
azd version 1.6.1 (commit xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)

最後に

今回はRocky LinuxへAzureで利用しそうなCLIツールのインストール手順をまとめてみました。
引き続き色々試してみたいと思います。

Visual Studio CodeでのAzure PowerShellやAzure CLIのインストール手順はこちらに纏めています。

 Azureへのサインインコマンドについてはこちらに纏めています。

スポンサーリンク