Powershell Linux-无法在 Azure Ubuntu 中安装模块

Powershell Linux-无法在 Azure Ubuntu 中安装模块

我正在尝试在 Azure Linux 服务器的 Ubuntu powershell 中安装 AZ 模块。

但是,powersheel 找不到 PSGallery 存储库。

我怀疑服务器检索到的 DNS 记录不正确,因为 IP 地址是由 Trafficmanager.net 提供的。

如果有人能指点如何解决这个问题,我将不胜感激。谢谢。

安装尝试:

# pwsh
PowerShell 7.3.4


PS /root> Install-Module -Name Az -Repository PSGallery -Force
Get-PackageSource: Unable to find repository 'PSGallery'. Use Get-PSRepository to see all available repositories.
PS /root> [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
PS /root> Register-PSRepository -Default -Verbose
VERBOSE: Performing the operation "Register Module Repository." on target "Module Repository 'PSGallery' () in provider 'PowerShellGet'.".
PS /root> Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
Set-PSRepository: No repository with the name 'PSGallery' was found.

DNS 查询:

scs3:~$  nslookup www.powershellgallery.com
Server:         127.0.0.53
Address:        127.0.0.53#53

Non-authoritative answer:
www.powershellgallery.com       canonical name = powershellgallerytrafficmanager.trafficmanager.net.
powershellgallerytrafficmanager.trafficmanager.net      canonical name = psg-prod-eastus.cloudapp.net.
Name:   psg-prod-eastus.cloudapp.net
Address: 172.174.17.44

# nslookup redhat.com
Server:         127.0.0.53
Address:        127.0.0.53#53

Non-authoritative answer:
Name:   redhat.com
Address: 34.235.198.240
Name:   redhat.com
Address: 52.200.142.250

一些故障排除:

PS /root> Invoke-WebRequest 'https://www.powershellgallery.com/api/v2/'
Invoke-WebRequest: Resource temporarily unavailable

# curl -v https://www.powershellgallery.com/api/v2/
*   Trying 172.174.17.44:443...
* TCP_NODELAY set
* connect to 172.174.17.44 port 443 failed: Connection timed out
* Failed to connect to www.powershellgallery.com port 443: Connection timed out
* Closing connection 0
curl: (28) Failed to connect to www.powershellgallery.com port 443: Connection timed out
[root@scsdevvem02 22Jun2023 12:42:32  ~]
# pwsh
PowerShell 7.3.4
PS /root> [enum]::GetNames([Net.SecurityProtocolType])

SystemDefault
Ssl3
Tls
Tls11
Tls12
Tls13

在 /etc/hosts 中添加后:

20.84.181.62 www.powershellgallery.com

PS /root> Install-Module -Name Az -Repository PSGallery -Force -verbose
VERBOSE: Acquiring providers for assembly: /opt/microsoft/powershell/7/Modules/PackageManagement/coreclr/netstandard2.0/Microsoft.PackageManagement.ArchiverProviders.dll
VERBOSE: Acquiring providers for assembly: /opt/microsoft/powershell/7/Modules/PackageManagement/coreclr/netstandard2.0/Microsoft.PackageManagement.CoreProviders.dll
VERBOSE: Acquiring providers for assembly: /opt/microsoft/powershell/7/Modules/PackageManagement/coreclr/netstandard2.0/Microsoft.PackageManagement.MetaProvider.PowerShell.dll
VERBOSE: Acquiring providers for assembly: /opt/microsoft/powershell/7/Modules/PackageManagement/coreclr/netstandard2.0/Microsoft.PackageManagement.NuGetProvider.dll
Get-PackageSource: Unable to find repository 'PSGallery'. Use Get-PSRepository to see all available repositories.

最后一次尝试。


# snap install powershell --classic
powershell 7.3.4 from Microsoft PowerShell✓ installed

# pwsh
-bash: /usr/bin/pwsh: No such file or directory

# /snap/bin/pwsh
PowerShell 7.3.4
PS /root> Install-Module -Name Az -Repository PSGallery -Force
Get-PackageSource: Unable to find repository 'PSGallery'. Use Get-PSRepository to see all available repositories.
PS /root> Get-PSRepository
WARNING: Unable to find module repositories.

相关内容